forked from xibosignage/xibo-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (132 loc) · 7.72 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Test Suite
on:
issue_comment:
types: [created]
jobs:
test-suite:
name: Build Containers and Run Tests
if: github.event.issue.pull_request && contains(github.event.comment.body, 'TEST:')
runs-on: ubuntu-22.04
steps:
# Step 1: Determine the correct branch associated with the PR
- name: Get branch of PR
uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
# Step 2: Set the status of the latest commit to "pending" at the beginning of the workflow
- name: Set latest commit status as pending
uses: myrotvorets/set-commit-status-action@master
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
# Step 3: Checkout the branch associated with the PR
- name: Checkout PR branch ${{ steps.comment-branch.outputs.head_ref }}
uses: actions/checkout@v4
with:
ref: ${{ steps.comment-branch.outputs.head_sha }}
# Step 4: The Rest
- 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: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull
run: |
docker pull mysql:8
docker pull ghcr.io/xibosignage/xibo-xmr:latest
docker pull ghcr.io/xibosignage/xibo-cms:test-${{ github.event.issue.number }}
- 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_HOST=cms-db -e MYSQL_USER=cms -e MYSQL_PASSWORD=jenkins -e CMS_DEV_MODE=true -e XMR_HOST=cms-xmr -e CMS_USAGE_REPORT=false -e INSTALL_TYPE=ci -e MYSQL_BACKUP_ENABLED=false --link cms-db --link cms-xmr -d ghcr.io/xibosignage/xibo-cms:test-${{ github.event.issue.number }}
- 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
# Step 5: Add a comment to the PR with the workflow result
- name: Add workflow result as comment on PR
uses: actions/github-script@v6
if: always()
with:
script: |
const name = '${{ github.workflow }}';
const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}';
const success = '${{ job.status }}' === 'success';
const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
# Step 6: Set the status of the latest commit to the final job status
- name: Set latest commit status as ${{ job.status }}
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
sha: ${{ steps.comment-branch.outputs.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}