n8n/.github/scripts/promote-github-release.mjs
Matsu ea12d022be
Some checks failed
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (22.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (24.13.1) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Unit tests (25.x) (push) Has been cancelled
CI: Master (Build, Test, Lint) / Lint (push) Has been cancelled
CI: Master (Build, Test, Lint) / Performance (push) Has been cancelled
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Has been cancelled
ci: Bring .github/scripts up to date in 1.x (#27965)
2026-04-02 18:30:57 +02:00

69 lines
1.8 KiB
JavaScript

import {
deleteRelease,
ensureEnvVar,
getExistingRelease,
initGithub,
writeGithubOutput,
} from './github-helpers.mjs';
/**
* Promotes a GitHub release to latest
*
* Required env variables:
* - RELEASE_TAG - Release tag on git e.g. n8n@2.13.0
*
* GitHub variables
* - GITHUB_TOKEN - Used to authenticate to octokit - Can be overwritten for privileged access
* - GITHUB_REPOSITORY - Used to determine target repository
* */
async function promoteGitHubRelease() {
const RELEASE_TAG = ensureEnvVar('RELEASE_TAG');
const { octokit, owner, repo } = initGithub();
const existingRelease = await getExistingRelease(RELEASE_TAG);
if (!existingRelease) {
console.warn("Couldn't find release by tag. Exiting...");
process.exit(1);
}
const releaseResponse = await octokit.rest.repos.updateRelease({
owner,
repo,
release_id: existingRelease.id,
prerelease: false,
make_latest: 'true',
});
console.log(`Successfully updated release ${releaseResponse.data.html_url}`);
const existingStableRelease = await getExistingRelease('stable');
if (existingStableRelease) {
await deleteRelease(existingStableRelease.id);
console.log("Deleted previous 'stable' release.");
}
const stableReleaseResponse = await octokit.rest.repos.createRelease({
tag_name: 'stable',
name: 'stable',
body: releaseResponse.data.body,
draft: false,
prerelease: false,
make_latest: 'false',
target_commitish: releaseResponse.data.target_commitish,
owner,
repo,
});
console.log(`Successfully created new stable release ${stableReleaseResponse.data.html_url}`);
writeGithubOutput({
release_url: releaseResponse.data.html_url,
stable_release_url: stableReleaseResponse.data.html_url,
});
}
// only run when executed directly, not when imported by tests
if (import.meta.url === `file://${process.argv[1]}`) {
promoteGitHubRelease();
}