Skip to content

Commit 39ab5e8

Browse files
authored
fix(ci): compute the correct hash (#438)
1 parent 93439e7 commit 39ab5e8

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ runs:
5454
- name: Compute cache common hash
5555
if: inputs.type != 'minimal'
5656
shell: bash
57-
run: echo "CACHE_COMMON_HASH=${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED_HASH }}-${{ steps.diff.outputs.SCRIPTS_CHANGED_HASH }}" >> $GITHUB_ENV
57+
run: echo "CACHE_COMMON_HASH=${{ steps.diff.outputs.COMMON_HASH }}" >> $GITHUB_ENV
5858

5959
- name: Compute specs matrix
6060
if: inputs.type != 'minimal'

.github/workflows/check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ jobs:
370370
needs:
371371
- setup
372372
- client_javascript
373+
- client_javascript_algoliasearch
373374
- client_java
374375
- client_php
375376
if: |

scripts/ci/setRunVariables.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable no-console */
2-
import type { HashElementOptions } from 'folder-hash';
2+
import crypto from 'crypto';
3+
34
import { hashElement } from 'folder-hash';
45

6+
import { toAbsolutePath } from '../common';
7+
58
import { getNbGitDiff } from './utils';
69

710
const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
@@ -16,20 +19,10 @@ const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript';
1619
*
1720
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
1821
*/
19-
const VARIABLES_TO_CHECK: Array<{
20-
name: string;
21-
path: string[];
22-
needHash?: boolean;
23-
hashOptions?: HashElementOptions;
24-
}> = [
22+
const VARIABLES_TO_CHECK = [
2523
{
2624
name: 'GITHUB_ACTIONS_CHANGED',
2725
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-
},
3326
},
3427
{
3528
name: 'SPECS_CHANGED',
@@ -46,10 +39,6 @@ const VARIABLES_TO_CHECK: Array<{
4639
{
4740
name: 'SCRIPTS_CHANGED',
4841
path: ['scripts'],
49-
needHash: true,
50-
hashOptions: {
51-
folders: { include: ['scripts'] },
52-
},
5342
},
5443
{
5544
name: 'GENERATORS_CHANGED',
@@ -106,6 +95,28 @@ const VARIABLES_TO_CHECK: Array<{
10695
},
10796
];
10897

98+
async function computeCommonHash(): Promise<string> {
99+
const hashGA = await hashElement(toAbsolutePath('.github'), {
100+
encoding: 'hex',
101+
folders: { exclude: ['ISSUE_TEMPLATE'] },
102+
files: { include: ['*.yml', '.cache_version'] },
103+
});
104+
const hashScripts = await hashElement(toAbsolutePath('scripts'), {
105+
encoding: 'hex',
106+
folders: { exclude: ['docker', '__tests__'] },
107+
});
108+
const hashConfig = await hashElement(toAbsolutePath('.'), {
109+
encoding: 'hex',
110+
folders: { include: ['config'] },
111+
files: { include: ['openapitools.json', 'clients.config.json'] },
112+
});
113+
114+
return crypto
115+
.createHash('sha256')
116+
.update(`${hashGA.hash}-${hashScripts.hash}-${hashConfig.hash}`)
117+
.digest('hex');
118+
}
119+
109120
/**
110121
* Outputs variables used in the CI to determine if a job should run.
111122
*/
@@ -124,14 +135,10 @@ async function setRunVariables({
124135

125136
console.log(`Found ${diff} changes for '${check.name}'`);
126137
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-
}
133138
}
134139

140+
console.log(`::set-output name=COMMON_HASH::${await computeCommonHash()}`);
141+
135142
console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`);
136143
}
137144

0 commit comments

Comments
 (0)