Skip to content

Commit 120ed46

Browse files
chore(ci): enable yarn hardened mode and immutable installs (API-476) (#6915)
1 parent 8eccb0c commit 120ed46

9 files changed

Lines changed: 34 additions & 17 deletions

File tree

โ€Ž.github/actions/setup/action.ymlโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ runs:
4646

4747
- name: Install JavaScript dependencies
4848
shell: bash
49-
run: YARN_ENABLE_HARDENED_MODE=0 YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
49+
run: YARN_ENABLE_HARDENED_MODE=1 yarn install
5050

5151
# Csharp
5252
- name: Install dotnet
@@ -107,7 +107,7 @@ runs:
107107
- name: Install JavaScript client dependencies
108108
if: ${{ inputs.language == 'javascript' }}
109109
shell: bash
110-
run: cd clients/algoliasearch-client-javascript && YARN_ENABLE_HARDENED_MODE=0 YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
110+
run: cd clients/algoliasearch-client-javascript && YARN_ENABLE_HARDENED_MODE=1 yarn install
111111

112112
# PHP
113113
- name: Install PHP

โ€Ž.github/workflows/check.ymlโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ jobs:
220220
run: yarn cli generate javascript
221221

222222
- name: Update `yarn.lock` for JavaScript
223-
run: cd clients/algoliasearch-client-javascript && YARN_ENABLE_HARDENED_MODE=0 YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
223+
run: cd clients/algoliasearch-client-javascript && YARN_ENABLE_HARDENED_MODE=1 YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
224224

225225
- name: Build clients
226226
run: cd clients/algoliasearch-client-javascript && yarn build

โ€Žclients/algoliasearch-client-javascript/.github/workflows/release.ymlโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- name: Install JavaScript dependencies
2929
shell: bash
30-
run: yarn install
30+
run: YARN_ENABLE_HARDENED_MODE=1 yarn install
3131

3232
- name: Build clients
3333
shell: bash

โ€Žscripts/buildLanguages.tsโ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from 'node:fs';
22

3-
import { createClientName, run, toAbsolutePath } from './common.ts';
3+
import { YARN_HARDENED_MODE_PREFIX, createClientName, run, toAbsolutePath } from './common.ts';
44
import { getLanguageFolder, getSwiftBuildFolder } from './config.ts';
55
import { formatter } from './formatter.ts';
66
import { updatePlaygroundLanguageVersion } from './playground.ts';
@@ -54,7 +54,10 @@ async function buildLanguage(
5454
await run('go build -o /dev/null ./...', { cwd, language });
5555
break;
5656
case 'javascript':
57-
await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', { cwd, language });
57+
await run(`${YARN_HARDENED_MODE_PREFIX}YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install`, {
58+
cwd,
59+
language,
60+
});
5861
if (buildType === 'client') {
5962
await run(`yarn build`, { cwd, language });
6063
break;

โ€Žscripts/common.tsโ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const TODAY = new Date().toISOString().split('T')[0];
2626

2727
export const CI = Boolean(process.env.CI);
2828

29+
// command prefix for yarn installs, `run` has no env option so it must be part of the command string (API-476)
30+
export const YARN_HARDENED_MODE_PREFIX = CI ? 'YARN_ENABLE_HARDENED_MODE=1 ' : '';
31+
2932
// This script is run by `yarn workspace ...`, which means the current working directory is `./script`
3033
export const ROOT_DIR = path.resolve(process.cwd(), '..');
3134

โ€Žscripts/cts/generate.tsโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { callGenerator, isWSL, run, setupAndGen } from '../common.ts';
1+
import { YARN_HARDENED_MODE_PREFIX, callGenerator, isWSL, run, setupAndGen } from '../common.ts';
22
import { getTestOutputFolder } from '../config.ts';
33
import { formatter } from '../formatter.ts';
44
import type { Generator } from '../types.ts';
@@ -28,7 +28,7 @@ export async function ctsGenerateMany(
2828
}
2929

3030
if (lang === 'javascript') {
31-
await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', {
31+
await run(`${YARN_HARDENED_MODE_PREFIX}YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install`, {
3232
cwd: 'tests/output/javascript',
3333
});
3434
}

โ€Žscripts/cts/runCts.tsโ€Ž

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fsp from 'fs/promises';
22

3-
import { exists, isVerbose, run, runComposerInstall, toAbsolutePath } from '../common.ts';
3+
import { exists, isVerbose, run, runComposerInstall, toAbsolutePath, YARN_HARDENED_MODE_PREFIX } from '../common.ts';
44
import { getSwiftBuildFolder, getTestOutputFolder } from '../config.ts';
55
import { createSpinner } from '../spinners.ts';
66
import type { Language } from '../types.ts';
@@ -88,10 +88,13 @@ async function runCtsOne(language: Language, suites: Record<CTSType, boolean>):
8888
break;
8989
}
9090
case 'javascript':
91-
await run(`YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn test ${filter((f) => `src/${f}`)}`, {
92-
cwd,
93-
language,
94-
});
91+
await run(
92+
`${YARN_HARDENED_MODE_PREFIX}YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn test ${filter((f) => `src/${f}`)}`,
93+
{
94+
cwd,
95+
language,
96+
},
97+
);
9598
break;
9699
case 'kotlin':
97100
await run(`./gradle/gradlew -p tests/output/kotlin jvmTest ${filter((f) => `--tests 'com.algolia.${f}*'`)}`, {

โ€Žscripts/docs/generate.tsโ€Ž

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { callGenerator, exists, isWSL, run, setupAndGen, toAbsolutePath } from '../common.ts';
1+
import {
2+
YARN_HARDENED_MODE_PREFIX,
3+
callGenerator,
4+
exists,
5+
isWSL,
6+
run,
7+
setupAndGen,
8+
toAbsolutePath,
9+
} from '../common.ts';
210
import { getTestOutputFolder } from '../config.ts';
311
import { formatter } from '../formatter.ts';
412
import type { Generator } from '../types.ts';
@@ -29,7 +37,7 @@ export async function docsGenerateMany(
2937
const docsPath = `docs/${scope}/${lang}`;
3038

3139
if (lang === 'javascript') {
32-
await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', {
40+
await run(`${YARN_HARDENED_MODE_PREFIX}YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install`, {
3341
cwd: docsPath,
3442
});
3543
}

โ€Žscripts/website/build.shโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ touch website/yarn.lock
66
# Generate the file with constants
77
cat config/clients.config.json | jq -r 'del(."$schema") | "export const versions = \(map_values(.packageVersion))"' > website/src/generated/variables.js
88

9-
# install website deps and build
10-
cd website && yarn install && yarn build
9+
# install website deps and build, with yarn supply-chain checks on CI
10+
cd website && env ${CI:+YARN_ENABLE_HARDENED_MODE=1} yarn install && yarn build

0 commit comments

Comments
ย (0)