Skip to content

Commit d457b77

Browse files
authored
fix(java): delete tag before release (#1370)
1 parent 629e147 commit d457b77

File tree

6 files changed

+54
-44
lines changed

6 files changed

+54
-44
lines changed

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-disable no-console */
2-
import { ensureGitHubToken, MAIN_BRANCH, run } from '../../common';
3-
import { configureGitHubAuthor } from '../../release/common';
2+
import {
3+
configureGitHubAuthor,
4+
ensureGitHubToken,
5+
MAIN_BRANCH,
6+
run,
7+
} from '../../common';
48
import { getNbGitDiff } from '../utils';
59

610
import text, { commitStartPrepareRelease } from './text';

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ import {
99
toAbsolutePath,
1010
REPO_URL,
1111
ensureGitHubToken,
12+
configureGitHubAuthor,
1213
} from '../../common';
1314
import { getLanguageFolder, getPackageVersionDefault } from '../../config';
14-
import {
15-
cloneRepository,
16-
configureGitHubAuthor,
17-
RELEASED_TAG,
18-
} from '../../release/common';
15+
import { RELEASED_TAG } from '../../release/common';
1916
import type { Language } from '../../types';
20-
import { getNbGitDiff } from '../utils';
17+
import { cloneRepository, getNbGitDiff } from '../utils';
2118

2219
import text, { commitStartRelease } from './text';
2320

@@ -106,7 +103,7 @@ async function spreadGeneration(): Promise<void> {
106103
await run(`git push --delete origin ${RELEASED_TAG}`);
107104

108105
console.log('Creating new `released` tag for latest commit');
109-
await run('git tag released');
106+
await run(`git tag ${RELEASED_TAG}`);
110107
await run('git push --tags');
111108
}
112109

@@ -154,6 +151,8 @@ async function spreadGeneration(): Promise<void> {
154151
`Processing release commit, creating new release tag ('${version}') for '${lang}' repository.`
155152
);
156153

154+
// we always want to delete the tag in case it exists
155+
await run(`git tag -d ${version} || true`, { cwd: tempGitDir });
157156
await run(`git tag ${version} HEAD`, { cwd: tempGitDir });
158157
await run('git push --tags', { cwd: tempGitDir });
159158
}

scripts/ci/utils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import fsp from 'fs/promises';
2+
import { resolve } from 'path';
3+
14
import { run } from '../common';
5+
import { getGitHubUrl } from '../config';
6+
import { getTargetBranch } from '../release/common';
7+
import type { Language } from '../types';
28

39
/**
410
* Returns the number of diff between a `branch` and its `HEAD` for the given `path`.
@@ -32,3 +38,26 @@ export async function getNbGitDiff({
3238
10
3339
);
3440
}
41+
42+
export async function cloneRepository({
43+
lang,
44+
githubToken,
45+
tempDir,
46+
}: {
47+
lang: Language;
48+
githubToken: string;
49+
tempDir: string;
50+
}): Promise<{ tempGitDir: string }> {
51+
const targetBranch = getTargetBranch(lang);
52+
53+
const gitHubUrl = getGitHubUrl(lang, { token: githubToken });
54+
const tempGitDir = resolve(tempDir, lang);
55+
await fsp.rm(tempGitDir, { force: true, recursive: true });
56+
await run(
57+
`git clone --depth 1 --branch ${targetBranch} ${gitHubUrl} ${tempGitDir}`
58+
);
59+
60+
return {
61+
tempGitDir,
62+
};
63+
}

scripts/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { remove } from 'fs-extra';
99
import openapiConfig from '../config/openapitools.json';
1010
import releaseConfig from '../config/release.config.json';
1111

12+
import { getGitAuthor } from './release/common';
1213
import { createSpinner } from './spinners';
1314
import type {
1415
CheckForCache,
@@ -286,6 +287,13 @@ export function capitalize(str: string): string {
286287
return str.charAt(0).toUpperCase() + str.slice(1);
287288
}
288289

290+
export async function configureGitHubAuthor(cwd?: string): Promise<void> {
291+
const { name, email } = getGitAuthor();
292+
293+
await run(`git config user.name "${name}"`, { cwd });
294+
await run(`git config user.email "${email}"`, { cwd });
295+
}
296+
289297
let verbose = false;
290298
export function setVerbose(v: boolean): void {
291299
verbose = v;

scripts/release/common.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import fsp from 'fs/promises';
2-
import path from 'path';
32

43
import config from '../../config/release.config.json';
5-
import { run } from '../common';
6-
import { getGitHubUrl } from '../config';
7-
import type { Language } from '../types';
84

95
export const RELEASED_TAG = config.releasedTag;
106
export const TEAM_SLUG = config.teamSlug;
@@ -17,36 +13,6 @@ export function getGitAuthor(): { name: string; email: string } {
1713
return config.gitAuthor;
1814
}
1915

20-
export async function configureGitHubAuthor(cwd?: string): Promise<void> {
21-
const { name, email } = getGitAuthor();
22-
23-
await run(`git config user.name "${name}"`, { cwd });
24-
await run(`git config user.email "${email}"`, { cwd });
25-
}
26-
27-
export async function cloneRepository({
28-
lang,
29-
githubToken,
30-
tempDir,
31-
}: {
32-
lang: Language;
33-
githubToken: string;
34-
tempDir: string;
35-
}): Promise<{ tempGitDir: string }> {
36-
const targetBranch = getTargetBranch(lang);
37-
38-
const gitHubUrl = getGitHubUrl(lang, { token: githubToken });
39-
const tempGitDir = path.resolve(tempDir, lang);
40-
await fsp.rm(tempGitDir, { force: true, recursive: true });
41-
await run(
42-
`git clone --depth 1 --branch ${targetBranch} ${gitHubUrl} ${tempGitDir}`
43-
);
44-
45-
return {
46-
tempGitDir,
47-
};
48-
}
49-
5016
/**
5117
* Reads a JSON file and returns its parsed data.
5218
*

scripts/release/createReleasePR.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import {
1818
CI,
1919
gitBranchExists,
2020
setVerbose,
21+
configureGitHubAuthor,
2122
} from '../common';
2223
import { getPackageVersionDefault } from '../config';
2324

24-
import { configureGitHubAuthor, RELEASED_TAG } from './common';
25+
import { RELEASED_TAG } from './common';
2526
import TEXT from './text';
2627
import type {
2728
Versions,
@@ -459,6 +460,9 @@ async function createReleasePR(): Promise<void> {
459460
await run(`CI=false git commit -m "${commitMessage}"`);
460461
}
461462

463+
// cleanup all the changes to the generated files (the ones not commited because of the pre-commit hook)
464+
await run(`git checkout .`);
465+
462466
await run(`git push origin ${headBranch}`);
463467
await run(`git checkout ${MAIN_BRANCH}`);
464468

0 commit comments

Comments
 (0)