Skip to content

Commit 2461fcd

Browse files
committed
[ci] Force-update release branch on tagged main commits
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 609e7ed commit 2461fcd

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

‎.github/workflows/pull-requests-release.yaml‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,41 @@ jobs:
8989
}
9090
const line = `${match[1]}.${match[2]}`;
9191
const branch = `release-${line}`;
92+
93+
// Get main branch commit for the tag
94+
const ref = await github.rest.git.getRef({
95+
owner: context.repo.owner,
96+
repo: context.repo.repo,
97+
ref: `tags/${tag}`
98+
});
99+
const commitSha = ref.data.object.sha;
100+
92101
try {
102+
// Check if branch exists
93103
await github.rest.repos.getBranch({
94104
owner: context.repo.owner,
95105
repo: context.repo.repo,
96106
branch
97107
});
98-
console.log(`Branch '${branch}' already exists`);
99-
} catch (_) {
108+
109+
// Force update existing branch to the tag commit
110+
await github.rest.git.updateRef({
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
ref: `heads/${branch}`,
114+
sha: commitSha,
115+
force: true
116+
});
117+
console.log(`🔁 Force-updated '${branch}' to ${commitSha}`);
118+
} catch (err) {
119+
// Branch doesn't exist, create it
100120
await github.rest.git.createRef({
101121
owner: context.repo.owner,
102122
repo: context.repo.repo,
103123
ref: `refs/heads/${branch}`,
104-
sha: context.sha
124+
sha: commitSha
105125
});
106-
console.log(`✅ Branch '${branch}' created at ${context.sha}`);
126+
console.log(`✅ Created branch '${branch}' at ${commitSha}`);
107127
}
108128
109129
# Get the latest published release

0 commit comments

Comments
 (0)