-
Notifications
You must be signed in to change notification settings - Fork 1
194 lines (175 loc) · 8.51 KB
/
test.yml
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: test
on:
push:
branches-ignore:
- 'dependabot/**' #avoid duplicates: only run the PR, not the commit
tags-ignore:
- 'v*' #avoids rerun existing commit on release
pull_request:
branches:
- 'main'
workflow_dispatch:
jobs:
test-ut:
runs-on: ubuntu-latest
#avoids duplicate execution of pr from local repo, but allows pr from forked repos and dependabot
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
steps:
- run : |
echo "event name: ${{ github.event_name }}"
echo "fork: ${{ github.event.pull_request.head.repo.fork }}"
echo "head ref: ${{ github.head_ref }}"
- name: Checkout GitHub repo
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Run unit tests
working-directory: ./dashgit-web/test
run: |
mkdir actual
npm install
npm run report
- name: Publish test report files
if: success() || failure() # always run even if the previous step fails
uses: actions/upload-artifact@v4.4.0
with:
name: "test-ut-report-files"
path: |
dashgit-web/test/expected
dashgit-web/test/actual
dashgit-web/test/mochawesome-report
sonarqube:
# As in test-ut, but excludes dependabot updates to remove duplicates on local prs
# if: ${{ false }}
if: github.actor != 'dependabot[bot]' && ( (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/'))) )
runs-on: ubuntu-latest
steps:
- if: github.event.pull_request.head.repo.fork
name: Failing job that is executed from forked repo
run: exit 1
- uses: javiertuya/sonarqube-action@v1.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
java-directory: dashgit-updater
# Notes on IT tests:
# Integration tests require access to two dedicated test repositories that should be accessed exclusively. Instead of using the native
# concurrency control, we use a mutex action, that allows more than one job waiting for the test repositories.
# Jobs are configured to remove duplicated PRs when run in local branches, and run on PRs from forks and dependabot,
# However, as we do not use pull_request_target to trigger workflows, IT tests will fail from forks and dependabot
# due to the security configuration of Actions.
# To test the pr #ID branch in local: git fetch origin pull/ID/head:PR-ID && git switch PR-ID
# IT tests only run when some file on the dashgit-updater project changes.
# If this is controlled by specifying the pahts in the on events, a problem appears:
# if no file changes in these paths, the IT checks appears as not run and then the branch protection rule is blocked.
# There are different dicussions about this, e.g.
# https://github.com/orgs/community/discussions/26733 that uses the re-actors/alls-green action.
# The approach used is here is the suggested in
# https://stackoverflow.com/questions/70708306/github-actions-run-step-job-in-a-workflow-if-changes-happen-in-specific-folde
# using dorny/paths-filter in a first job that produces an output with a true value if some file in the paths has changed
# and the test jobs that require the previous output to be true. If not, the job will be skipped, which does not block
# the branch protection rule.
# The last problem is with the matrix (GitHub and GitLab): their status can't be used in a branch protection rule when skipped.
# To overcome this, each matrix execution uploads an artifact with the status (true or false) and a final job
# downloads and combines the artifacts, failing the job if any is not successful
test-it-trigger:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
output1: ${{ steps.filter.outputs.workflows }}
if: (github.event_name != 'pull_request' && ! github.event.pull_request.head.repo.fork) || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/')))
steps:
- uses: actions/checkout@v4
- run: echo "current branch ${{ github.ref_name }}"
- uses: dorny/paths-filter@v3.0.2
id: filter
with:
base: ${{ github.ref_name }}
filters: |
workflows:
- 'dashgit-updater/**'
- name: Trigger IT tests
if: steps.filter.outputs.workflows == 'true'
run: echo "Trigger IT tests"
test-it:
runs-on: ubuntu-latest
permissions:
contents: write # for mutex on test repos
checks: write # for junit report
strategy:
matrix:
scope: [Github, Gitlab]
fail-fast: false
needs: test-it-trigger
if: needs.test-it-trigger.outputs.output1 == 'true'
steps:
- uses: actions/checkout@v4
# workaround #35, avoid infinite loop of ben-z/gh-action-mutex, issue #15
- if: github.event.pull_request.head.repo.fork
name: Failing job that is executed from forked repo
run: exit 1
- name: Set up & wait mutex - ${{ matrix.scope }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ben-z/gh-action-mutex@v1.0.0-alpha.9
with:
branch: gh-mutex-${{ matrix.scope }}
- name: Create dashgit-updater/it.properties
run: |
echo "github.server=https://github.com" > dashgit-updater/it.properties
echo "github.repo=${{ github.actor }}/dashgit-test" >> dashgit-updater/it.properties
echo "github.secret=DASHGIT_GITHUB_IT_TOKEN" >> dashgit-updater/it.properties
echo "github.user=${{ github.actor }}" >> dashgit-updater/it.properties
echo "github.email=" >> dashgit-updater/it.properties
echo "gitlab.server=https://gitlab.com" >> dashgit-updater/it.properties
echo "gitlab.repo=${{ github.actor }}/dashgit-test" >> dashgit-updater/it.properties
echo "gitlab.secret=DASHGIT_GITLAB_IT_TOKEN" >> dashgit-updater/it.properties
echo "gitlab.user=${{ github.actor }}" >> dashgit-updater/it.properties
echo "gitlab.email=" >> dashgit-updater/it.properties
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Run IT tests - ${{ matrix.scope }}
env:
DASHGIT_GITHUB_IT_TOKEN: ${{ secrets.DASHGIT_GITHUB_IT_TOKEN}}
DASHGIT_GITLAB_IT_TOKEN: ${{ secrets.DASHGIT_GITLAB_IT_TOKEN}}
run: cd dashgit-updater && mvn test -Dtest=TestIt${{ matrix.scope }}*,TestUt* -Dmaven.test.failure.ignore=false -U --no-transfer-progress
#run: cd dashgit-updater && mvn test -Dtest=TestUt* -Dmaven.test.failure.ignore=false -U --no-transfer-progress
- name: Generate report checks - ${{ matrix.scope }}
if: success() || failure()
uses: mikepenz/action-junit-report@v4.3.1
with:
check_name: "test-it-result-${{ matrix.scope }}"
report_paths: "**/surefire-reports/TEST-*.xml"
fail_on_failure: 'true'
- if: failure()
run: echo "false" > test-it-status-${{ matrix.scope }}.txt
- if: success()
run: echo "true" > test-it-status-${{ matrix.scope }}.txt
- uses: actions/upload-artifact@v4.4.0
if: success() || failure()
with:
name: test-it-status-${{ matrix.scope }}
path: test-it-status-${{ matrix.scope }}.txt
test-it-status:
runs-on: ubuntu-latest
needs: test-it
if: success() || failure()
steps:
- name: Download statuses from artifacts generated by matrix
uses: actions/download-artifact@v4.1.8
with:
merge-multiple: true
pattern: test-it-status-*
- name: Check statuses and fails if any is unsuccessful
run: |
ls -la
echo -n "$(cat test-it-status-Github.txt)" > test-it-status.txt
echo -n "$(cat test-it-status-Gitlab.txt)" >> test-it-status.txt
echo "Combined status is: $(cat test-it-status.txt)"
if [ "$(cat test-it-status.txt)" != "truetrue" ]; then exit 1; fi