Skip to content

Commit 0cb544a

Browse files
committed
fix: handle stale branches and configure git identity for tags
- Reset uncommitted changes before checkout to prevent conflicts - Configure git user identity before creating annotated tags - Fixes version PR creation when branch exists with changes - Fixes 'empty ident name' error when creating tags
1 parent 0fbcb62 commit 0cb544a

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

dist/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130428,6 +130428,11 @@ async function createOrUpdateVersionPR(octokit, context3, options) {
130428130428
core3.debug(`Base branch: ${baseBranch}, Version branch: ${options.branch}`);
130429130429
await ensureBranchExists(octokit, owner, repo, options.branch, baseBranch);
130430130430
git2(`fetch origin ${options.branch}`);
130431+
try {
130432+
git2("reset --hard HEAD");
130433+
} catch {
130434+
core3.debug("No changes to reset");
130435+
}
130431130436
git2(`checkout ${options.branch}`);
130432130437
try {
130433130438
git2(`pull origin ${options.branch} --rebase`);
@@ -131258,6 +131263,8 @@ function isPrerelease(version) {
131258131263
__name(isPrerelease, "isPrerelease");
131259131264
async function createGitTag(tagName, message) {
131260131265
core4.info(`Creating git tag: ${tagName}`);
131266+
await exec("git", ["config", "user.name", "contractual[bot]"]);
131267+
await exec("git", ["config", "user.email", "contractual[bot]@users.noreply.github.com"]);
131261131268
await exec("git", ["tag", "-a", tagName, "-m", message]);
131262131269
await exec("git", ["push", "origin", tagName]);
131263131270
core4.info(`Tag ${tagName} created and pushed`);

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github/pull-requests.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ export async function createOrUpdateVersionPR(
5353
// Ensure branch exists
5454
await ensureBranchExists(octokit, owner, repo, options.branch, baseBranch);
5555

56-
// Checkout the version branch
56+
// Checkout the version branch (force to handle any uncommitted changes)
5757
git(`fetch origin ${options.branch}`);
58+
59+
try {
60+
// Try to reset any uncommitted changes before checkout
61+
git('reset --hard HEAD');
62+
} catch {
63+
core.debug('No changes to reset');
64+
}
65+
5866
git(`checkout ${options.branch}`);
5967

6068
// Pull latest changes to avoid conflicts

src/github/releases.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export function isPrerelease(version: string): boolean {
8080
export async function createGitTag(tagName: string, message: string): Promise<void> {
8181
core.info(`Creating git tag: ${tagName}`);
8282

83+
// Configure git identity for tag creation
84+
await exec.exec('git', ['config', 'user.name', 'contractual[bot]']);
85+
await exec.exec('git', ['config', 'user.email', 'contractual[bot]@users.noreply.github.com']);
86+
8387
// Create annotated tag
8488
await exec.exec('git', ['tag', '-a', tagName, '-m', message]);
8589

0 commit comments

Comments
 (0)