mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-12 16:10:30 +02:00
chore: Add 1.x branch compatibility to workflow scripts (#27153)
This commit is contained in:
parent
04bf206acf
commit
6dd462e3ef
8
.github/scripts/determine-version-info.mjs
vendored
8
.github/scripts/determine-version-info.mjs
vendored
|
|
@ -1,6 +1,10 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import { RELEASE_TRACKS, resolveReleaseTagForTrack, writeGithubOutput } from './github-helpers.mjs';
|
||||
import { tagVersionInfoToReleaseCandidateBranchName } from './ensure-release-candidate-branches.mjs';
|
||||
import {
|
||||
RELEASE_TRACKS,
|
||||
resolveReleaseTagForTrack,
|
||||
tagVersionInfoToReleaseCandidateBranchName,
|
||||
writeGithubOutput,
|
||||
} from './github-helpers.mjs';
|
||||
import semver from 'semver';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, it, mock, before } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { tagVersionInfoToReleaseCandidateBranchName } from './github-helpers.mjs';
|
||||
|
||||
/**
|
||||
* 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' };
|
||||
return { version: '1.123.33', tag: 'n8n@1.123.33' };
|
||||
},
|
||||
tagVersionInfoToReleaseCandidateBranchName,
|
||||
writeGithubOutput: () => {}, // no-op in tests
|
||||
getCommitForRef: () => {}, // no-op
|
||||
localRefExists: () => {}, // no-op
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ import semver from 'semver';
|
|||
import {
|
||||
getCommitForRef,
|
||||
localRefExists,
|
||||
RELEASE_CANDIDATE_BRANCH_PREFIX,
|
||||
remoteBranchExists,
|
||||
resolveReleaseTagForTrack,
|
||||
sh,
|
||||
tagVersionInfoToReleaseCandidateBranchName,
|
||||
writeGithubOutput,
|
||||
} from './github-helpers.mjs';
|
||||
|
||||
const RELEASE_CANDIDATE_BRANCH_PREFIX = 'release-candidate/';
|
||||
|
||||
/**
|
||||
* @typedef BranchChanges
|
||||
* @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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, it, mock, before } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { RELEASE_CANDIDATE_BRANCH_PREFIX } from './github-helpers.mjs';
|
||||
|
||||
/**
|
||||
* 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
|
||||
* */
|
||||
|
||||
let tagVersionInfoToReleaseCandidateBranchName;
|
||||
before(async () => {
|
||||
({ tagVersionInfoToReleaseCandidateBranchName } = await import('./github-helpers.mjs'));
|
||||
});
|
||||
|
||||
// mock.module must be called before the module under test is imported,
|
||||
// because static imports are hoisted and resolve before any code runs.
|
||||
mock.module('./github-helpers.mjs', {
|
||||
namedExports: {
|
||||
RELEASE_TRACKS: ['stable', 'beta', 'v1'],
|
||||
RELEASE_PREFIX: 'n8n@',
|
||||
RELEASE_CANDIDATE_BRANCH_PREFIX: RELEASE_CANDIDATE_BRANCH_PREFIX,
|
||||
tagVersionInfoToReleaseCandidateBranchName,
|
||||
resolveReleaseTagForTrack: (track) => {
|
||||
// Always return deterministic data
|
||||
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 () => {
|
||||
({ determineBranchChanges, tagVersionInfoToReleaseCandidateBranchName } = await import(
|
||||
'./ensure-release-candidate-branches.mjs'
|
||||
));
|
||||
({ determineBranchChanges } = await import('./ensure-release-candidate-branches.mjs'));
|
||||
});
|
||||
|
||||
describe('Determine branch changes', () => {
|
||||
|
|
|
|||
25
.github/scripts/github-helpers.mjs
vendored
25
.github/scripts/github-helpers.mjs
vendored
|
|
@ -4,6 +4,9 @@ import fs from 'node:fs';
|
|||
import path from 'node:path';
|
||||
import semver from 'semver';
|
||||
|
||||
export const CURRENT_MAJOR_VERSION = 2;
|
||||
export const RELEASE_CANDIDATE_BRANCH_PREFIX = 'release-candidate/';
|
||||
|
||||
export const RELEASE_TRACKS = /** @type { const } */ ([
|
||||
//
|
||||
'stable',
|
||||
|
|
@ -112,6 +115,25 @@ export function resolveRcBranchForTrack(track) {
|
|||
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
|
||||
*
|
||||
|
|
@ -150,8 +172,9 @@ export function readPrLabels(pullRequest) {
|
|||
/**
|
||||
* Ensures git tag exists.
|
||||
*
|
||||
* @param {string} tag
|
||||
* @throws {Error} if no tag was found
|
||||
* */
|
||||
*/
|
||||
export function ensureTagExists(tag) {
|
||||
sh('git', ['fetch', '--force', '--no-tags', 'origin', `refs/tags/${tag}:refs/tags/${tag}`]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user