Skip to content

Commit acca4d2

Browse files
authored
chore(ci): include common changes to cache version (#433)
1 parent fd6b910 commit acca4d2

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

.github/.cache_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.0.10.0.8
1+
8.0.11

.github/actions/cache/action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ inputs:
99
language:
1010
description: The language to retrieve dependencies.
1111
required: false
12+
cache_hash:
13+
description: The cache hash from github actions and scripts
14+
required: false
1215

1316
runs:
1417
using: composite
1518
steps:
1619
- name: Read current GitHub Actions cache version
1720
shell: bash
18-
run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV
21+
run: |
22+
echo "CACHE_VERSION_YARN=$(< .github/.cache_version)" >> $GITHUB_ENV
23+
echo "CACHE_VERSION=$(< .github/.cache_version)-${{ inputs.cache_hash }}" >> $GITHUB_ENV
1924
2025
# JavaScript setup
2126
- name: Get yarn cache directory path
@@ -27,7 +32,7 @@ runs:
2732
uses: actions/cache@v2
2833
with:
2934
path: ${{ steps.yarn-cache-dir.outputs.dir || '.yarn/cache' }}
30-
key: node-cache-${{ env.CACHE_VERSION }}-yarn-${{ hashFiles('yarn.lock') }}
35+
key: node-cache-${{ env.CACHE_VERSION_YARN }}-yarn-${{ hashFiles('yarn.lock') }}
3136

3237
# Java setup: used during 'java' generation or 'cts'
3338
- name: Download Java formatter

.github/actions/setup/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ runs:
3535
node-version-file: .nvmrc
3636
cache: yarn
3737

38-
- name: Restore cache
38+
- name: Run yarn install and install java formatter
3939
uses: ./.github/actions/cache
4040
with:
41-
# We want to load the java formatter
4241
language: java
4342

4443
- name: Setting diff outputs variables
@@ -52,6 +51,11 @@ runs:
5251
5352
yarn workspace scripts setRunVariables "$origin"
5453
54+
- name: Compute cache common hash
55+
if: inputs.type != 'minimal'
56+
shell: bash
57+
run: echo "CACHE_COMMON_HASH=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED_HASH }}-${{ steps.diff.outputs.SCRIPTS_CHANGED_HASH }}" >> $GITHUB_ENV
58+
5559
- name: Compute specs matrix
5660
if: inputs.type != 'minimal'
5761
id: spec-matrix

.github/workflows/check.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
run: yarn eslint --ext=json .
4141

4242
outputs:
43+
CACHE_COMMON_HASH: ${{ env.CACHE_COMMON_HASH }}
4344
RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }}
4445

4546
RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }}
@@ -71,6 +72,8 @@ jobs:
7172

7273
- name: Restore cache
7374
uses: ./.github/actions/cache
75+
with:
76+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
7477

7578
- name: Check script linting
7679
run: yarn scripts:lint
@@ -93,6 +96,8 @@ jobs:
9396

9497
- name: Restore cache
9598
uses: ./.github/actions/cache
99+
with:
100+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
96101

97102
- name: Cache '${{ matrix.client.name }}' bundled specs
98103
id: cache
@@ -126,6 +131,8 @@ jobs:
126131

127132
- name: Restore cache
128133
uses: ./.github/actions/cache
134+
with:
135+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
129136

130137
- name: Cache '${{ matrix.client }}' client
131138
id: cache
@@ -164,6 +171,7 @@ jobs:
164171
with:
165172
job: client
166173
language: javascript
174+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
167175

168176
- name: Cache '${{ matrix.client.name }}' client
169177
id: cache
@@ -215,6 +223,7 @@ jobs:
215223
with:
216224
job: client
217225
language: java
226+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
218227

219228
- name: Cache '${{ matrix.client.name }}' client
220229
id: cache
@@ -264,6 +273,7 @@ jobs:
264273
with:
265274
job: client
266275
language: php
276+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
267277

268278
- name: Cache '${{ matrix.client.name }}' client
269279
id: cache
@@ -295,7 +305,9 @@ jobs:
295305
client_javascript_algoliasearch:
296306
timeout-minutes: 10
297307
runs-on: ubuntu-20.04
298-
needs: client_javascript
308+
needs:
309+
- setup
310+
- client_javascript
299311
if: |
300312
always() &&
301313
needs.setup.outputs.RUN_JS_ALGOLIASEARCH == 'true' &&
@@ -309,6 +321,7 @@ jobs:
309321
with:
310322
job: codegen
311323
language: javascript
324+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
312325

313326
- name: Cache 'algoliasearch' client
314327
id: cache
@@ -331,7 +344,9 @@ jobs:
331344
client_javascript_tests:
332345
runs-on: ubuntu-20.04
333346
timeout-minutes: 10
334-
needs: client_javascript
347+
needs:
348+
- setup
349+
- client_javascript
335350
if: |
336351
always() &&
337352
needs.setup.outputs.RUN_JS_TESTS == 'true' &&
@@ -344,6 +359,7 @@ jobs:
344359
uses: ./.github/actions/cache
345360
with:
346361
job: cts
362+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
347363

348364
- name: Run client-common tests
349365
run: yarn workspace @experimental-api-clients-automation/client-common test
@@ -352,6 +368,7 @@ jobs:
352368
runs-on: ubuntu-20.04
353369
timeout-minutes: 20
354370
needs:
371+
- setup
355372
- client_javascript
356373
- client_java
357374
- client_php
@@ -371,6 +388,7 @@ jobs:
371388
uses: ./.github/actions/cache
372389
with:
373390
job: cts
391+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
374392

375393
- name: Push generated code to generated branch
376394
id: pushGeneratedCode
@@ -398,6 +416,7 @@ jobs:
398416
runs-on: ubuntu-20.04
399417
timeout-minutes: 10
400418
needs:
419+
- setup
401420
- cts
402421
- client_javascript_tests
403422
- client_javascript_algoliasearch
@@ -417,6 +436,7 @@ jobs:
417436
uses: ./.github/actions/cache
418437
with:
419438
job: codegen
439+
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}
420440

421441
- name: Push generated code to main
422442
id: pushGeneratedCode

scripts/ci/setRunVariables.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* eslint-disable no-console */
2+
import type { HashElementOptions } from 'folder-hash';
3+
import { hashElement } from 'folder-hash';
4+
25
import { getNbGitDiff } from './utils';
36

47
const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
@@ -13,10 +16,20 @@ const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
1316
*
1417
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
1518
*/
16-
const VARIABLES_TO_CHECK = [
19+
const VARIABLES_TO_CHECK: Array<{
20+
name: string;
21+
path: string[];
22+
needHash?: boolean;
23+
hashOptions?: HashElementOptions;
24+
}> = [
1725
{
1826
name: 'GITHUB_ACTIONS_CHANGED',
1927
path: ['.github/actions', '.github/workflows', '.github/.cache_version'],
28+
needHash: true,
29+
hashOptions: {
30+
folders: { include: ['.github/actions', '.github/workflows'] },
31+
files: { include: ['.github/.cache_version'] },
32+
},
2033
},
2134
{
2235
name: 'SPECS_CHANGED',
@@ -33,6 +46,10 @@ const VARIABLES_TO_CHECK = [
3346
{
3447
name: 'SCRIPTS_CHANGED',
3548
path: ['scripts'],
49+
needHash: true,
50+
hashOptions: {
51+
folders: { include: ['scripts'] },
52+
},
3653
},
3754
{
3855
name: 'GENERATORS_CHANGED',
@@ -107,6 +124,12 @@ async function setRunVariables({
107124

108125
console.log(`Found ${diff} changes for '${check.name}'`);
109126
console.log(`::set-output name=${check.name}::${diff}`);
127+
if (diff && check.needHash) {
128+
const hash = (
129+
await hashElement('.', { encoding: 'hex', ...check.hashOptions })
130+
).hash;
131+
console.log(`::set-output name=${check.name}_HASH::${hash}`);
132+
}
110133
}
111134

112135
console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`);

0 commit comments

Comments
 (0)