Skip to content

Commit d22e05f

Browse files
authored
chore: fix specs run condition (#488)
1 parent f516c24 commit d22e05f

File tree

4 files changed

+65
-114
lines changed

4 files changed

+65
-114
lines changed

.github/actions/setup/action.yml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ runs:
9898
echo "::set-output name=RUN_JS_ALGOLIASEARCH::true"
9999
fi
100100
101-
if [[ ${{ steps.gen-matrix.outputs.RUN_GEN_JAVASCRIPT || steps.diff.outputs.JS_UTILS_CHANGED > 0 }} ]]; then
101+
if [[ ${{ steps.gen-matrix.outputs.RUN_GEN_JAVASCRIPT || steps.diff.outputs.JAVASCRIPT_UTILS_CHANGED > 0 }} ]]; then
102102
echo "Running JavaScript utils: true"
103103
echo "::set-output name=RUN_JS_UTILS::true"
104104
fi
@@ -108,9 +108,6 @@ outputs:
108108
description: Determine if the `scripts` job should run
109109
value: ${{ steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 }}
110110

111-
RUN_SPECS:
112-
description: Determine if the `specs` job should run
113-
value: ${{ steps.spec-matrix.outputs.RUN_SPECS }}
114111
SPECS_MATRIX:
115112
description: The generated `specs` matrix
116113
value: ${{ steps.spec-matrix.outputs.MATRIX }}
@@ -132,20 +129,6 @@ outputs:
132129
description: Determine if the `client_javascript_tests` job should run
133130
value: ${{ steps.diff.outputs.JS_COMMON_TESTS_CHANGED > 0 }}
134131

135-
RUN_CTS:
136-
description: Determine if the `cts` jobs should run
137-
value: ${{
138-
steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 ||
139-
steps.diff.outputs.SCRIPTS_CHANGED > 0 ||
140-
steps.diff.outputs.SHOULD_RUN_SPECS > 0 ||
141-
steps.diff.outputs.TESTS_CHANGED > 0 ||
142-
steps.diff.outputs.JS_CLIENT_CHANGED > 0 ||
143-
steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 ||
144-
steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 ||
145-
steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}
146-
147132
RUN_CODEGEN:
148133
description: Determine if the `codegen` job should run
149-
value: ${{
150-
steps.spec-matrix.outputs.RUN_SPECS == 'true' ||
151-
steps.gen-matrix.outputs.RUN_GEN == 'true' }}
134+
value: ${{ steps.gen-matrix.outputs.RUN_GEN == 'true' }}

.github/workflows/check.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jobs:
5050
outputs:
5151
RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }}
5252

53-
RUN_SPECS: ${{ steps.setup.outputs.RUN_SPECS }}
5453
SPECS_MATRIX: ${{ steps.setup.outputs.SPECS_MATRIX }}
5554

5655
RUN_GEN: ${{ steps.setup.outputs.RUN_GEN }}
@@ -60,8 +59,6 @@ jobs:
6059
RUN_JS_UTILS: ${{ steps.setup.outputs.RUN_JS_UTILS }}
6160
RUN_JS_TESTS: ${{ steps.setup.outputs.RUN_JS_TESTS }}
6261

63-
RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}
64-
6562
RUN_CODEGEN: ${{ steps.setup.outputs.RUN_CODEGEN }}
6663

6764
scripts:
@@ -90,7 +87,6 @@ jobs:
9087
runs-on: ubuntu-20.04
9188
timeout-minutes: 10
9289
needs: setup
93-
if: ${{ needs.setup.outputs.RUN_SPECS == 'true' }}
9490
strategy:
9591
matrix: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX) }}
9692
steps:
@@ -224,21 +220,17 @@ jobs:
224220
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toRun }}
225221

226222
- name: Clean CTS output before generate
227-
if: ${{ needs.setup.outputs.RUN_CTS == 'true' }}
228223
run: rm -rf ${{ matrix.client.testsOutputPath }}
229224

230225
- name: Generate CTS
231-
if: ${{ needs.setup.outputs.RUN_CTS == 'true' }}
232226
run: yarn cli cts generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}
233227

234228
- name: Check diff with pushed CTS
235-
if: ${{ needs.setup.outputs.RUN_CTS == 'true' }}
236229
run: |
237230
git --no-pager diff
238231
exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPath }} | wc -l)
239232
240233
- name: Run CTS
241-
if: ${{ needs.setup.outputs.RUN_CTS == 'true' }}
242234
run: yarn cli cts run ${{ matrix.client.language }}
243235

244236
- name: Zip artifact before storing

scripts/ci/githubActions/createMatrix.ts

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,13 @@ import { getLanguageFolder, getTestOutputFolder } from '../../config';
44
import type { Language } from '../../types';
55
import { getNbGitDiff } from '../utils';
66

7-
import { DEPENDENCIES } from './setRunVariables';
7+
import { DEPENDENCIES, COMMON_DEPENDENCIES } from './setRunVariables';
88
import type { ClientMatrix, CreateMatrix, Matrix, SpecMatrix } from './types';
99
import { computeCacheKey, isBaseChanged } from './utils';
1010

1111
// This empty matrix is required by the CI, otherwise it throws
1212
const EMPTY_MATRIX = { client: ['no-run'] };
1313

14-
/**
15-
* List of dependencies based on the language, inherited from `./setRunVariables.ts` in a more dynamic form.
16-
*/
17-
const MATRIX_DEPENDENCIES = {
18-
common: {
19-
GITHUB_ACTIONS_CHANGED: DEPENDENCIES.GITHUB_ACTIONS_CHANGED,
20-
SCRIPTS_CHANGED: DEPENDENCIES.SCRIPTS_CHANGED,
21-
COMMON_SPECS_CHANGED: DEPENDENCIES.COMMON_SPECS_CHANGED,
22-
},
23-
clients: {
24-
common: {
25-
GENERATORS_CHANGED: DEPENDENCIES.GENERATORS_CHANGED,
26-
},
27-
javascript: {
28-
JS_UTILS_CHANGED: DEPENDENCIES.JS_UTILS_CHANGED,
29-
JS_TEMPLATE_CHANGED: DEPENDENCIES.JS_TEMPLATE_CHANGED,
30-
},
31-
php: {
32-
PHP_TEMPLATE_CHANGED: DEPENDENCIES.PHP_TEMPLATE_CHANGED,
33-
},
34-
java: {
35-
JAVA_TEMPLATE_CHANGED: DEPENDENCIES.JAVA_TEMPLATE_CHANGED,
36-
},
37-
},
38-
};
39-
4014
type ToRunMatrix = {
4115
path: string;
4216
toRun: string[];
@@ -62,6 +36,20 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
6236
continue;
6337
}
6438

39+
const languageDependencies = Object.entries(DEPENDENCIES).reduce(
40+
(finalDeps, [key, deps]) => {
41+
if (key.startsWith(`${language.toUpperCase()}_`)) {
42+
return {
43+
...finalDeps,
44+
[key]: deps,
45+
};
46+
}
47+
48+
return finalDeps;
49+
},
50+
{} as Record<string, string[]>
51+
);
52+
6553
const bundledSpec = client === 'algoliasearch-lite' ? 'search' : client;
6654
const specChanges = await getNbGitDiff({
6755
branch: baseBranch,
@@ -72,17 +60,15 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
7260
path: output,
7361
});
7462
const baseChanged = await isBaseChanged(baseBranch, {
75-
...MATRIX_DEPENDENCIES.common,
76-
...MATRIX_DEPENDENCIES.clients.common,
77-
...MATRIX_DEPENDENCIES.clients[language],
63+
...COMMON_DEPENDENCIES,
64+
...languageDependencies,
7865
});
7966

8067
// No changes found, we don't put this job in the matrix
8168
if (clientChanges === 0 && specChanges === 0 && !baseChanged) {
8269
continue;
8370
}
8471

85-
console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`);
8672
matrix[language].toRun.push(client);
8773
matrix[language].cacheToCompute.push(`specs/${bundledSpec}`);
8874
}
@@ -111,6 +97,7 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
11197
language
11298
)}`,
11399
});
100+
console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`);
114101
}
115102

116103
const shouldRun = clientMatrix.client.length > 0;
@@ -123,7 +110,7 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
123110
);
124111
}
125112

126-
async function getSpecMatrix(baseBranch: string): Promise<void> {
113+
async function getSpecMatrix(): Promise<void> {
127114
const matrix: ToRunMatrix = {
128115
path: 'specs/bundled',
129116
toRun: [],
@@ -133,31 +120,9 @@ async function getSpecMatrix(baseBranch: string): Promise<void> {
133120
for (const client of CLIENTS) {
134121
// The `algoliasearch-lite` spec is created by the `search` spec
135122
const bundledSpecName = client === 'algoliasearch-lite' ? 'search' : client;
136-
const path = `specs/${bundledSpecName}`;
137-
const specChanges = await getNbGitDiff({
138-
branch: baseBranch,
139-
path,
140-
});
141-
const baseChanged = await isBaseChanged(baseBranch, {
142-
...MATRIX_DEPENDENCIES.common,
143-
...MATRIX_DEPENDENCIES.clients.common,
144-
});
145-
146-
// No changes found, we don't put this job in the matrix
147-
if (specChanges === 0 && !baseChanged) {
148-
continue;
149-
}
150123

151124
matrix.toRun.push(client);
152-
matrix.cacheToCompute.push(path);
153-
}
154-
155-
// We have nothing to run
156-
if (matrix.toRun.length === 0) {
157-
console.log('::set-output name=RUN_SPECS::false');
158-
console.log(`::set-output name=MATRIX::${JSON.stringify(EMPTY_MATRIX)}`);
159-
160-
return;
125+
matrix.cacheToCompute.push(`specs/${bundledSpecName}`);
161126
}
162127

163128
const ciMatrix: Matrix<SpecMatrix> = {
@@ -174,7 +139,6 @@ async function getSpecMatrix(baseBranch: string): Promise<void> {
174139
],
175140
};
176141

177-
console.log('::set-output name=RUN_SPECS::true');
178142
console.log(`::set-output name=MATRIX::${JSON.stringify(ciMatrix)}`);
179143
}
180144

@@ -186,7 +150,7 @@ async function createMatrix(opts: CreateMatrix): Promise<void> {
186150
return await getClientMatrix(opts.baseBranch);
187151
}
188152

189-
return await getSpecMatrix(opts.baseBranch);
153+
return await getSpecMatrix();
190154
}
191155

192156
if (require.main === module) {

scripts/ci/githubActions/setRunVariables.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,72 @@ const PHP_CLIENT_FOLDER = getLanguageFolder('php');
1111
const CLIENTS_COMMON_FILES = [
1212
'config/openapitools.json',
1313
'config/clients.config.json',
14+
'generators/src/main/java/com/algolia/codegen/Utils.java',
1415
];
1516

17+
/**
18+
* Dependencies that are common to every specs, clients or CTS jobs.
19+
*/
20+
export const COMMON_DEPENDENCIES = {
21+
GITHUB_ACTIONS_CHANGED: [
22+
'.github/actions',
23+
'.github/workflows',
24+
'.github/.cache_version',
25+
],
26+
SCRIPTS_CHANGED: ['scripts'],
27+
COMMON_SPECS_CHANGED: ['specs/common'],
28+
};
29+
1630
/**
1731
* Exhaustive list of output variables to use in the CI.
1832
*
1933
* Those variables are used to determine if jobs should run, based on the changes
20-
* made in their respective `path`s.
34+
* made in their respective dependencies.
2135
*
2236
* Negative paths should start with `:!`.
2337
*
2438
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
39+
*
40+
* Variables starting by `LANGUAGENAME_` will be used in the `createMatrix` to determine
41+
* if a job should be added.
2542
*/
2643
export const DEPENDENCIES = {
27-
GITHUB_ACTIONS_CHANGED: [
28-
'.github/actions',
29-
'.github/workflows',
30-
'.github/.cache_version',
31-
],
32-
SHOULD_RUN_SPECS: [
33-
...CLIENTS_COMMON_FILES,
34-
'specs',
35-
'templates',
36-
'generators',
37-
':!specs/bundled',
38-
],
39-
COMMON_SPECS_CHANGED: ['specs/common'],
44+
...COMMON_DEPENDENCIES,
4045
TESTS_CHANGED: ['tests'],
41-
SCRIPTS_CHANGED: ['scripts'],
42-
GENERATORS_CHANGED: ['generators'],
43-
JS_CLIENT_CHANGED: [
44-
...CLIENTS_COMMON_FILES,
45-
JS_CLIENT_FOLDER,
46-
`:!${JS_CLIENT_FOLDER}/.github`,
47-
`:!${JS_CLIENT_FOLDER}/README.md`,
48-
],
4946
JS_ALGOLIASEARCH_CHANGED: [
5047
`${JS_CLIENT_FOLDER}/packages/algoliasearch`,
5148
`${JS_CLIENT_FOLDER}/packages/client-search`,
5249
`${JS_CLIENT_FOLDER}/packages/client-analytics`,
5350
`${JS_CLIENT_FOLDER}/packages/client-personalization`,
5451
],
55-
JS_UTILS_CHANGED: [
52+
JS_COMMON_TESTS_CHANGED: [
53+
`${JS_CLIENT_FOLDER}/packages/client-common/src/__tests__`,
54+
],
55+
JAVASCRIPT_UTILS_CHANGED: [
5656
`${JS_CLIENT_FOLDER}/packages/client-common`,
5757
`${JS_CLIENT_FOLDER}/packages/requester-browser-xhr`,
5858
`${JS_CLIENT_FOLDER}/packages/requester-node-http`,
5959
],
60-
JS_COMMON_TESTS_CHANGED: [
61-
`${JS_CLIENT_FOLDER}/packages/client-common/src/__tests__`,
60+
JAVASCRIPT_CLIENT_CHANGED: [
61+
...CLIENTS_COMMON_FILES,
62+
JS_CLIENT_FOLDER,
63+
'templates/javascript',
64+
'generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java',
65+
`:!${JS_CLIENT_FOLDER}/.github`,
66+
`:!${JS_CLIENT_FOLDER}/README.md`,
67+
],
68+
JAVA_CLIENT_CHANGED: [
69+
...CLIENTS_COMMON_FILES,
70+
JAVA_CLIENT_FOLDER,
71+
'templates/java',
72+
'generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java',
73+
],
74+
PHP_CLIENT_CHANGED: [
75+
...CLIENTS_COMMON_FILES,
76+
PHP_CLIENT_FOLDER,
77+
'templates/php',
78+
'generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java',
6279
],
63-
JS_TEMPLATE_CHANGED: ['templates/javascript'],
64-
JAVA_CLIENT_CHANGED: [...CLIENTS_COMMON_FILES, JAVA_CLIENT_FOLDER],
65-
JAVA_TEMPLATE_CHANGED: ['templates/java'],
66-
PHP_CLIENT_CHANGED: [...CLIENTS_COMMON_FILES, PHP_CLIENT_FOLDER],
67-
PHP_TEMPLATE_CHANGED: ['templates/php'],
6880
};
6981

7082
/**

0 commit comments

Comments
 (0)