From d7222758361bb31e8919b12f43049ca339a8c066 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 18 Jun 2024 15:56:57 +0200 Subject: [PATCH] fix: Also cleanup dry-run tags --- dist/create-release-branch-main.js | 16 ++++++++++------ src/create-release-branch.ts | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/dist/create-release-branch-main.js b/dist/create-release-branch-main.js index 36e8d0d..e84d2ab 100644 --- a/dist/create-release-branch-main.js +++ b/dist/create-release-branch-main.js @@ -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 }); diff --git a/src/create-release-branch.ts b/src/create-release-branch.ts index 3c80467..5876fcc 100644 --- a/src/create-release-branch.ts +++ b/src/create-release-branch.ts @@ -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 }); + }); } }