Skip to content

Commit 7f2de01

Browse files
authoredJan 14, 2023
chore: improve integration test workflow (#4015)
* create action `echo` to echo values to the log * create action `output` to set output values * create action `summary` to easily add to the job summary * create action `build-for-integrations` to simplify the build/cache process
1 parent 750ddd9 commit 7f2de01

File tree

6 files changed

+302
-80
lines changed

6 files changed

+302
-80
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Build and Cache Dist
2+
description: Build the repo and store it in the cache.
3+
4+
inputs:
5+
show-summary:
6+
description: Show a build summary.
7+
required: false
8+
node-version:
9+
required: false
10+
description: The version of Node to use.
11+
use-setup:
12+
required: false
13+
description: |
14+
Run node setup if it is necessary to build.
15+
16+
outputs:
17+
key:
18+
description: Cache Key
19+
value: ${{ steps.cache-key.outputs.value }}
20+
path:
21+
description: Cache Path
22+
value: ${{ steps.cache-path.outputs.value }}
23+
cache-hit:
24+
description: |
25+
Indicates that the cache was hit.
26+
Return values:
27+
- 'true' - the cache was used.
28+
- '' - the cache was not used.
29+
value: ${{ steps.step-cache-build.outputs.cache-hit }}
30+
31+
runs:
32+
using: "composite"
33+
34+
steps:
35+
- name: Inputs
36+
shell: bash
37+
env:
38+
INPUTS: ${{ toJSON(inputs || github.event.inputs) }}
39+
run: |
40+
echo "inputs: $INPUTS"
41+
42+
- id: cache-path
43+
uses: ./.github/actions/output
44+
with:
45+
value: |
46+
packages/*/dist
47+
integration-tests/dist
48+
show: true
49+
50+
- id: cache-key
51+
uses: ./.github/actions/output
52+
with:
53+
value: >-
54+
integrations-build-${{ hashFiles(
55+
'integration-tests/src/**/*.ts', 'integration-tests/tsconfig.json',
56+
'*-lock.yaml', 'packages/*/src/**/*.ts', 'packages/*/tsconfig.json'
57+
) }}
58+
show: true
59+
60+
- name: Cache Build
61+
id: step-cache-build
62+
uses: actions/cache@v3
63+
with:
64+
key: ${{ steps.cache-key.outputs.value }}
65+
path: ${{ steps.cache-path.outputs.value }}
66+
67+
- name: Cached Results
68+
uses: ./.github/actions/echo
69+
with:
70+
value: >-
71+
Build Cache: ${{ steps.step-cache-build.outputs.cache-hit && 'Hit' || 'Miss' }}
72+
73+
- name: Setup Env
74+
if: ${{ !steps.step-cache-build.outputs.cache-hit && inputs.use-setup }}
75+
uses: ./.github/actions/setup
76+
with:
77+
node-version: ${{ inputs.node-version }}
78+
79+
- name: Pnpm CI
80+
if: ${{ !steps.step-cache-build.outputs.cache-hit }}
81+
run: pnpm i
82+
shell: bash
83+
84+
- name: Has Pnpm has failed?
85+
if: ${{ failure() }}
86+
run: |
87+
ls -alF /home/runner/.pnpm/_logs/*.log
88+
cat /home/runner/.pnpm/_logs/*.log
89+
shell: bash
90+
91+
- name: Build
92+
if: ${{ !steps.step-cache-build.outputs.cache-hit }}
93+
run: pnpm run build
94+
shell: bash
95+
96+
- name: Summary
97+
if: inputs.show-summary == 'true'
98+
uses: ./.github/actions/summary
99+
with:
100+
text: |
101+
## Build
102+
- key: ${{ steps.cache-key.outputs.value }}
103+
- path:
104+
```
105+
${{ steps.cache-path.outputs.value }}
106+
```
107+
- hit: ${{ steps.step-cache-build.outputs.cache-hit || 'Miss' }}

‎.github/actions/echo/action.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: echo
2+
description: Echo the input as output
3+
4+
inputs:
5+
value:
6+
description: The Value to return.
7+
required: true
8+
show:
9+
description: Show the value in the console.
10+
default: "true"
11+
required: false
12+
outputs:
13+
value:
14+
description: The value that was input.
15+
value: ${{ inputs.value }}
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Show
20+
if: inputs.show
21+
shell: bash
22+
env:
23+
VALUE: ${{ inputs.value }}
24+
run: |
25+
echo "$VALUE"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: list-integration-repos
2+
description: Export list of repositories to check.
3+
4+
# Uses `integration-test/repo-list.sh`to generate.
5+
6+
outputs:
7+
repos:
8+
description: JSON list of integration test repositories
9+
value: ${{ steps.result.outputs.value }}
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Inputs
15+
uses: ./.github/actions/echo
16+
with:
17+
value: |
18+
inputs: ${{ toJSON(inputs) }}
19+
20+
- name: Gen List
21+
shell: bash
22+
run: |
23+
cd integration-tests
24+
echo "REPOS<<HEREDOC" >> $GITHUB_ENV
25+
./repo-list.sh >> $GITHUB_ENV
26+
echo HEREDOC >> $GITHUB_ENV
27+
28+
- name: Set Outputs
29+
id: result
30+
uses: ./.github/actions/output
31+
with:
32+
value: ${{ env.REPOS }}
33+
show: true

‎.github/actions/output/action.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: output
2+
description: Echo the input as output
3+
4+
inputs:
5+
value:
6+
description: The Value to return.
7+
required: true
8+
show:
9+
description: Show the value in the console.
10+
required: false
11+
outputs:
12+
value:
13+
description: The value that was input.
14+
value: ${{ inputs.value }}
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Show
19+
if: inputs.show
20+
shell: bash
21+
env:
22+
VALUE: ${{ inputs.value }}
23+
run: |
24+
echo "$VALUE"

‎.github/actions/summary/action.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Summary
2+
description: Send markdown to the step summary
3+
4+
inputs:
5+
text:
6+
description: The markdown text to send.
7+
required: true
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: write
12+
shell: bash
13+
env:
14+
VALUE: ${{ inputs.text }}
15+
run: |
16+
echo "$VALUE" >> $GITHUB_STEP_SUMMARY

‎.github/workflows/integration-test.yml

+97-80
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ on:
1010
- "*-lock.yaml"
1111
- ".github/workflows/integration-test.yml"
1212
- "!docs/**"
13-
push:
14-
branches:
15-
- main
16-
paths:
17-
- "packages/**/package.json"
18-
- "packages/**/*-lock.yaml"
19-
- "packages/**/*.ts"
20-
- "integration-tests/**"
21-
- "package.json"
22-
- "*-lock.yaml"
23-
- ".github/workflows/integration-test.yml"
24-
- "!docs/**"
13+
# push:
14+
# branches:
15+
# - main
16+
# paths:
17+
# - "packages/**/package.json"
18+
# - "packages/**/*-lock.yaml"
19+
# - "packages/**/*.ts"
20+
# - "integration-tests/**"
21+
# - "package.json"
22+
# - "*-lock.yaml"
23+
# - ".github/workflows/integration-test.yml"
24+
# - "!docs/**"
2525
# Run on demand
2626
workflow_dispatch:
2727
inputs:
@@ -38,58 +38,78 @@ env:
3838
NPM_VERSION: "8"
3939

4040
jobs:
41-
calc-ref:
41+
prepare:
4242
runs-on: ubuntu-latest
4343
env:
4444
REF_BRANCH: ${{ github.event.inputs.ref || github.ref }}
4545
outputs:
4646
ref: ${{ env.REF_BRANCH }}
4747
runs_on: ${{ env.RUNS_ON }}
4848
node_version: ${{ env.NODE_VERSION }}
49+
repos: ${{ steps.load-integrations.outputs.repos }}
4950
steps:
50-
- name: Refs
51-
run: |
52-
echo ref: "${{ env.REF_BRANCH }}"
53-
echo runs_on: "${{ env.RUNS_ON }}"
54-
echo node_version: ${{ env.NODE_VERSION }}
51+
- name: Checkout
52+
uses: actions/checkout@v3
53+
with:
54+
ref: ${{ env.REF_BRANCH }}
5555

56-
load-integrations:
57-
needs:
58-
- calc-ref
59-
uses: ./.github/workflows/reuseable-list-integration-repos.yml
60-
with:
61-
ref: ${{ needs.calc-ref.outputs.ref }}
56+
- name: Start Prepare
57+
uses: ./.github/actions/summary
58+
with:
59+
text: |
60+
# Prepare Integration
6261
63-
build:
64-
needs:
65-
- calc-ref
66-
uses: "./.github/workflows/reuseable-build-dist-cache.yml"
67-
with:
68-
ref: ${{ needs.calc-ref.outputs.ref }}
62+
- ref: "${{ env.REF_BRANCH }}"
63+
- runs_on: "${{ env.RUNS_ON }}"
64+
- node_version: ${{ env.NODE_VERSION }}
65+
66+
- name: load-integrations
67+
id: load-integrations
68+
uses: ./.github/actions/list-integration-repos
69+
70+
- name: Refs
71+
uses: ./.github/actions/summary
72+
with:
73+
text: |
74+
## Integrations
75+
```json
76+
${{ steps.load-integrations.outputs.repos }}
77+
```
78+
79+
- name: Pre-build and cache
80+
uses: ./.github/actions/build-for-integrations
81+
with:
82+
show-summary: true
83+
node-version: ${{ env.NODE_VERSION }}
84+
use-setup: true
85+
86+
- name: Done
87+
uses: ./.github/actions/summary
88+
with:
89+
text: |
90+
## Done
6991
7092
integration-tests:
7193
needs:
72-
- calc-ref
73-
- load-integrations
74-
- build
94+
- prepare
7595
runs-on: ${{ matrix.os }}
7696

7797
env:
78-
REF_BRANCH: ${{ needs.calc-ref.outputs.ref }}
98+
REF_BRANCH: ${{ needs.prepare.outputs.ref }}
7999

80100
strategy:
81101
# the integration tests are independent, so we want to run them all.
82102
fail-fast: false
83103
matrix:
84104
node-version:
85-
- ${{ needs.calc-ref.outputs.node_version }}
105+
- ${{ needs.prepare.outputs.node_version }}
86106

87107
os:
88-
- ${{ needs.calc-ref.outputs.runs_on }}
108+
- ${{ needs.prepare.outputs.runs_on }}
89109

90110
# List of repositories to check.
91111
# Use `repo-list.sh` in `integration-tests` to generate.
92-
repo: ${{ fromJSON(needs.load-integrations.outputs.repos) }}
112+
repo: ${{ fromJSON(needs.prepare.outputs.repos) }}
93113
# repo:
94114
# - prettier/prettier
95115
# - typescript-eslint/typescript-eslint
@@ -98,51 +118,62 @@ jobs:
98118
- name: Checkout
99119
uses: actions/checkout@v3
100120

101-
- name: Setup pnpm
102-
uses: pnpm/action-setup@v2.2.4
103-
104-
- name: Use Node.js ${{ matrix.node-version }}
105-
uses: actions/setup-node@v3
121+
- id: repo-hash
122+
uses: ./.github/actions/echo
106123
with:
107-
node-version: ${{ matrix.node-version }}
108-
cache: "pnpm"
109-
110-
- run: pnpm -v
124+
value: >-
125+
${{ hashFiles(
126+
'integration-tests/tsconfig.json',
127+
'integration-tests/config/repositories/${{matrix.repo}}/**',
128+
'integration-tests/snapshots/${{ matrix.repo }}/*',
129+
'integration-tests/repositories/*',
130+
'integration-tests/src/**/*.ts', 'integration-tests/tsconfig.json',
131+
'packages/*/src/**/*.ts', 'packages/*/tsconfig.json',
132+
'packages/*/*.ts',
133+
'*-lock.yaml'
134+
) }}
111135
112136
- name: Repo Info
113137
id: step-repo-info
114138
run: |
115139
echo "repo-info=$(jq -c '.repositories[] | select(.path == "${{ matrix.repo }}")' integration-tests/config/config.json)" >> $GITHUB_OUTPUT
116-
echo "repo-hash=${{ hashFiles(
117-
'integration-tests/tsconfig.json',
118-
'integration-tests/config/repositories/${{matrix.repo}}/**',
119-
'integration-tests/snapshots/${{ matrix.repo }}/*',
120-
'integration-tests/repositories/*',
121-
'integration-tests/src/**/*.ts', 'integration-tests/tsconfig.json',
122-
'packages/*/src/**/*.ts', 'packages/*/tsconfig.json',
123-
'packages/*/*.ts',
124-
'*-lock.yaml'
125-
) }}" >> $GITHUB_OUTPUT
140+
141+
- uses: ./.github/actions/echo
142+
with:
143+
value: |
144+
step.repo-hash: "${{ steps.repo-hash.outputs.value }}"
145+
env.repo-info: ${{ steps.step-repo-info.outputs.repo-info }}
146+
$repo-hash
126147
127148
- name: Cache Integration Run
128149
id: step-cache-run
129150
uses: actions/cache@v3
130151
with:
131-
key: int-repo-${{ steps.step-repo-info.outputs.repo-hash }}-${{ fromJSON(steps.step-repo-info.outputs.repo-info).commit }}
152+
key: integration-run-result-${{ steps.repo-hash.outputs.value }}-${{ fromJSON(steps.step-repo-info.outputs.repo-info).commit }}
153+
# We just need a path, its contents isn't important. We really just care if the key was cached.
132154
path: |
133155
integration-tests/tsconfig.json
134156
135-
- name: Cache Build
136-
id: step-cache-build
137-
uses: actions/cache@v3
157+
- uses: ./.github/actions/echo
138158
with:
139-
key: ${{ needs.build.outputs.key }}
140-
path: ${{ needs.build.outputs.path }}
159+
value: |
160+
Run Cache: ${{ steps.step-cache-run.outputs.cache-hit && 'Hit' || 'Miss' }}
141161
142-
- name: Cached Results
143-
run: |
144-
echo Build Cache: ${{ steps.step-cache-build.outputs.cache-hit && 'Hit' || 'Miss' }}
145-
echo Run Cache: ${{ steps.step-cache-run.outputs.cache-hit && 'Hit' || 'Miss' }}
162+
- name: Setup Env
163+
if: ${{ !steps.step-cache-run.outputs.cache-hit }}
164+
uses: ./.github/actions/setup
165+
with:
166+
node-version: ${{ matrix.node-version }}
167+
168+
- id: step-cache-build
169+
if: ${{ !steps.step-cache-run.outputs.cache-hit }}
170+
uses: ./.github/actions/build-for-integrations
171+
172+
- uses: ./.github/actions/echo
173+
if: ${{ !steps.step-cache-run.outputs.cache-hit }}
174+
with:
175+
value: |
176+
Run Cache: ${{ steps.step-cache-run.outputs.cache-hit && 'Hit' || 'Miss' }}
146177
147178
- name: Cache Integration Test Repository Files
148179
if: ${{ !steps.step-cache-run.outputs.cache-hit }}
@@ -152,20 +183,6 @@ jobs:
152183
path: |
153184
integration-tests/repositories/temp/${{ matrix.repo }}
154185
155-
- name: pnpm CI
156-
if: ${{ !steps.step-cache-build.outputs.cache-hit || !steps.step-cache-run.outputs.cache-hit }}
157-
run: pnpm i
158-
159-
- name: Has pnpm has failed?
160-
if: ${{ failure() }}
161-
run: |
162-
ls -alF /home/runner/.pnpm/_logs/*.log
163-
cat /home/runner/.pnpm/_logs/*.log
164-
165-
- name: Build
166-
if: ${{ !steps.step-cache-build.outputs.cache-hit }}
167-
run: pnpm run build
168-
169186
- name: Run Integration Tests ${{ matrix.repo }}
170187
if: ${{ !steps.step-cache-run.outputs.cache-hit }}
171188
env:

0 commit comments

Comments
 (0)
Please sign in to comment.