From 376682e54751a000c6111ab267e4e3a1fbd0e8dd Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 18 Jun 2024 15:36:50 +0200 Subject: [PATCH 1/3] fix: Fetch all tags in `create-release-branch` --- dist/create-release-branch-main.js | 1 + src/create-release-branch.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/create-release-branch-main.js b/dist/create-release-branch-main.js index 4361dea..04d120a 100644 --- a/dist/create-release-branch-main.js +++ b/dist/create-release-branch-main.js @@ -24861,6 +24861,7 @@ async function main(input) { const repo = input.repo.split("/")[1]; const remote = `https://${input.githubToken}@github.com/${input.repo}.git`; cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch }); + command_sh("git fetch --tags"); const version = input.version ?? command_sh("git describe", { cwd: repo }).trimEnd(); lib_core.setOutput("version", version); let branch; diff --git a/src/create-release-branch.ts b/src/create-release-branch.ts index 3c80467..59d3ecb 100644 --- a/src/create-release-branch.ts +++ b/src/create-release-branch.ts @@ -40,6 +40,7 @@ export async function main(input: Input) { const remote = `https://${input.githubToken}@github.com/${input.repo}.git`; git.cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch }); + sh("git fetch --tags"); const version = input.version ?? sh("git describe", { cwd: repo }).trimEnd(); core.setOutput("version", version); From cd220a9cf04fba9ff0c97fd459f49d55e04f002b Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 18 Jun 2024 15:46:34 +0200 Subject: [PATCH 2/3] fix: Don't use `--single-branch` by defualt in `git.cloneFromGitHub` --- dist/build-crates-standalone-main.js | 3 ++- dist/create-release-branch-main.js | 4 ++-- dist/publish-crates-eclipse-main.js | 3 ++- dist/publish-crates-github-main.js | 3 ++- dist/publish-crates-homebrew-main.js | 3 ++- src/create-release-branch.ts | 1 - src/git.ts | 3 ++- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dist/build-crates-standalone-main.js b/dist/build-crates-standalone-main.js index c3b836f..db738f4 100644 --- a/dist/build-crates-standalone-main.js +++ b/dist/build-crates-standalone-main.js @@ -127657,8 +127657,9 @@ const gitEnv = { 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"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); diff --git a/dist/create-release-branch-main.js b/dist/create-release-branch-main.js index 04d120a..36e8d0d 100644 --- a/dist/create-release-branch-main.js +++ b/dist/create-release-branch-main.js @@ -24820,8 +24820,9 @@ function exec(program, args, options) { 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"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); @@ -24861,7 +24862,6 @@ async function main(input) { const repo = input.repo.split("/")[1]; const remote = `https://${input.githubToken}@github.com/${input.repo}.git`; cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch }); - command_sh("git fetch --tags"); const version = input.version ?? command_sh("git describe", { cwd: repo }).trimEnd(); lib_core.setOutput("version", version); let branch; diff --git a/dist/publish-crates-eclipse-main.js b/dist/publish-crates-eclipse-main.js index e6ac9de..93018c9 100644 --- a/dist/publish-crates-eclipse-main.js +++ b/dist/publish-crates-eclipse-main.js @@ -127751,8 +127751,9 @@ const gitEnv = { 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"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); diff --git a/dist/publish-crates-github-main.js b/dist/publish-crates-github-main.js index 6395a4c..9f77262 100644 --- a/dist/publish-crates-github-main.js +++ b/dist/publish-crates-github-main.js @@ -127730,8 +127730,9 @@ const gitEnv = { 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"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); diff --git a/dist/publish-crates-homebrew-main.js b/dist/publish-crates-homebrew-main.js index 711dc5c..f79d66c 100644 --- a/dist/publish-crates-homebrew-main.js +++ b/dist/publish-crates-homebrew-main.js @@ -127654,8 +127654,9 @@ const gitEnv = { 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"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); diff --git a/src/create-release-branch.ts b/src/create-release-branch.ts index 59d3ecb..3c80467 100644 --- a/src/create-release-branch.ts +++ b/src/create-release-branch.ts @@ -40,7 +40,6 @@ export async function main(input: Input) { const remote = `https://${input.githubToken}@github.com/${input.repo}.git`; git.cloneFromGitHub(input.repo, { token: input.githubToken, branch: input.branch }); - sh("git fetch --tags"); const version = input.version ?? sh("git describe", { cwd: repo }).trimEnd(); core.setOutput("version", version); diff --git a/src/git.ts b/src/git.ts index ef11992..42b937b 100644 --- a/src/git.ts +++ b/src/git.ts @@ -10,8 +10,9 @@ export function cloneFromGitHub(repo: string, options: CloneFromGitHubOptions) { const remote = options.token == undefined ? `https://github.com/${repo}.git` : `https://${options.token}@github.com/${repo}.git`; - const command = ["git", "clone", "--recursive", "--single-branch"]; + const command = ["git", "clone", "--recursive"]; if (options.branch != undefined) { + command.push("--single-branch"); command.push("--branch", options.branch); } command.push(remote); From d7222758361bb31e8919b12f43049ca339a8c066 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 18 Jun 2024 15:56:57 +0200 Subject: [PATCH 3/3] 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 }); + }); } }