-
-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (190 loc) · 9.43 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Tests"
on: # yamllint disable-line rule:truthy
# eslint-disable-next-line yml/no-empty-mapping-value
pull_request: # yamllint disable-line rule:empty-values
types: ["opened", "synchronize", "reopened"]
merge_group: # yamllint disable-line rule:empty-values
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
permissions:
contents: "read" # to fetch code (actions/checkout)
env:
NX_BRANCH: "${{ github.event.number }}"
NX_RUN_GROUP: "${{ github.run_id }}"
HEAD_REF: "${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}"
HEAD_REPOSITORY: "${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }}"
jobs:
files-changed:
name: "Detect what files changed"
runs-on: "ubuntu-24.04"
timeout-minutes: 3
# Map a step output to a job output
outputs:
packages: "${{ steps.changes.outputs.packages }}"
codecov: "${{ steps.changes.outputs.codecov }}"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e" # v2.10.4
with:
egress-policy: "audit"
- name: "Git checkout"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Check for file changes"
uses: "dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36" # v3.0.2
id: "changes"
with:
token: "${{ github.token }}"
filters: ".github/file-filters.yml"
test-multi-semantic-release:
name: "Test semantic-release version ${{ matrix.semantic_release_version }} on (node-${{ matrix.node_version }}, ${{ matrix.os }})"
if: "needs.files-changed.outputs.packages == 'true'"
needs: "files-changed"
strategy:
max-parallel: 4
matrix:
os:
- "ubuntu-latest"
node_version: ["18", "20", "21", "22", "23"]
semantic_release_version: ["^20", "^21", "^22", "^23", "^24"]
# On the other platforms, we only test the lts node version
include:
- os: "macos-latest"
node_version: "22"
semantic_release_version: "^22"
fail-fast: false
runs-on: "${{ matrix.os }}"
env:
NODE: "${{ matrix.node_version }}"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e" # v2.10.4
with:
egress-policy: "audit"
- name: "Git checkout ${{ env.HEAD_REPOSITORY }}:${{ env.HEAD_REF }}"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Pulls all commits (needed for NX)
fetch-depth: 0
- name: "Derive appropriate SHAs for base and head for `nx affected` commands"
id: "setSHAs"
uses: "nrwl/nx-set-shas@e2e6dc8bce4b0387a05eb687735c39c41580b792" # v4
- name: "Setup resources and environment"
id: "setup"
uses: "anolilab/workflows/step/setup@main"
with:
node-version: "${{ matrix.node_version }}"
enable-nx-cache: false
- name: "Install semantic-release version ${{ matrix.semantic_release_version }}"
run: |
pnpm add -D semantic-release@${{ matrix.semantic_release_version }} --filter=multi-semantic-release
env:
SKIP_CHECK: "true"
- name: "Run tests"
shell: "bash"
run: "pnpm run --filter=multi-semantic-release test"
test-packages:
name: "Test (node-${{ matrix.node_version }}, ${{ matrix.os }})"
if: "needs.files-changed.outputs.packages == 'true'"
needs: "files-changed"
strategy:
max-parallel: 4
matrix:
os:
- "ubuntu-latest"
node_version: ["18", "20", "21", "22"]
# On the other platforms, we only test the lts node version
include:
- os: "macos-latest"
node_version: "20"
fail-fast: false
runs-on: "${{ matrix.os }}"
env:
NODE: "${{ matrix.node_version }}"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e" # v2.10.4
with:
egress-policy: "audit"
- name: "Git checkout ${{ env.HEAD_REPOSITORY }}:${{ env.HEAD_REF }}"
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Pulls all commits (needed for NX)
fetch-depth: 0
- name: "Derive appropriate SHAs for base and head for `nx affected` commands"
id: "setSHAs"
uses: "nrwl/nx-set-shas@e2e6dc8bce4b0387a05eb687735c39c41580b792" # v4
- name: "Setup resources and environment"
id: "setup"
uses: "anolilab/workflows/step/setup@main"
with:
node-version: "${{ matrix.node_version }}"
# Temporary solution until Nx solve this https://github.com/nrwl/nx/issues/22259
- name: "Get changed files"
id: "files"
uses: "tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f" # v45.0.6
with:
files_ignore_from_source_file: ".github/ignore-files-for-nx-affected.yml"
base_sha: "${{ steps.setSHAs.outputs.base }}"
separator: ","
- name: "Build"
shell: "bash"
run: |
files="${{ steps.files.outputs.all_changed_files }}";
pnpm run build:affected:packages --files=${files//\\/\/}
- name: "Run tests"
shell: "bash"
run: |
files="${{ steps.files.outputs.all_changed_files }}";
if [[ ${{ matrix.os }} == "ubuntu-latest" && ${{ matrix.node_version }} == 18 ]]; then
pnpm run test:affected:coverage --files=${files//\\/\/}
else
pnpm run test:affected --files=${files//\\/\/}
fi
- name: "Prepare nx cache"
shell: "bash"
run: "tar -cf - .nx/cache | lz4 > /tmp/nx_cache.tar.lz4" # compress nx cache
- name: "Upload code coverage to codecov"
if: "matrix.os == 'ubuntu-latest' && matrix.node_version == 18"
uses: "anolilab/workflows/step/codecov@main"
with:
run-lint: "needs.files-changed.outputs.codecov == 'true'"
codecov-token: "${{ secrets.CODECOV_TOKEN }}"
use-affected: "true"
affected-files: "${{ steps.files.outputs.all_changed_files }}"
exclude-affected-projects: "semantic-release-preset"
# This check runs once all dependant jobs have passed
# It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
# This check is the only required GitHub check
test-required-check:
needs: ["files-changed", "test-multi-semantic-release", "test-packages"]
name: "Check Test Run"
# This is necessary since a failed/skipped dependent job would cause this job to be skipped
if: "always() && (needs.test-packages.result == 'success' || needs.test-packages.result == 'skipped') && (needs.test-multi-semantic-release.result == 'success' || needs.test-multi-semantic-release.result == 'skipped')"
runs-on: "ubuntu-24.04"
steps:
# If any jobs we depend on fail, we will fail since this is a required check
# NOTE: A timeout is considered a failure
- name: "Harden Runner"
uses: "step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e" # v2.10.4
with:
egress-policy: "audit"
- name: "Check for failures"
if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
run: |
echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1