Skip to content

Commit

Permalink
fix: Also cleanup dry-run tags
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Jun 18, 2024
1 parent cd220a9 commit d722275
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 10 additions & 6 deletions dist/create-release-branch-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24872,16 +24872,20 @@ async function main(input) {
else {
branch = `release/dry-run/${version}`;
lib_core.setOutput("branch", branch);
const refsPattern = "refs/remotes/origin/release/dry-run";
const branchPattern = "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 = command_sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${refsPattern}`, {
const branchesRaw = command_sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${branchPattern}`, {
cwd: repo,
});
const refs = refsRaw.split("\n");
if (refs.length >= input.dryRunHistorySize) {
const toDelete = refs.slice(0, refs.length - input.dryRunHistorySize);
toDelete.forEach(ref => command_sh(`git push origin --delete ${ref}`, { cwd: repo }));
const branches = branchesRaw.split("\n");
if (branches.length >= input.dryRunHistorySize) {
const toDelete = branches.slice(0, branches.length - input.dryRunHistorySize);
toDelete.forEach(branch => {
const tag = branch.replace("release/dry-run/", "");
command_sh(`git push origin --delete ${branch}`, { cwd: repo });
command_sh(`git push origin --delete ${tag}`, { cwd: repo });
});
}
}
command_sh(`git switch --force-create ${branch}`, { cwd: repo });
Expand Down
16 changes: 10 additions & 6 deletions src/create-release-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ export async function main(input: Input) {
branch = `release/dry-run/${version}`;
core.setOutput("branch", branch);

const refsPattern = "refs/remotes/origin/release/dry-run";
const branchPattern = "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 branchesRaw = sh(`git for-each-ref --format='%(refname:strip=3)' --sort=authordate ${branchPattern}`, {
cwd: repo,
});
const refs = refsRaw.split("\n");
const branches = branchesRaw.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 }));
if (branches.length >= input.dryRunHistorySize) {
const toDelete = branches.slice(0, branches.length - input.dryRunHistorySize);
toDelete.forEach(branch => {
const tag = branch.replace("release/dry-run/", "");
sh(`git push origin --delete ${branch}`, { cwd: repo });
sh(`git push origin --delete ${tag}`, { cwd: repo });
});
}
}

Expand Down

0 comments on commit d722275

Please sign in to comment.