chore: Add 1.x branch compatibility to workflow scripts (#27153)

This commit is contained in:
Matsu 2026-03-17 15:06:26 +02:00 committed by GitHub
parent 04bf206acf
commit 6dd462e3ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 25 deletions

View File

@ -1,6 +1,10 @@
import { readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import { RELEASE_TRACKS, resolveReleaseTagForTrack, writeGithubOutput } from './github-helpers.mjs'; import {
import { tagVersionInfoToReleaseCandidateBranchName } from './ensure-release-candidate-branches.mjs'; RELEASE_TRACKS,
resolveReleaseTagForTrack,
tagVersionInfoToReleaseCandidateBranchName,
writeGithubOutput,
} from './github-helpers.mjs';
import semver from 'semver'; import semver from 'semver';
/** /**

View File

@ -1,5 +1,6 @@
import { describe, it, mock, before } from 'node:test'; import { describe, it, mock, before } from 'node:test';
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import { tagVersionInfoToReleaseCandidateBranchName } from './github-helpers.mjs';
/** /**
* Run these tests by running * Run these tests by running
@ -18,6 +19,7 @@ mock.module('./github-helpers.mjs', {
if (track === 'beta') return { version: '2.10.1', tag: 'n8n@2.10.1' }; if (track === 'beta') return { version: '2.10.1', tag: 'n8n@2.10.1' };
return { version: '1.123.33', tag: 'n8n@1.123.33' }; return { version: '1.123.33', tag: 'n8n@1.123.33' };
}, },
tagVersionInfoToReleaseCandidateBranchName,
writeGithubOutput: () => {}, // no-op in tests writeGithubOutput: () => {}, // no-op in tests
getCommitForRef: () => {}, // no-op getCommitForRef: () => {}, // no-op
localRefExists: () => {}, // no-op localRefExists: () => {}, // no-op

View File

@ -2,14 +2,14 @@ import semver from 'semver';
import { import {
getCommitForRef, getCommitForRef,
localRefExists, localRefExists,
RELEASE_CANDIDATE_BRANCH_PREFIX,
remoteBranchExists, remoteBranchExists,
resolveReleaseTagForTrack, resolveReleaseTagForTrack,
sh, sh,
tagVersionInfoToReleaseCandidateBranchName,
writeGithubOutput, writeGithubOutput,
} from './github-helpers.mjs'; } from './github-helpers.mjs';
const RELEASE_CANDIDATE_BRANCH_PREFIX = 'release-candidate/';
/** /**
* @typedef BranchChanges * @typedef BranchChanges
* @property { import('./github-helpers.mjs').TagVersionInfo[] } branchesToEnsure TagVersionInfo for branches the system needs to make sure exist * @property { import('./github-helpers.mjs').TagVersionInfo[] } branchesToEnsure TagVersionInfo for branches the system needs to make sure exist
@ -51,20 +51,6 @@ export function determineBranchChanges() {
}; };
} }
/**
* Takes a TagVersionInfo object and returns a rc-branch name.
*
* e.g. release-candidate/2.8.x
*
* @param {import('./github-helpers.mjs').TagVersionInfo} tagVersionInfo
*
* @returns { `${RELEASE_CANDIDATE_BRANCH_PREFIX}${number}.${number}.x` }
* */
export function tagVersionInfoToReleaseCandidateBranchName(tagVersionInfo) {
const version = tagVersionInfo.version;
return `${RELEASE_CANDIDATE_BRANCH_PREFIX}${semver.major(version)}.${semver.minor(version)}.x`;
}
/** /**
* @param {import("./github-helpers.mjs").TagVersionInfo} tagInfo * @param {import("./github-helpers.mjs").TagVersionInfo} tagInfo
*/ */

View File

@ -1,5 +1,6 @@
import { describe, it, mock, before } from 'node:test'; import { describe, it, mock, before } from 'node:test';
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import { RELEASE_CANDIDATE_BRANCH_PREFIX } from './github-helpers.mjs';
/** /**
* Run these tests by running * Run these tests by running
@ -7,12 +8,19 @@ import assert from 'node:assert/strict';
* node --test --experimental-test-module-mocks ./.github/scripts/ensure-release-candidate-branches.test.mjs * node --test --experimental-test-module-mocks ./.github/scripts/ensure-release-candidate-branches.test.mjs
* */ * */
let tagVersionInfoToReleaseCandidateBranchName;
before(async () => {
({ tagVersionInfoToReleaseCandidateBranchName } = await import('./github-helpers.mjs'));
});
// mock.module must be called before the module under test is imported, // mock.module must be called before the module under test is imported,
// because static imports are hoisted and resolve before any code runs. // because static imports are hoisted and resolve before any code runs.
mock.module('./github-helpers.mjs', { mock.module('./github-helpers.mjs', {
namedExports: { namedExports: {
RELEASE_TRACKS: ['stable', 'beta', 'v1'], RELEASE_TRACKS: ['stable', 'beta', 'v1'],
RELEASE_PREFIX: 'n8n@', RELEASE_PREFIX: 'n8n@',
RELEASE_CANDIDATE_BRANCH_PREFIX: RELEASE_CANDIDATE_BRANCH_PREFIX,
tagVersionInfoToReleaseCandidateBranchName,
resolveReleaseTagForTrack: (track) => { resolveReleaseTagForTrack: (track) => {
// Always return deterministic data // Always return deterministic data
if (track === 'stable') return { version: '2.9.2', tag: 'n8n@2.9.2' }; if (track === 'stable') return { version: '2.9.2', tag: 'n8n@2.9.2' };
@ -27,11 +35,9 @@ mock.module('./github-helpers.mjs', {
}, },
}); });
let determineBranchChanges, tagVersionInfoToReleaseCandidateBranchName; let determineBranchChanges;
before(async () => { before(async () => {
({ determineBranchChanges, tagVersionInfoToReleaseCandidateBranchName } = await import( ({ determineBranchChanges } = await import('./ensure-release-candidate-branches.mjs'));
'./ensure-release-candidate-branches.mjs'
));
}); });
describe('Determine branch changes', () => { describe('Determine branch changes', () => {

View File

@ -4,6 +4,9 @@ import fs from 'node:fs';
import path from 'node:path'; import path from 'node:path';
import semver from 'semver'; import semver from 'semver';
export const CURRENT_MAJOR_VERSION = 2;
export const RELEASE_CANDIDATE_BRANCH_PREFIX = 'release-candidate/';
export const RELEASE_TRACKS = /** @type { const } */ ([ export const RELEASE_TRACKS = /** @type { const } */ ([
// //
'stable', 'stable',
@ -24,7 +27,7 @@ export const RELEASE_TRACKS = /** @type { const } */ ([
* */ * */
/** /**
* @typedef {{ tag: ReleaseVersion, version: SemVer}} TagVersionInfo * @typedef {{ tag: ReleaseVersion, version: SemVer }} TagVersionInfo
* */ * */
export const RELEASE_PREFIX = 'n8n@'; export const RELEASE_PREFIX = 'n8n@';
@ -112,6 +115,25 @@ export function resolveRcBranchForTrack(track) {
return `release-candidate/${parsed.major}.${parsed.minor}.x`; return `release-candidate/${parsed.major}.${parsed.minor}.x`;
} }
/**
* Takes a TagVersionInfo object and returns a rc-branch name.
*
* e.g. release-candidate/2.8.x or 1.x
*
* @param {import('./github-helpers.mjs').TagVersionInfo} tagVersionInfo
*
* @returns { `${RELEASE_CANDIDATE_BRANCH_PREFIX}${number}.${number}.x` | `${number}.x` }
* */
export function tagVersionInfoToReleaseCandidateBranchName(tagVersionInfo) {
const version = tagVersionInfo.version;
const majorVersion = semver.major(version);
if (majorVersion < CURRENT_MAJOR_VERSION) {
return `${majorVersion}.x`;
}
return `${RELEASE_CANDIDATE_BRANCH_PREFIX}${majorVersion}.${semver.minor(version)}.x`;
}
/** /**
* @param {string} tag * @param {string} tag
* *
@ -150,8 +172,9 @@ export function readPrLabels(pullRequest) {
/** /**
* Ensures git tag exists. * Ensures git tag exists.
* *
* @throws { Error } if no tag was found * @param {string} tag
* */ * @throws {Error} if no tag was found
*/
export function ensureTagExists(tag) { export function ensureTagExists(tag) {
sh('git', ['fetch', '--force', '--no-tags', 'origin', `refs/tags/${tag}:refs/tags/${tag}`]); sh('git', ['fetch', '--force', '--no-tags', 'origin', `refs/tags/${tag}:refs/tags/${tag}`]);
} }