Skip to content

Commit 22c18b1

Browse files
committed
Merge branch 'feat/APIC-456/request-options-php' of https://github.com/algolia/api-clients-automation into feat/APIC-456/request-options-php
2 parents 18f381e + e43b770 commit 22c18b1

File tree

4 files changed

+65
-88
lines changed

4 files changed

+65
-88
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 & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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

@@ -65,6 +65,20 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
6565
continue;
6666
}
6767

68+
const languageDependencies = Object.entries(DEPENDENCIES).reduce(
69+
(finalDeps, [key, deps]) => {
70+
if (key.startsWith(`${language.toUpperCase()}_`)) {
71+
return {
72+
...finalDeps,
73+
[key]: deps,
74+
};
75+
}
76+
77+
return finalDeps;
78+
},
79+
{} as Record<string, string[]>
80+
);
81+
6882
const bundledSpec = client === 'algoliasearch-lite' ? 'search' : client;
6983
const specChanges = await getNbGitDiff({
7084
branch: baseBranch,
@@ -75,17 +89,15 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
7589
path: output,
7690
});
7791
const baseChanged = await isBaseChanged(baseBranch, {
78-
...MATRIX_DEPENDENCIES.common,
79-
...MATRIX_DEPENDENCIES.clients.common,
80-
...MATRIX_DEPENDENCIES.clients[language],
92+
...COMMON_DEPENDENCIES,
93+
...languageDependencies,
8194
});
8295

8396
// No changes found, we don't put this job in the matrix
8497
if (clientChanges === 0 && specChanges === 0 && !baseChanged) {
8598
continue;
8699
}
87100

88-
console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`);
89101
matrix[language].toRun.push(client);
90102
matrix[language].cacheToCompute.push(`specs/${bundledSpec}`);
91103
}
@@ -114,6 +126,7 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
114126
language
115127
)}`,
116128
});
129+
console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`);
117130
}
118131

119132
const shouldRun = clientMatrix.client.length > 0;
@@ -126,7 +139,7 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
126139
);
127140
}
128141

129-
async function getSpecMatrix(baseBranch: string): Promise<void> {
142+
async function getSpecMatrix(): Promise<void> {
130143
const matrix: ToRunMatrix = {
131144
path: 'specs/bundled',
132145
toRun: [],
@@ -136,31 +149,9 @@ async function getSpecMatrix(baseBranch: string): Promise<void> {
136149
for (const client of CLIENTS) {
137150
// The `algoliasearch-lite` spec is created by the `search` spec
138151
const bundledSpecName = client === 'algoliasearch-lite' ? 'search' : client;
139-
const path = `specs/${bundledSpecName}`;
140-
const specChanges = await getNbGitDiff({
141-
branch: baseBranch,
142-
path,
143-
});
144-
const baseChanged = await isBaseChanged(baseBranch, {
145-
...MATRIX_DEPENDENCIES.common,
146-
...MATRIX_DEPENDENCIES.clients.common,
147-
});
148-
149-
// No changes found, we don't put this job in the matrix
150-
if (specChanges === 0 && !baseChanged) {
151-
continue;
152-
}
153152

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

166157
const ciMatrix: Matrix<SpecMatrix> = {
@@ -177,7 +168,6 @@ async function getSpecMatrix(baseBranch: string): Promise<void> {
177168
],
178169
};
179170

180-
console.log('::set-output name=RUN_SPECS::true');
181171
console.log(`::set-output name=MATRIX::${JSON.stringify(ciMatrix)}`);
182172
}
183173

@@ -189,7 +179,7 @@ async function createMatrix(opts: CreateMatrix): Promise<void> {
189179
return await getClientMatrix(opts.baseBranch);
190180
}
191181

192-
return await getSpecMatrix(opts.baseBranch);
182+
return await getSpecMatrix();
193183
}
194184

195185
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)