Skip to content

Commit b1d5dea

Browse files
committed
inline headRef parameter
1 parent 2344eb8 commit b1d5dea

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

.github/workflows/codegen-cleanup.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,4 @@ jobs:
2222
uses: ./.github/actions/setup
2323

2424
- name: Clean previously generated branch
25-
run: yarn workspace scripts cleanGeneratedBranch
26-
env:
27-
HEAD_REF: ${{ github.head_ref }}
25+
run: yarn workspace scripts cleanGeneratedBranch ${{ github.head_ref }}

scripts/ci/codegen/cleanGeneratedBranch.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
import { run } from '../../common';
33

44
/**
5-
* Deletes a branch for it's `generated/${headRef}` name on origin.
6-
*
7-
* @param headRef - The name of the branch to search for.
5+
* Deletes a branch for its `generated/${headRef}` name on origin.
86
*/
9-
export async function cleanGeneratedBranch(headRef?: string): Promise<void> {
10-
if (!process.env.HEAD_REF && !headRef) {
11-
throw new Error('Unable to run cleanup, HEAD_REF is missing.');
12-
}
13-
14-
const generatedCodeBranch = `generated/${process.env.HEAD_REF || headRef}`;
7+
async function cleanGeneratedBranch(headRef: string): Promise<void> {
8+
const generatedCodeBranch = `generated/${headRef}`;
159

1610
if (!(await run(`git ls-remote --heads origin ${generatedCodeBranch}`))) {
1711
console.log(`No branch named '${generatedCodeBranch}' was found.`);
@@ -26,6 +20,12 @@ export async function cleanGeneratedBranch(headRef?: string): Promise<void> {
2620
await run(`git push -d origin ${generatedCodeBranch}`);
2721
}
2822

29-
if (process.env.HEAD_REF) {
30-
cleanGeneratedBranch();
23+
const args = process.argv.slice(2);
24+
25+
if (!args || args.length === 0) {
26+
throw new Error(
27+
'The base branch should be passed as a cli parameter of the `cleanGeneratedBranch` script.'
28+
);
3129
}
30+
31+
cleanGeneratedBranch(args[0]);

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Octokit } from '@octokit/rest';
44
import { run } from '../../common';
55
import { configureGitHubAuthor, OWNER, REPO } from '../../release/common';
66

7-
import { cleanGeneratedBranch } from './cleanGeneratedBranch';
8-
97
if (!process.env.GITHUB_TOKEN) {
108
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
119
}
@@ -103,7 +101,7 @@ async function pushGeneratedCode(): Promise<void> {
103101
return;
104102
}
105103

106-
await cleanGeneratedBranch(baseBranch);
104+
await run(`yarn workspace scripts cleanGeneratedBranch ${baseBranch}`);
107105

108106
const baseCommit = await run(`git show ${baseBranch} -s --format=%H`);
109107
console.log(

0 commit comments

Comments
 (0)