Skip to content

Commit 578be2c

Browse files
committed
chore: fix CI matrix, fix job skipping
1 parent c174a8b commit 578be2c

File tree

6 files changed

+63
-30
lines changed

6 files changed

+63
-30
lines changed

.github/.cache_version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

.github/actions/cache/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
runs:
1414
using: composite
1515
steps:
16+
- name: Read current GitHub Actions cache version
17+
shell: bash
18+
run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV
19+
1620
# JavaScript setup
1721
- name: Get yarn cache directory path
1822
shell: bash

.github/actions/setup/action.yml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ description: Setup CI environment.
55
runs:
66
using: composite
77
steps:
8+
- name: Read current GitHub Actions cache version
9+
shell: bash
10+
run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV
11+
812
- name: Install Java
913
uses: actions/setup-java@v2
1014
with:
@@ -29,9 +33,11 @@ runs:
2933
shell: bash
3034
run: |
3135
previousCommit=${{ github.event.before }}
32-
baseRef=${{ steps.diff.outputs.ORIGIN_BRANCH }}
36+
baseRef=${{ github.base_ref }}
3337
origin=$( [[ -z $baseRef ]] && echo $previousCommit || echo "origin/$baseRef" )
3438
39+
echo "Checking diff with branch: $origin"
40+
3541
echo "::set-output name=GITHUB_ACTIONS_CHANGED::$(git diff --shortstat $origin..HEAD -- .github/actions .github/workflows | wc -l)"
3642
3743
echo "::set-output name=SPECS_CHANGED::$(git diff --shortstat $origin..HEAD -- specs | wc -l)"
@@ -87,9 +93,9 @@ runs:
8793
algoliasearch_client='{"name": "algoliasearch","folder": "clients/algoliasearch-client-javascript/packages/algoliasearch"}'
8894
8995
if [[ $matrix == '{"client":["no-run"]}' ]]; then
90-
matrix="{'client': [$algoliasearch_client]}"
96+
matrix="{\"client\": [$algoliasearch_client]}"
9197
else
92-
matrix="{'client': $(echo $matrix | jq ".client + [$algoliasearch_client]" -c)}"
98+
matrix="{\"client\": $(echo $matrix | jq ".client + [$algoliasearch_client]" -c)}"
9399
fi
94100
fi
95101
@@ -152,41 +158,61 @@ runs:
152158
153159
outputs:
154160
RUN_SPECS:
155-
description: Whether to run specs or not
161+
description: Determine if the `specs` job should run
156162
value: ${{ steps.spec-matrix.outputs.RUN_SPECS }}
157163

164+
RUN_SCRIPTS:
165+
description: Determine if the `scripts` job should run
166+
value: ${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 }}
167+
158168
SPECS_MATRIX:
159-
description: Generate the matrix for specs
169+
description: The generated `specs` matrix
160170
value: ${{ steps.spec-matrix.outputs.MATRIX }}
161171

162172
RUN_JS:
163-
description: Whether to run js client or not
173+
description: Determine if the `client-javascript` job should run
164174
value: ${{ steps.js-matrix.outputs.RUN_CLIENT }}
165175

166176
RUN_JS_COMMON:
167177
description: Whether to build JS client common folders when RUN_JS is false
168178
value: ${{ steps.js-matrix.outputs.RUN_COMMON }}
169179

170180
JS_MATRIX:
171-
description: Generate the matrix for the Javascript client
181+
description: The generated `client-javascript` matrix
172182
value: ${{ steps.js-matrix.outputs.MATRIX }}
173183

174184
RUN_JAVA:
175-
description: Whether to run java client or not
185+
description: Determine if the `client-java` job should run
176186
value: ${{ steps.java-matrix.outputs.RUN_CLIENT }}
177187

178188
JAVA_MATRIX:
179-
description: Generate the matrix for the Java client
189+
description: The generated `client-java` matrix
180190
value: ${{ steps.java-matrix.outputs.MATRIX }}
181191

182192
RUN_PHP:
183-
description: Whether to run php client or not
193+
description: Determine if the `client-php` job should run
184194
value: ${{ steps.php-matrix.outputs.RUN_CLIENT }}
185195

186196
PHP_MATRIX:
187-
description: Generate the matrix for the PHP client
197+
description: The generated `client-php` matrix
188198
value: ${{ steps.php-matrix.outputs.MATRIX }}
189199

190200
RUN_CTS:
191201
description: Determine if the `cts` job should run
192-
value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.SPECS_CHANGED > 0 || steps.diff.outputs.TESTS_CHANGED > 0 || steps.diff.outputs.JS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}
202+
value: ${{
203+
steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 ||
204+
steps.diff.outputs.SCRIPTS_CHANGED > 0 ||
205+
steps.diff.outputs.SPECS_CHANGED > 0 ||
206+
steps.diff.outputs.TESTS_CHANGED > 0 ||
207+
steps.diff.outputs.JS_CLIENT_CHANGED > 0 ||
208+
steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 ||
209+
steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 ||
210+
steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}
211+
212+
RUN_CODEGEN:
213+
description: Determine if the `codegen` job should run
214+
value: ${{
215+
steps.spec-matrix.outputs.RUN_SPECS == 'true' ||
216+
steps.js-matrix.outputs.RUN_CLIENT == 'true' ||
217+
steps.java-matrix.outputs.RUN_CLIENT == 'true' ||
218+
steps.php-matrix.outputs.RUN_CLIENT == 'true' }}

.github/workflows/check.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ on:
77
branches:
88
- main
99

10-
env:
11-
CACHE_VERSION: '9'
12-
1310
concurrency:
1411
group: ${{ github.ref }}
1512
cancel-in-progress: true
@@ -31,6 +28,8 @@ jobs:
3128
run: yarn github-actions:lint
3229

3330
outputs:
31+
RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }}
32+
3433
RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }}
3534
SPECS_MATRIX: ${{ steps.setup.outputs.SPECS_MATRIX }}
3635

@@ -46,10 +45,13 @@ jobs:
4645

4746
RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}
4847

48+
RUN_CODEGEN: ${{ steps.setup.outputs.RUN_CODEGEN }}
49+
4950
scripts:
5051
runs-on: ubuntu-20.04
51-
needs: setup
5252
timeout-minutes: 20
53+
needs: setup
54+
if: ${{ needs.setup.outputs.RUN_SCRIPTS == 'true' }}
5355
steps:
5456
- uses: actions/checkout@v2
5557

@@ -66,7 +68,7 @@ jobs:
6668
runs-on: ubuntu-20.04
6769
timeout-minutes: 10
6870
needs: setup
69-
if: ${{ always() && needs.setup.outputs.RUN_SPECS == 'true' }}
71+
if: ${{ needs.setup.outputs.RUN_SPECS == 'true' }}
7072
strategy:
7173
matrix: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX) }}
7274
steps:
@@ -95,7 +97,7 @@ jobs:
9597
timeout-minutes: 10
9698
runs-on: ubuntu-20.04
9799
needs: setup
98-
if: ${{ always() && needs.setup.outputs.RUN_JS_COMMON == 'true' }}
100+
if: ${{ needs.setup.outputs.RUN_JS_COMMON == 'true' }}
99101
strategy:
100102
matrix:
101103
client:
@@ -131,7 +133,7 @@ jobs:
131133
- setup
132134
- specs
133135
- client_javascript_common
134-
if: ${{ always() && needs.setup.outputs.RUN_JS == 'true' }}
136+
if: ${{ needs.setup.outputs.RUN_JS == 'true' }}
135137
strategy:
136138
matrix: ${{ fromJSON(needs.setup.outputs.JS_MATRIX) }}
137139
steps:
@@ -170,7 +172,7 @@ jobs:
170172
needs:
171173
- setup
172174
- specs
173-
if: ${{ always() && needs.setup.outputs.RUN_JAVA == 'true' }}
175+
if: ${{ needs.setup.outputs.RUN_JAVA == 'true' }}
174176
strategy:
175177
matrix: ${{ fromJSON(needs.setup.outputs.JAVA_MATRIX) }}
176178
steps:
@@ -209,7 +211,7 @@ jobs:
209211
needs:
210212
- setup
211213
- specs
212-
if: ${{ always() && needs.setup.outputs.RUN_PHP == 'true' }}
214+
if: ${{ needs.setup.outputs.RUN_PHP == 'true' }}
213215
strategy:
214216
matrix: ${{ fromJSON(needs.setup.outputs.PHP_MATRIX) }}
215217
steps:
@@ -248,7 +250,11 @@ jobs:
248250
- client_javascript
249251
- client_java
250252
- client_php
251-
if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
253+
if: |
254+
always() &&
255+
needs.setup.outputs.RUN_CTS == 'true' &&
256+
contains(needs.*.result, 'success') &&
257+
!contains(needs.*.result, 'failure')
252258
steps:
253259
- uses: actions/checkout@v2
254260

@@ -271,8 +277,11 @@ jobs:
271277
codegen:
272278
runs-on: ubuntu-20.04
273279
timeout-minutes: 10
274-
if: ${{ always() }}
275280
needs: cts
281+
if: |
282+
always() &&
283+
needs.setup.outputs.RUN_CODEGEN == 'true' &&
284+
needs.cts.result == 'success'
276285
steps:
277286
- uses: actions/checkout@v2
278287
with:

.github/workflows/codegen-cleanup.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
pull_request:
55
types: [closed]
66

7-
env:
8-
CACHE_VERSION: '9'
9-
107
jobs:
118
codegen:
129
runs-on: ubuntu-20.04
@@ -18,7 +15,6 @@ jobs:
1815
ref: main
1916

2017
- name: Setup
21-
id: setup
2218
uses: ./.github/actions/setup
2319

2420
- name: Clean previously generated branch

.github/workflows/process-release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ on:
55
types:
66
- closed
77

8-
env:
9-
CACHE_VERSION: '9'
10-
118
jobs:
129
build:
1310
name: Release

0 commit comments

Comments
 (0)