-
Notifications
You must be signed in to change notification settings - Fork 284
104 lines (102 loc) · 5.8 KB
/
test-suite.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Test Suite
on:
issue_comment:
types:
- created
- edited
jobs:
test-suite:
name: Build Containers and Run Tests
runs-on: ubuntu-22.04
steps:
- name: Check Comment
id: check_comment
run: |
comment_body="${{ github.event.comment.body }}"
if [[ "$comment_body" =~ TEST:\ (all|\*) ]]; then
test_all=true
elif [[ "$comment_body" =~ TEST:(.*?)END ]]; then
specs="${BASH_REMATCH[1]}"
# Split the content by commas and remove spaces
IFS=',' read -ra content_array <<< "$specs"
# Remove leading and trailing spaces and slashes from each element
content_array=("${content_array[@]// /}")
content_array=("${content_array[@]#/}")
content_array=("${content_array[@]%/}")
# Add "/app/cypress/e2e/" prefix to each element
for ((i=0; i<${#content_array[@]}; i++)); do
content_array[$i]="/app/cypress/e2e/${content_array[$i]}"
done
# Join the content array elements with commas
content_no_spaces="$(IFS=','; echo "${content_array[*]}")"
echo "spec_content=$content_no_spaces" >> $GITHUB_ENV
else
echo "Comment does not match the expected format."
exit 1
fi
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Configure Build X
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile.ci
cache-from: type=gha
cache-to: type=gha,mode=max
tags: cms-web
build-args: GIT_COMMIT=${{ github.sha }}
push: false
load: true
- name: Pull
run: |
docker pull mysql:8
docker pull ghcr.io/xibosignage/xibo-xmr:latest
- name: Run
run: |
docker run --name cms-db -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=cms -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -d mysql:8
docker run --name cms-xmr -d ghcr.io/xibosignage/xibo-xmr:latest
docker run --name cms-web -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -e XIBO_DEV_MODE=true -e XMR_HOST=cms-xmr --link cms-db:db --link cms-xmr:50001 -d cms-web
- name: Wait for CMS
run: |
docker exec -t cms-web /bin/bash -c "/usr/local/bin/wait-for-command.sh -q -t 300 -c \"nc -z localhost 80\""
docker cp cms-web:/var/www/cms/web/settings.php web/settings.php
docker exec -t cms-web /bin/bash -c "chown -R www-data.www-data /var/www/cms"
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; /usr/bin/php bin/run.php 1"
sleep 5
- name: Seed Database
run: |
docker exec cms-db mysql -ucms -pjenkins cms -e "UPDATE setting SET value=\"6v4RduQhaw5Q\" WHERE setting = \"SERVER_KEY\" "
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO task (name, class, status, isActive, configFile, options, schedule) VALUES ('Seed Database', '\\\\Xibo\\\\XTR\\\\SeedDatabaseTask', 2, 1, '/tasks/seed-database.task', '{}', '* * * * * *')"
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; /usr/bin/php bin/run.php \"Seed Database\""
sleep 5
- name: Run PHP Unit
run: |
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; php vendor/bin/phpunit --log-junit results.xml"
- name: Run Cypress
id: cypress
run: |
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO oauth_clients (id, secret, name, userId, authCode, clientCredentials) VALUES ('MrGPc7e3IL1hA6w13l7Ru5giygxmNiafGNhFv89d', 'Pk6DdDgu2HzSoepcMHRabY60lDEvQ9ucTejYvc5dOgNVSNaOJirCUM83oAzlwe0KBiGR2Nhi6ltclyNC1rmcq0CiJZXzE42KfeatQ4j9npr6nMIQAzMal8O8RiYrIoono306CfyvSSJRfVfKExIjj0ZyE4TUrtPezJbKmvkVDzh8aj3kbanDKatirhwpfqfVdfgsqVNjzIM9ZgKHnbrTX7nNULL3BtxxNGgDMuCuvKiJFrLSyIIz1F4SNrHwHz', 'cypress', 1, 0, 1)"
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO oauth_client_scopes (clientId, scopeId) VALUES ('MrGPc7e3IL1hA6w13l7Ru5giygxmNiafGNhFv89d', 'all') ON DUPLICATE KEY UPDATE scopeId = scopeId"
if [[ "$test_all" == true ]]; then
docker run --ipc=host --name cms-cypress --link=cms-web:web -v $(pwd)/cypress.config.js:/app/cypress.config.js -v $(pwd)/cypress:/app/cypress ghcr.io/xibosignage/xibo-cms:cypress bash -c "CYPRESS_baseUrl=http://web /app/node_modules/.bin/cypress run --config screenshotsFolder=/app/cypress/results,video=false --reporter junit --reporter-options 'mochaFile=/app/cypress/results/results_cypress_[hash].xml,toConsole=true' && chown -R 1001:1001 /app/cypress/results && exit \${PIPESTATUS[0]};"
else
docker run --ipc=host --name cms-cypress --link=cms-web:web -v $(pwd)/cypress.config.js:/app/cypress.config.js -v $(pwd)/cypress:/app/cypress ghcr.io/xibosignage/xibo-cms:cypress bash -c "CYPRESS_baseUrl=http://web /app/node_modules/.bin/cypress run --config screenshotsFolder=/app/cypress/results,video=false --spec \"$spec_content\" --reporter junit --reporter-options 'mochaFile=/app/cypress/results/results_cypress_[hash].xml,toConsole=true' && chown -R 1001:1001 /app/cypress/results && exit \${PIPESTATUS[0]};"
fi
continue-on-error: true
- name: Save Cypress test results as an artifact
uses: actions/upload-artifact@v3
with:
name: cypress-test-results
path: cypress/results
- name: Check Cypress exit code
run: |
if [[ ${{ steps.cypress.outcome }} == 'success' ]]; then
echo "Cypress tests succeeded"
else
echo "Cypress tests failed with exit code ${{ steps.cypress.exitCode }}"
exit 1
fi