Skip to content

Commit 58a0949

Browse files
committed
chore: rewrite test workflow
The motivation for this is improve the speed at which the CI tasks complete in the Pact-JS repository. This hopefully achieves this by having more parallel builds which are each smaller and cached. I have also reduced the reliance on the scripts as it appeared to me that they duplicate a number of steps. These duplications are justified when running locally to ensure all previous steps are run, but in CI it likely results in longer runs thhan necessary. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent d7bd517 commit 58a0949

File tree

2 files changed

+269
-123
lines changed

2 files changed

+269
-123
lines changed

.github/workflows/build-and-test.yml

-123
This file was deleted.

.github/workflows/test.yml

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
env:
17+
GIT_COMMIT: ${{ github.sha }}
18+
GIT_REF: ${{ github.ref }}
19+
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
20+
LOG_LEVEL: info
21+
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
22+
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
23+
24+
jobs:
25+
complete:
26+
name: Test completion check
27+
if: always()
28+
29+
permissions:
30+
contents: none
31+
32+
runs-on: ubuntu-latest
33+
needs:
34+
- test-x86
35+
- test-alpine
36+
- test-arm64
37+
- lint
38+
- format
39+
- examples
40+
41+
steps:
42+
- name: Failed
43+
run: exit 1
44+
if: >
45+
contains(needs.*.result, 'failure')
46+
|| contains(needs.*.result, 'cancelled')
47+
|| contains(needs.*.result, 'skipped')
48+
49+
lint:
50+
name: Lint
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
56+
57+
- name: Setup Node.JS
58+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
59+
with:
60+
cache: npm
61+
62+
- name: Install dependencies
63+
run: npm ci
64+
65+
- name: Lint
66+
run: npm run lint
67+
68+
format:
69+
name: Format
70+
runs-on: ubuntu-latest
71+
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
75+
76+
- name: Setup Node.JS
77+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
78+
with:
79+
cache: npm
80+
81+
- name: Install dependencies
82+
run: npm ci
83+
84+
- name: Format
85+
run: npm run format:check
86+
87+
test-x86:
88+
name: >-
89+
Test x86_64
90+
on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
91+
with Node ${{ matrix.node-version }}
92+
93+
runs-on: ${{ matrix.os }}
94+
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
node-version: [18, 20, 22]
99+
os:
100+
- macos-13
101+
- macos-latest
102+
- ubuntu-latest
103+
- windows-latest
104+
105+
steps:
106+
- name: Checkout
107+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
108+
109+
- name: Setup Node.js ${{ matrix.node-version }}
110+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
111+
with:
112+
node-version: ${{ matrix.node-version }}
113+
cache: npm
114+
115+
- name: Install dependencies
116+
run: |
117+
npm ci
118+
npm run dist
119+
120+
- name: Run tests
121+
run: npm test
122+
123+
- name: Coverage
124+
if: startsWith(matrix.os, 'ubuntu-')
125+
run: npm run coverage
126+
127+
- name: Codecov
128+
if: startsWith(matrix.os, 'ubuntu-')
129+
uses: codecov/codecov-action@v5
130+
131+
# On Ubuntu, we also package the `dist` folder to be re-used by the
132+
# examples
133+
- name: Re-use dict folder
134+
if: startsWith(matrix.os, 'ubuntu-')
135+
uses: actions/upload-artifact@v4
136+
with:
137+
name: dist
138+
path: dist/
139+
140+
141+
test-alpine:
142+
name: >-
143+
Test Alpine
144+
on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
145+
with Node ${{ matrix.node-version }}
146+
147+
runs-on: ubuntu-latest
148+
container:
149+
image: node:${{ matrix.node-version }}-alpine
150+
151+
strategy:
152+
fail-fast: false
153+
matrix:
154+
os: [ubuntu-latest]
155+
node-version: [18, 20, 22]
156+
157+
steps:
158+
- name: Checkout
159+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
160+
161+
- name: Install dependencies
162+
run: |
163+
npm ci
164+
npm run dist
165+
166+
- name: Run tests
167+
run: npm test
168+
169+
test-arm64:
170+
name: >-
171+
Test ARM64
172+
on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
173+
with Node ${{ matrix.node-version }}
174+
175+
runs-on: ${{ matrix.os }}
176+
177+
strategy:
178+
fail-fast: false
179+
matrix:
180+
node-version: [18, 20, 22]
181+
os:
182+
- ubuntu-latest
183+
- macos-latest
184+
185+
steps:
186+
- name: Checkout
187+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
188+
189+
- name: Set up QEMU
190+
if: startsWith(matrix.os, 'ubuntu-')
191+
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
192+
193+
- name: Setup Node.js ${{ matrix.node-version }}
194+
if: startsWith(matrix.os, 'macos-')
195+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
196+
with:
197+
node-version: ${{ matrix.node-version }}
198+
cache: npm
199+
200+
- name: Install dependencies
201+
if: startsWith(matrix.os, 'macos-')
202+
run: |
203+
npm ci
204+
npm run dist
205+
206+
- name: Test
207+
if: startsWith(matrix.os, 'macos-')
208+
run: |
209+
npm test
210+
211+
- name: Install dependencies and test
212+
if: startsWith(matrix.os, 'ubuntu-')
213+
run: |
214+
docker run \
215+
--rm \
216+
-v $(pwd):/${{ github.workspace }} \
217+
-w /${{ github.workspace }} \
218+
--platform linux/arm64 \
219+
node:${{ matrix.node-version }}-alpine \
220+
sh -c "npm ci && npm run dist && npm test"
221+
222+
examples:
223+
name: >-
224+
Test Examples
225+
on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
226+
with Node ${{ matrix.node-version }}
227+
228+
runs-on: ${{ matrix.os }}
229+
needs:
230+
- test-x86
231+
232+
strategy:
233+
fail-fast: false
234+
matrix:
235+
node-version: [22]
236+
os: [ubuntu-latest]
237+
d:
238+
- e2e
239+
- graphql
240+
- jest
241+
- messages
242+
- mocha
243+
- serverless
244+
- typescript
245+
- v3
246+
- v4
247+
248+
steps:
249+
- name: Checkout
250+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
251+
252+
- name: Setup Node.js ${{ matrix.node-version }}
253+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
254+
with:
255+
node-version: ${{ matrix.node-version }}
256+
cache: npm
257+
258+
- name: Download dist folder
259+
uses: actions/download-artifact@v4
260+
with:
261+
name: dist
262+
263+
- name: Run tests
264+
working-directory: examples/${{ matrix.d }}
265+
run: |
266+
jq '.dependencies["@pact-foundation/pact"] = "file:../../dist"' package.json > package.json.tmp
267+
mv package.json.tmp package.json
268+
npm install
269+
npm run test:${{ matrix.d }}

0 commit comments

Comments
 (0)