Skip to content

fix(java): delete tag before release #1370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions scripts/ci/codegen/pushGeneratedCode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable no-console */
import { ensureGitHubToken, MAIN_BRANCH, run } from '../../common';
import { configureGitHubAuthor } from '../../release/common';
import {
configureGitHubAuthor,
ensureGitHubToken,
MAIN_BRANCH,
run,
} from '../../common';
import { getNbGitDiff } from '../utils';

import text, { commitStartPrepareRelease } from './text';
Expand Down
13 changes: 6 additions & 7 deletions scripts/ci/codegen/spreadGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import {
toAbsolutePath,
REPO_URL,
ensureGitHubToken,
configureGitHubAuthor,
} from '../../common';
import { getLanguageFolder, getPackageVersionDefault } from '../../config';
import {
cloneRepository,
configureGitHubAuthor,
RELEASED_TAG,
} from '../../release/common';
import { RELEASED_TAG } from '../../release/common';
import type { Language } from '../../types';
import { getNbGitDiff } from '../utils';
import { cloneRepository, getNbGitDiff } from '../utils';

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

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

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

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

// we always want to delete the tag in case it exists
await run(`git tag -d ${version} || true`, { cwd: tempGitDir });
await run(`git tag ${version} HEAD`, { cwd: tempGitDir });
await run('git push --tags', { cwd: tempGitDir });
}
Expand Down
29 changes: 29 additions & 0 deletions scripts/ci/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import fsp from 'fs/promises';
import { resolve } from 'path';

import { run } from '../common';
import { getGitHubUrl } from '../config';
import { getTargetBranch } from '../release/common';
import type { Language } from '../types';

/**
* Returns the number of diff between a `branch` and its `HEAD` for the given `path`.
Expand Down Expand Up @@ -32,3 +38,26 @@ export async function getNbGitDiff({
10
);
}

export async function cloneRepository({
lang,
githubToken,
tempDir,
}: {
lang: Language;
githubToken: string;
tempDir: string;
}): Promise<{ tempGitDir: string }> {
const targetBranch = getTargetBranch(lang);

const gitHubUrl = getGitHubUrl(lang, { token: githubToken });
const tempGitDir = resolve(tempDir, lang);
await fsp.rm(tempGitDir, { force: true, recursive: true });
await run(
`git clone --depth 1 --branch ${targetBranch} ${gitHubUrl} ${tempGitDir}`
);

return {
tempGitDir,
};
}
8 changes: 8 additions & 0 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { remove } from 'fs-extra';
import openapiConfig from '../config/openapitools.json';
import releaseConfig from '../config/release.config.json';

import { getGitAuthor } from './release/common';
import { createSpinner } from './spinners';
import type {
CheckForCache,
Expand Down Expand Up @@ -286,6 +287,13 @@ export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export async function configureGitHubAuthor(cwd?: string): Promise<void> {
const { name, email } = getGitAuthor();

await run(`git config user.name "${name}"`, { cwd });
await run(`git config user.email "${email}"`, { cwd });
}

let verbose = false;
export function setVerbose(v: boolean): void {
verbose = v;
Expand Down
34 changes: 0 additions & 34 deletions scripts/release/common.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import fsp from 'fs/promises';
import path from 'path';

import config from '../../config/release.config.json';
import { run } from '../common';
import { getGitHubUrl } from '../config';
import type { Language } from '../types';

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

export async function configureGitHubAuthor(cwd?: string): Promise<void> {
const { name, email } = getGitAuthor();

await run(`git config user.name "${name}"`, { cwd });
await run(`git config user.email "${email}"`, { cwd });
}

export async function cloneRepository({
lang,
githubToken,
tempDir,
}: {
lang: Language;
githubToken: string;
tempDir: string;
}): Promise<{ tempGitDir: string }> {
const targetBranch = getTargetBranch(lang);

const gitHubUrl = getGitHubUrl(lang, { token: githubToken });
const tempGitDir = path.resolve(tempDir, lang);
await fsp.rm(tempGitDir, { force: true, recursive: true });
await run(
`git clone --depth 1 --branch ${targetBranch} ${gitHubUrl} ${tempGitDir}`
);

return {
tempGitDir,
};
}

/**
* Reads a JSON file and returns its parsed data.
*
Expand Down
6 changes: 5 additions & 1 deletion scripts/release/createReleasePR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {
CI,
gitBranchExists,
setVerbose,
configureGitHubAuthor,
} from '../common';
import { getPackageVersionDefault } from '../config';

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

// cleanup all the changes to the generated files (the ones not commited because of the pre-commit hook)
await run(`git checkout .`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice


await run(`git push origin ${headBranch}`);
await run(`git checkout ${MAIN_BRANCH}`);

Expand Down