ci: Workflow to create Patch release for track (#26824)

This commit is contained in:
Matsu
2026-03-10 12:59:03 +00:00
committed by GitHub
parent a99cf3d0e4
commit b27a28de4f
3 changed files with 118 additions and 2 deletions
@@ -0,0 +1,39 @@
import {
countCommitsBetweenRefs,
ensureEnvVar,
listCommitsBetweenRefs,
resolveRcBranchForTrack,
resolveReleaseTagForTrack,
writeGithubOutput,
} from './github-helpers.mjs';
function main() {
const track = /** @type { import('./github-helpers.mjs').ReleaseTrack } */ (
ensureEnvVar('TRACK')
);
const currentTag = resolveReleaseTagForTrack(track);
const releaseCandidateBranch = resolveRcBranchForTrack(track);
if (!currentTag?.tag || !releaseCandidateBranch) {
throw new Error(
`Couldn't resolve needed parameters. currentTag.tag=${currentTag?.tag}, releaseCandidateBranch=${releaseCandidateBranch}`,
);
}
console.log(`Commits between ${releaseCandidateBranch} and ${currentTag.tag}:`);
console.log(listCommitsBetweenRefs(releaseCandidateBranch, currentTag.tag));
const commitCount = countCommitsBetweenRefs(releaseCandidateBranch, currentTag.tag);
writeGithubOutput({
release_candidate_branch: releaseCandidateBranch,
should_update: commitCount > 0 ? 'true' : 'false',
});
}
// only run when executed directly, not when imported by tests
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}
+25 -2
View File
@@ -68,7 +68,7 @@ export function ensureReleaseTrack(track) {
*
* @param { typeof RELEASE_TRACKS[number] } track
*
* @returns { TagVersionInfo }
* @returns { TagVersionInfo | null }
* */
export function resolveReleaseTagForTrack(track) {
const commit = getCommitForRef(track);
@@ -91,9 +91,13 @@ export function resolveReleaseTagForTrack(track) {
*
* Returns null if the track tag or release tag is missing.
*
* @param { typeof RELEASE_TRACKS[number] } track
* @param { ReleaseTrack } track
* */
export function resolveRcBranchForTrack(track) {
if (track === 'v1') {
return '1.x';
}
const commit = getCommitForRef(track);
if (!commit) return null;
@@ -241,6 +245,25 @@ export function listTagsPointingAt(commit) {
.filter(Boolean);
}
/**
* @param {string} from
* @param {string} to
*/
export function listCommitsBetweenRefs(from, to) {
return sh('git', ['--no-pager', 'log', '--format="- %s (%h)', `${to}..origin/${from}`]);
}
/**
* @param {string} from
* @param {string} to
*/
export function countCommitsBetweenRefs(from, to) {
const output = sh('git', ['rev-list', '--count', `${to}..origin/${from}`]);
const count = parseInt(output);
return isNaN(count) ? 0 : count;
}
/**
* @param {string} branch
*/