Skip to content

Commit 1d8bd72

Browse files
authored
fix(scripts): release independently each language (#1374)
1 parent 12f9c4c commit 1d8bd72

File tree

5 files changed

+60
-105
lines changed

5 files changed

+60
-105
lines changed

clients/algoliasearch-client-java-2/.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-java@v3
2424
with:
2525
distribution: zulu
26-
java-version-file: config/.java-version
26+
java-version-file: .java-version
2727
cache: gradle
2828

2929
- name: Validate gradle wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11.0.18

clients/algoliasearch-client-javascript/.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
**dist
2-
**.openapi-generator
2+
**.openapi-generator*
3+
4+
.DS_Store
5+
.env
36

47
yarn-error.log
58

@@ -8,5 +11,3 @@ yarn-error.log
811
!.yarn/plugins
912

1013
node_modules
11-
12-
node_

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
1-
import { LANGUAGES } from '../../../common';
2-
import { decideWhereToSpread, cleanUpCommitMessage } from '../spreadGeneration';
1+
import { cleanUpCommitMessage } from '../spreadGeneration';
32
import text from '../text';
43

54
describe('spread generation', () => {
6-
describe('decideWhereToSpread', () => {
7-
it('spreads to all languages if it is a release commit', () => {
8-
expect(
9-
decideWhereToSpread(`${text.commitReleaseMessage} [skip ci]`)
10-
).toEqual(LANGUAGES);
11-
});
12-
13-
it('spreads to all languages if scope is missing', () => {
14-
expect(decideWhereToSpread('chore: do something')).toEqual(LANGUAGES);
15-
});
16-
17-
it('spreads to javascript if the scope is javascript', () => {
18-
expect(decideWhereToSpread('fix(javascript): fix something')).toEqual([
19-
'javascript',
20-
]);
21-
});
22-
23-
LANGUAGES.forEach((lang) => {
24-
it(`spreads to ${lang} if the scope is ${lang}`, () => {
25-
expect(decideWhereToSpread(`fix(${lang}): fix something`)).toEqual([
26-
lang,
27-
]);
28-
});
29-
});
30-
31-
it('spreads to all if scope is not specific language', () => {
32-
['cts', 'spec', 'script', 'ci'].forEach((scope) => {
33-
expect(decideWhereToSpread(`fix(${scope}): fix something`)).toEqual(
34-
LANGUAGES
35-
);
36-
});
37-
});
38-
});
39-
405
describe('cleanUpCommitMessage', () => {
416
it('returns a release commit message with the version', () => {
427
expect(

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,14 @@ import {
1010
REPO_URL,
1111
ensureGitHubToken,
1212
configureGitHubAuthor,
13+
setVerbose,
1314
} from '../../common';
1415
import { getLanguageFolder, getPackageVersionDefault } from '../../config';
1516
import { RELEASED_TAG } from '../../release/common';
16-
import type { Language } from '../../types';
1717
import { cloneRepository, getNbGitDiff } from '../utils';
1818

1919
import text, { commitStartRelease } from './text';
2020

21-
export function decideWhereToSpread(commitMessage: string): Language[] {
22-
if (commitMessage.startsWith(commitStartRelease)) {
23-
return LANGUAGES;
24-
}
25-
26-
const result = commitMessage.match(/(.+)\((.+)\):/);
27-
if (!result) {
28-
// no scope
29-
return LANGUAGES;
30-
}
31-
32-
const scope = result[2] as Language;
33-
return LANGUAGES.includes(scope) ? [scope] : LANGUAGES;
34-
}
35-
3621
export function cleanUpCommitMessage(
3722
commitMessage: string,
3823
version: string
@@ -84,10 +69,9 @@ async function spreadGeneration(): Promise<void> {
8469
.filter(Boolean);
8570

8671
const IS_RELEASE_COMMIT = lastCommitMessage.startsWith(commitStartRelease);
87-
const langs = decideWhereToSpread(lastCommitMessage);
8872
console.log(
8973
'Spreading code to the following repositories:',
90-
langs.join(' | ')
74+
LANGUAGES.join(' | ')
9175
);
9276

9377
// At this point, we know the release will happen on at least one client
@@ -99,70 +83,74 @@ async function spreadGeneration(): Promise<void> {
9983
await run(
10084
`git fetch origin refs/tags/${RELEASED_TAG}:refs/tags/${RELEASED_TAG}`
10185
);
102-
await run(`git tag -d ${RELEASED_TAG}`);
10386
await run(`git push --delete origin ${RELEASED_TAG}`);
10487

10588
console.log('Creating new `released` tag for latest commit');
10689
await run(`git tag ${RELEASED_TAG}`);
10790
await run('git push --tags');
10891
}
10992

110-
for (const lang of langs) {
111-
const { tempGitDir } = await cloneRepository({
112-
lang,
113-
githubToken,
114-
tempDir: process.env.RUNNER_TEMP!,
115-
});
116-
117-
const clientPath = toAbsolutePath(getLanguageFolder(lang));
118-
await emptyDirExceptForDotGit(tempGitDir);
119-
await copy(clientPath, tempGitDir, { preserveTimestamps: true });
120-
121-
if (
122-
(await getNbGitDiff({
123-
head: null,
93+
for (const lang of LANGUAGES) {
94+
try {
95+
const { tempGitDir } = await cloneRepository({
96+
lang,
97+
githubToken,
98+
tempDir: process.env.RUNNER_TEMP!,
99+
});
100+
101+
const clientPath = toAbsolutePath(getLanguageFolder(lang));
102+
await emptyDirExceptForDotGit(tempGitDir);
103+
await copy(clientPath, tempGitDir, { preserveTimestamps: true });
104+
105+
if (
106+
(await getNbGitDiff({
107+
head: null,
108+
cwd: tempGitDir,
109+
})) === 0
110+
) {
111+
console.log(
112+
`❎ Skipping ${lang} repository, because there is no change.`
113+
);
114+
continue;
115+
} else {
116+
console.log(`✅ Spreading code to the ${lang} repository.`);
117+
}
118+
119+
const version = getPackageVersionDefault(lang);
120+
const commitMessage = cleanUpCommitMessage(lastCommitMessage, version);
121+
122+
await configureGitHubAuthor(tempGitDir);
123+
124+
await run('git add .', { cwd: tempGitDir });
125+
await gitCommit({
126+
message: commitMessage,
127+
coAuthors: [author, ...coAuthors],
124128
cwd: tempGitDir,
125-
})) === 0
126-
) {
127-
console.log(
128-
`❎ Skipping ${lang} repository, because there is no change.`
129-
);
130-
continue;
131-
} else {
132-
console.log(`✅ Spreading code to the ${lang} repository.`);
133-
}
134-
135-
const version = getPackageVersionDefault(lang);
136-
const commitMessage = cleanUpCommitMessage(lastCommitMessage, version);
129+
});
130+
await run('git push', { cwd: tempGitDir });
137131

138-
await configureGitHubAuthor(tempGitDir);
132+
// In case of a release commit, we also want to update tags on the clients repositories
133+
if (IS_RELEASE_COMMIT) {
134+
console.log(
135+
`Processing release commit, creating new release tag ('${version}') for '${lang}' repository.`
136+
);
139137

140-
await run('git add .', { cwd: tempGitDir });
141-
await gitCommit({
142-
message: commitMessage,
143-
coAuthors: [author, ...coAuthors],
144-
cwd: tempGitDir,
145-
});
146-
await run('git push', { cwd: tempGitDir });
138+
// we always want to delete the tag in case it exists
139+
await run(`git tag -d ${version} || true`, { cwd: tempGitDir });
140+
await run(`git tag ${version} HEAD`, { cwd: tempGitDir });
141+
await run('git push --tags', { cwd: tempGitDir });
142+
}
147143

148-
// In case of a release commit, we also want to update tags on the clients repositories
149-
if (IS_RELEASE_COMMIT) {
150144
console.log(
151-
`Processing release commit, creating new release tag ('${version}') for '${lang}' repository.`
145+
`✅ Code generation successfully pushed to ${lang} repository.`
152146
);
153-
154-
// we always want to delete the tag in case it exists
155-
await run(`git tag -d ${version} || true`, { cwd: tempGitDir });
156-
await run(`git tag ${version} HEAD`, { cwd: tempGitDir });
157-
await run('git push --tags', { cwd: tempGitDir });
147+
} catch (e) {
148+
console.error(`Release failed for language ${lang}: ${e}`);
158149
}
159-
160-
console.log(
161-
`✅ Code generation successfully pushed to ${lang} repository.`
162-
);
163150
}
164151
}
165152

166153
if (require.main === module) {
154+
setVerbose(false);
167155
spreadGeneration();
168156
}

0 commit comments

Comments
 (0)