Skip to content
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

feat: Add branch input to create-release-branch action #156

Merged
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
7 changes: 7 additions & 0 deletions .github/workflows/branch-bump-tag-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
version:
type: string
required: false
branch:
type: string
required: false
bump-deps-pattern:
type: string
required: true
Expand Down Expand Up @@ -43,6 +46,9 @@ on:
version:
type: string
required: false
branch:
type: string
required: false
bump-deps-pattern:
type: string
required: true
Expand All @@ -66,6 +72,7 @@ jobs:
repo: ${{ inputs.repo }}
live-run: ${{ inputs.live-run }}
version: ${{ inputs.version }}
branch: ${{ inputs.branch }}
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}

- uses: eclipse-zenoh/ci/bump-crates@main
Expand Down
7 changes: 5 additions & 2 deletions create-release-branch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ inputs:
required: false
live-run:
required: true
dry-run-history-size:
required: false
repo:
required: true
branch:
required: false
github-token:
required: true
dry-run-history-size:
required: false


outputs:
version:
Expand Down
41 changes: 31 additions & 10 deletions dist/create-release-branch-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24711,7 +24711,7 @@ module.exports = {
"use strict";
__nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__nccwpck_require__.r(__webpack_exports__);
/* harmony import */ var _create_release_branch__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(1712);
/* harmony import */ var _create_release_branch__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(6210);

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

Expand All @@ -24720,7 +24720,7 @@ __webpack_async_result__();

/***/ }),

/***/ 1712:
/***/ 6210:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

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


const MAX_BUFFER = 10 * 1024 * 1024;
function sh(cmd, options) {
function command_sh(cmd, options) {
options = options != null ? options : {};
options.env = options.env != null ? options.env : {};
options.cwd = options.cwd != null ? options.cwd : ".";
Expand Down Expand Up @@ -24816,21 +24816,42 @@ function exec(program, args, options) {
return returns.stdout;
}

;// CONCATENATED MODULE: ./src/git.ts

function cloneFromGitHub(repo, options) {
const remote = options.token == undefined ? `https://github.com/${repo}.git` : `https://${options.token}@github.com/${repo}.git`;
const command = ["git", "clone", "--recursive", "--single-branch"];
if (options.branch != undefined) {
command.push("--branch", options.branch);
}
command.push(remote);
if (options.path != undefined) {
command.push(options.path);
}
command_sh(command.join(" "));
}
function describe(path = process.cwd()) {
return sh("git describe", { cwd: path }).trim();
}

;// CONCATENATED MODULE: ./src/create-release-branch.ts




const DEFAULT_DRY_RUN_HISTORY_SIZE = 5;
function setup() {
const version = lib_core.getInput("version");
const liveRun = lib_core.getBooleanInput("live-run", { required: true });
const dryRunHistorySize = lib_core.getInput("dry-run-history-size", { required: false });
const repo = lib_core.getInput("repo", { required: true });
const branch = lib_core.getInput("branch", { required: false });
const githubToken = lib_core.getInput("github-token", { required: true });
const dryRunHistorySize = lib_core.getInput("dry-run-history-size");
return {
version: version === "" ? undefined : version,
liveRun,
repo,
branch,
githubToken,
dryRunHistorySize: dryRunHistorySize == "" ? DEFAULT_DRY_RUN_HISTORY_SIZE : Number(dryRunHistorySize),
};
Expand All @@ -24839,8 +24860,8 @@ async function main(input) {
try {
const repo = input.repo.split("/")[1];
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
sh(`git clone --recursive ${remote}`);
const version = input.version ?? sh("git describe", { cwd: repo }).trimEnd();
cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch });
const version = input.version ?? command_sh("git describe", { cwd: repo }).trimEnd();
lib_core.setOutput("version", version);
let branch;
if (input.liveRun) {
Expand All @@ -24853,17 +24874,17 @@ async function main(input) {
const refsPattern = "refs/remotes/origin/release/dry-run";
// for some reason using the full refname won't work to delete the remote branch, so
// refname:strip=3 removes 'refs/remotes/origin' from the pattern to have the branch name only.
const refsRaw = sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${refsPattern}`, {
const refsRaw = command_sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${refsPattern}`, {
cwd: repo,
});
const refs = refsRaw.split("\n");
if (refs.length >= input.dryRunHistorySize) {
const toDelete = refs.slice(0, refs.length - input.dryRunHistorySize);
toDelete.forEach(ref => sh(`git push origin --delete ${ref}`, { cwd: repo }));
toDelete.forEach(ref => command_sh(`git push origin --delete ${ref}`, { cwd: repo }));
}
}
sh(`git switch --force-create ${branch}`, { cwd: repo });
sh(`git push --force ${remote} ${branch}`, { cwd: repo });
command_sh(`git switch --force-create ${branch}`, { cwd: repo });
command_sh(`git push --force ${remote} ${branch}`, { cwd: repo });
await cleanup(input);
}
catch (error) {
Expand Down
8 changes: 6 additions & 2 deletions src/create-release-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { rm } from "fs/promises";
import * as core from "@actions/core";

import { sh } from "./command";
import * as git from "./git";

const DEFAULT_DRY_RUN_HISTORY_SIZE = 5;

Expand All @@ -11,20 +12,23 @@ export type Input = {
liveRun: boolean;
dryRunHistorySize?: number;
repo: string;
branch?: string;
githubToken: string;
};

export function setup(): Input {
const version = core.getInput("version");
const liveRun = core.getBooleanInput("live-run", { required: true });
const dryRunHistorySize = core.getInput("dry-run-history-size", { required: false });
const repo = core.getInput("repo", { required: true });
const branch = core.getInput("branch", { required: false });
const githubToken = core.getInput("github-token", { required: true });
const dryRunHistorySize = core.getInput("dry-run-history-size");

return {
version: version === "" ? undefined : version,
liveRun,
repo,
branch,
githubToken,
dryRunHistorySize: dryRunHistorySize == "" ? DEFAULT_DRY_RUN_HISTORY_SIZE : Number(dryRunHistorySize),
};
Expand All @@ -35,7 +39,7 @@ export async function main(input: Input) {
const repo = input.repo.split("/")[1];
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;

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

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