Skip to content

Commit 8df0b72

Browse files
authored
chore(scripts): improve release script with git diff [skip-bc] (#3686)
1 parent 223e8b8 commit 8df0b72

17 files changed

+444
-1239
lines changed

.env.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# See ./website/docs/releaseProcess.md for more information.
1+
# See ./website/docs/release-process.md for more information.
22

3-
GITHUB_TOKEN=
3+
GITHUB_TOKEN=

config/release.config.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"mainBranch": "main",
44
"owner": "algolia",
55
"repo": "api-clients-automation",
6-
"teamSlug": "api-clients-automation",
76
"targetBranch": {
87
"csharp": "main",
98
"dart": "main",

scripts/.eslintrc.cjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
ignorePatterns: ['*.test.ts', '**.yml', 'tsconfig.json'],
2+
ignorePatterns: ['**.yml', 'tsconfig.json'],
33

44
extends: "../.eslintrc.cjs",
55

@@ -35,6 +35,7 @@ module.exports = {
3535
complexity: 0,
3636
'no-param-reassign': 0,
3737
'@typescript-eslint/consistent-type-assertions': 0,
38+
'@typescript-eslint/consistent-type-imports': 0,
3839
curly: ['error', 'all'],
3940
},
4041
};

scripts/__tests__/common.test.ts

+16-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { afterEach, describe, expect, it, vi } from "vitest";
1+
import { execa } from 'execa';
2+
import { afterEach, describe, expect, it, vi } from 'vitest';
23

4+
import { capitalize, createClientName, gitCommit } from '../common.js';
35
import { getClientsConfigField } from '../config.js';
46

57
vi.mock('execa', () => {
@@ -9,11 +11,6 @@ vi.mock('execa', () => {
911
};
1012
});
1113

12-
const { capitalize, createClientName, gitCommit } = await import(
13-
'../common.js'
14-
);
15-
const { execa } = await import('execa');
16-
1714
describe('gitCommit', () => {
1815
afterEach(() => {
1916
vi.clearAllMocks();
@@ -22,10 +19,7 @@ describe('gitCommit', () => {
2219
it('commits with message', () => {
2320
gitCommit({ message: 'chore: does something' });
2421
expect(execa).toHaveBeenCalledTimes(1);
25-
expect(execa).toHaveBeenCalledWith(
26-
'git', ["commit", "-m", "chore: does something"],
27-
{ cwd: expect.any(String) }
28-
);
22+
expect(execa).toHaveBeenCalledWith('git', ['commit', '-m', 'chore: does something'], { cwd: expect.any(String) });
2923
});
3024

3125
it('commits with co-author', () => {
@@ -50,8 +44,13 @@ describe('gitCommit', () => {
5044
});
5145
expect(execa).toHaveBeenCalledTimes(1);
5246
expect(execa).toHaveBeenCalledWith(
53-
'git', ["commit", "-m", "chore: does something\n\n\nCo-authored-by: them <[email protected]>\nCo-authored-by: me <[email protected]>\nCo-authored-by: you <[email protected]>"],
54-
{ cwd: expect.any(String) }
47+
'git',
48+
[
49+
'commit',
50+
'-m',
51+
'chore: does something\n\n\nCo-authored-by: them <[email protected]>\nCo-authored-by: me <[email protected]>\nCo-authored-by: you <[email protected]>',
52+
],
53+
{ cwd: expect.any(String) },
5554
);
5655
});
5756
});
@@ -61,15 +60,11 @@ describe('config', () => {
6160
it('throws if the field is not found', () => {
6261
expect(() => {
6362
getClientsConfigField('javascript', 'foofoo');
64-
}).toThrowErrorMatchingInlineSnapshot(
65-
`[Error: Unable to find 'foofoo' for 'javascript']`
66-
);
63+
}).toThrowErrorMatchingInlineSnapshot(`[Error: Unable to find 'foofoo' for 'javascript']`);
6764
});
6865

6966
it('find the field if it exists', () => {
70-
expect(getClientsConfigField('java', ['tests', 'extension'])).toEqual(
71-
'.test.java'
72-
);
67+
expect(getClientsConfigField('java', ['tests', 'extension'])).toEqual('.test.java');
7368
});
7469
});
7570
});
@@ -95,20 +90,14 @@ describe('utils', () => {
9590
describe('createClientName', () => {
9691
it('does not capitalize every part for JavaScript', () => {
9792
expect(createClientName('search', 'javascript')).toEqual('search');
98-
expect(createClientName('search-client', 'javascript')).toEqual(
99-
'searchClient'
100-
);
101-
expect(createClientName('search-cli!nt-complex', 'javascript')).toEqual(
102-
'searchCli!ntComplex'
103-
);
93+
expect(createClientName('search-client', 'javascript')).toEqual('searchClient');
94+
expect(createClientName('search-cli!nt-complex', 'javascript')).toEqual('searchCli!ntComplex');
10495
});
10596

10697
it('capitalize every part for other languages', () => {
10798
expect(createClientName('search', 'java')).toEqual('Search');
10899
expect(createClientName('search-client', 'java')).toEqual('SearchClient');
109-
expect(createClientName('search-cli!nt-complex', 'java')).toEqual(
110-
'SearchCli!ntComplex'
111-
);
100+
expect(createClientName('search-cli!nt-complex', 'java')).toEqual('SearchCli!ntComplex');
112101
});
113102
});
114103
});
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { describe, expect, it, vi } from "vitest";
1+
import { describe, expect, it, vi } from 'vitest';
2+
23
import { pushGeneratedCode } from '../pushGeneratedCode.js';
34

4-
vi.mock('../../../common.js', async () => {
5-
const mod = await vi.importActual<typeof import('../../../common.js')>('../../../common.js')
5+
vi.mock('../../../common.js', async (importOriginal) => {
6+
const mod = await importOriginal<typeof import('../../../common.js')>();
67
return {
78
...mod,
89
run: vi.fn().mockResolvedValue(''),
9-
}
10+
};
1011
});
1112

1213
describe('pushGeneratedCode', () => {
1314
it('throws without GITHUB_TOKEN environment variable', async () => {
1415
process.env.GITHUB_TOKEN = '';
15-
await expect(pushGeneratedCode()).rejects.toThrow(
16-
'Environment variable `GITHUB_TOKEN` does not exist.'
17-
);
16+
await expect(pushGeneratedCode()).rejects.toThrow('Environment variable `GITHUB_TOKEN` does not exist.');
1817
});
1918
});

scripts/ci/codegen/__tests__/spreadGeneration.test.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import { describe, expect, it } from "vitest";
1+
import { describe, expect, it } from 'vitest';
2+
23
import { cleanUpCommitMessage } from '../spreadGeneration.js';
34
import text from '../text.js';
45

56
describe('spread generation', () => {
67
describe('cleanUpCommitMessage', () => {
78
it('returns a release commit message with the version', () => {
8-
expect(
9-
cleanUpCommitMessage(`${text.commitReleaseMessage} [skip ci]`, '1.0.0')
10-
).toEqual('chore: release 1.0.0');
9+
expect(cleanUpCommitMessage(`${text.commitReleaseMessage} [skip ci]`, '1.0.0')).toEqual('chore: release 1.0.0');
1110
});
1211

1312
it('removes pull-request number from commit message', () => {
14-
expect(
15-
cleanUpCommitMessage('feat(ci): make ci push generated code (#244)', '')
16-
).toEqual(
17-
`feat(ci): make ci push generated code (generated)\n\nhttps://github.com/algolia/api-clients-automation/pull/244`
13+
expect(cleanUpCommitMessage('feat(ci): make ci push generated code (#244)', '')).toEqual(
14+
'feat(ci): make ci push generated code (generated)\n\nhttps://github.com/algolia/api-clients-automation/pull/244',
1815
);
1916
});
2017

2118
it('keeps the commit message even if it does not have PR number', () => {
22-
const commitMessage = `feat(ci): make ci push generated code`;
19+
const commitMessage = 'feat(ci): make ci push generated code';
2320
expect(cleanUpCommitMessage(commitMessage, '')).toEqual(commitMessage);
2421
});
2522

2623
it('cleans up correctly even if the title contains a url', () => {
27-
const commitMessage = `fix(java): solve oneOf using a custom generator https://algolia.atlassian.net/browse/APIC-123 (#200)`;
24+
const commitMessage =
25+
'fix(java): solve oneOf using a custom generator https://algolia.atlassian.net/browse/APIC-123 (#200)';
2826
expect(cleanUpCommitMessage(commitMessage, '')).toMatchInlineSnapshot(`
2927
"fix(java): solve oneOf using a custom generator https://algolia.atlassian.net/browse/APIC-123 (generated)
3028
@@ -33,10 +31,8 @@ describe('spread generation', () => {
3331
});
3432

3533
it('generated commits have a link to the origin pull request', () => {
36-
expect(
37-
cleanUpCommitMessage('feat(ci): make ci push generated code (#244) (generated)', '')
38-
).toEqual(
39-
`feat(ci): make ci push generated code (generated)\n\nhttps://github.com/algolia/api-clients-automation/pull/244`
34+
expect(cleanUpCommitMessage('feat(ci): make ci push generated code (#244) (generated)', '')).toEqual(
35+
'feat(ci): make ci push generated code (generated)\n\nhttps://github.com/algolia/api-clients-automation/pull/244',
4036
);
4137
});
4238
});

scripts/cli/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ program
242242
program
243243
.command('release')
244244
.description('Releases the client')
245-
.addArgument(args.languages)
246245
.option(flags.verbose.flag, flags.verbose.description)
247246
.option<semver.ReleaseType>(
248247
'-rt --releaseType <type>',
@@ -258,7 +257,7 @@ program
258257
.option('-d, --dry-run', 'does not push anything to GitHub')
259258
.option('-sla, --sla-only', 'only generates the sla policy', false)
260259
.option('-b --breaking', 'allow breaking change on the CI', false)
261-
.action(async (langArgs: LangArg[], { verbose, releaseType, dryRun, slaOnly, breaking }) => {
260+
.action(async ({ verbose, releaseType, dryRun, slaOnly, breaking }) => {
262261
setVerbose(Boolean(verbose));
263262

264263
if (slaOnly) {
@@ -267,12 +266,7 @@ program
267266
return;
268267
}
269268

270-
if (langArgs.length === 0) {
271-
langArgs = [ALL];
272-
}
273-
274269
await createReleasePR({
275-
languages: langArgs.includes(ALL) ? LANGUAGES : (langArgs as Language[]),
276270
releaseType,
277271
dryRun,
278272
breaking,

scripts/common.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export const TODAY = new Date().toISOString().split('T')[0];
2828
export const CI = Boolean(process.env.CI);
2929

3030
// This script is run by `yarn workspace ...`, which means the current working directory is `./script`
31-
const ROOT_DIR = path.resolve(process.cwd(), '..');
32-
33-
export const ROOT_ENV_PATH = path.resolve(ROOT_DIR, '.env');
31+
export const ROOT_DIR = path.resolve(process.cwd(), '..');
3432

3533
// Build `GENERATORS` from the `clients.config.json` file
3634
export const GENERATORS = Object.entries(clientsConfig).reduce(

0 commit comments

Comments
 (0)