Skip to content

Commit fd4cdc0

Browse files
authored
feat: Add branch input to create-release-branch action (#156)
* feat: Add `branch` input to `create-release-branch` action * feat: Add `branch` input to branch-bump-tag-crates workflow
1 parent 9990818 commit fd4cdc0

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

.github/workflows/branch-bump-tag-crates.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
version:
1616
type: string
1717
required: false
18+
branch:
19+
type: string
20+
required: false
1821
bump-deps-pattern:
1922
type: string
2023
required: true
@@ -43,6 +46,9 @@ on:
4346
version:
4447
type: string
4548
required: false
49+
branch:
50+
type: string
51+
required: false
4652
bump-deps-pattern:
4753
type: string
4854
required: true
@@ -66,6 +72,7 @@ jobs:
6672
repo: ${{ inputs.repo }}
6773
live-run: ${{ inputs.live-run }}
6874
version: ${{ inputs.version }}
75+
branch: ${{ inputs.branch }}
6976
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}
7077

7178
- uses: eclipse-zenoh/ci/bump-crates@main

create-release-branch/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ inputs:
55
required: false
66
live-run:
77
required: true
8+
dry-run-history-size:
9+
required: false
810
repo:
911
required: true
12+
branch:
13+
required: false
1014
github-token:
1115
required: true
12-
dry-run-history-size:
13-
required: false
16+
1417

1518
outputs:
1619
version:

dist/create-release-branch-main.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24711,7 +24711,7 @@ module.exports = {
2471124711
"use strict";
2471224712
__nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
2471324713
__nccwpck_require__.r(__webpack_exports__);
24714-
/* harmony import */ var _create_release_branch__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(1712);
24714+
/* harmony import */ var _create_release_branch__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(6210);
2471524715

2471624716
await (0,_create_release_branch__WEBPACK_IMPORTED_MODULE_0__/* .main */ .DH)((0,_create_release_branch__WEBPACK_IMPORTED_MODULE_0__/* .setup */ .cY)());
2471724717

@@ -24720,7 +24720,7 @@ __webpack_async_result__();
2472024720

2472124721
/***/ }),
2472224722

24723-
/***/ 1712:
24723+
/***/ 6210:
2472424724
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
2472524725

2472624726
"use strict";
@@ -24743,7 +24743,7 @@ const external_child_process_namespaceObject = require("child_process");
2474324743

2474424744

2474524745
const MAX_BUFFER = 10 * 1024 * 1024;
24746-
function sh(cmd, options) {
24746+
function command_sh(cmd, options) {
2474724747
options = options != null ? options : {};
2474824748
options.env = options.env != null ? options.env : {};
2474924749
options.cwd = options.cwd != null ? options.cwd : ".";
@@ -24816,21 +24816,42 @@ function exec(program, args, options) {
2481624816
return returns.stdout;
2481724817
}
2481824818

24819+
;// CONCATENATED MODULE: ./src/git.ts
24820+
24821+
function cloneFromGitHub(repo, options) {
24822+
const remote = options.token == undefined ? `https://github.com/${repo}.git` : `https://${options.token}@github.com/${repo}.git`;
24823+
const command = ["git", "clone", "--recursive", "--single-branch"];
24824+
if (options.branch != undefined) {
24825+
command.push("--branch", options.branch);
24826+
}
24827+
command.push(remote);
24828+
if (options.path != undefined) {
24829+
command.push(options.path);
24830+
}
24831+
command_sh(command.join(" "));
24832+
}
24833+
function describe(path = process.cwd()) {
24834+
return sh("git describe", { cwd: path }).trim();
24835+
}
24836+
2481924837
;// CONCATENATED MODULE: ./src/create-release-branch.ts
2482024838

2482124839

2482224840

24841+
2482324842
const DEFAULT_DRY_RUN_HISTORY_SIZE = 5;
2482424843
function setup() {
2482524844
const version = lib_core.getInput("version");
2482624845
const liveRun = lib_core.getBooleanInput("live-run", { required: true });
24846+
const dryRunHistorySize = lib_core.getInput("dry-run-history-size", { required: false });
2482724847
const repo = lib_core.getInput("repo", { required: true });
24848+
const branch = lib_core.getInput("branch", { required: false });
2482824849
const githubToken = lib_core.getInput("github-token", { required: true });
24829-
const dryRunHistorySize = lib_core.getInput("dry-run-history-size");
2483024850
return {
2483124851
version: version === "" ? undefined : version,
2483224852
liveRun,
2483324853
repo,
24854+
branch,
2483424855
githubToken,
2483524856
dryRunHistorySize: dryRunHistorySize == "" ? DEFAULT_DRY_RUN_HISTORY_SIZE : Number(dryRunHistorySize),
2483624857
};
@@ -24839,8 +24860,8 @@ async function main(input) {
2483924860
try {
2484024861
const repo = input.repo.split("/")[1];
2484124862
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
24842-
sh(`git clone --recursive ${remote}`);
24843-
const version = input.version ?? sh("git describe", { cwd: repo }).trimEnd();
24863+
cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch });
24864+
const version = input.version ?? command_sh("git describe", { cwd: repo }).trimEnd();
2484424865
lib_core.setOutput("version", version);
2484524866
let branch;
2484624867
if (input.liveRun) {
@@ -24853,17 +24874,17 @@ async function main(input) {
2485324874
const refsPattern = "refs/remotes/origin/release/dry-run";
2485424875
// for some reason using the full refname won't work to delete the remote branch, so
2485524876
// refname:strip=3 removes 'refs/remotes/origin' from the pattern to have the branch name only.
24856-
const refsRaw = sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${refsPattern}`, {
24877+
const refsRaw = command_sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${refsPattern}`, {
2485724878
cwd: repo,
2485824879
});
2485924880
const refs = refsRaw.split("\n");
2486024881
if (refs.length >= input.dryRunHistorySize) {
2486124882
const toDelete = refs.slice(0, refs.length - input.dryRunHistorySize);
24862-
toDelete.forEach(ref => sh(`git push origin --delete ${ref}`, { cwd: repo }));
24883+
toDelete.forEach(ref => command_sh(`git push origin --delete ${ref}`, { cwd: repo }));
2486324884
}
2486424885
}
24865-
sh(`git switch --force-create ${branch}`, { cwd: repo });
24866-
sh(`git push --force ${remote} ${branch}`, { cwd: repo });
24886+
command_sh(`git switch --force-create ${branch}`, { cwd: repo });
24887+
command_sh(`git push --force ${remote} ${branch}`, { cwd: repo });
2486724888
await cleanup(input);
2486824889
}
2486924890
catch (error) {

src/create-release-branch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { rm } from "fs/promises";
33
import * as core from "@actions/core";
44

55
import { sh } from "./command";
6+
import * as git from "./git";
67

78
const DEFAULT_DRY_RUN_HISTORY_SIZE = 5;
89

@@ -11,20 +12,23 @@ export type Input = {
1112
liveRun: boolean;
1213
dryRunHistorySize?: number;
1314
repo: string;
15+
branch?: string;
1416
githubToken: string;
1517
};
1618

1719
export function setup(): Input {
1820
const version = core.getInput("version");
1921
const liveRun = core.getBooleanInput("live-run", { required: true });
22+
const dryRunHistorySize = core.getInput("dry-run-history-size", { required: false });
2023
const repo = core.getInput("repo", { required: true });
24+
const branch = core.getInput("branch", { required: false });
2125
const githubToken = core.getInput("github-token", { required: true });
22-
const dryRunHistorySize = core.getInput("dry-run-history-size");
2326

2427
return {
2528
version: version === "" ? undefined : version,
2629
liveRun,
2730
repo,
31+
branch,
2832
githubToken,
2933
dryRunHistorySize: dryRunHistorySize == "" ? DEFAULT_DRY_RUN_HISTORY_SIZE : Number(dryRunHistorySize),
3034
};
@@ -35,7 +39,7 @@ export async function main(input: Input) {
3539
const repo = input.repo.split("/")[1];
3640
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
3741

38-
sh(`git clone --recursive ${remote}`);
42+
git.cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch });
3943

4044
const version = input.version ?? sh("git describe", { cwd: repo }).trimEnd();
4145
core.setOutput("version", version);

0 commit comments

Comments
 (0)