mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-24 23:22:38 +08:00
ci: Call Cloud DB populate workflow from actions (#26808)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { ensureEnvVar, sh, writeGithubOutput } from './github-helpers.mjs';
|
||||
|
||||
function determineReleaseVersionChanges() {
|
||||
const previousVersion = ensureEnvVar('PREVIOUS_VERSION_TAG');
|
||||
const releaseVersion = ensureEnvVar('RELEASE_VERSION_TAG');
|
||||
|
||||
const log = sh('git', [
|
||||
'--no-pager',
|
||||
'log',
|
||||
'--format="%s (%h)"',
|
||||
`${previousVersion}..${releaseVersion}`,
|
||||
]);
|
||||
|
||||
writeGithubOutput({
|
||||
has_node_enhancements: hasNodeEnhancements(log),
|
||||
has_core_changes: hasCoreChanges(log),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches commit messages with
|
||||
*
|
||||
* fix(nodes)
|
||||
* fix(xyz Node)
|
||||
* feat(nodes)
|
||||
* feat(xyz Node)
|
||||
*
|
||||
* @param {string} log
|
||||
*/
|
||||
export function hasNodeEnhancements(log) {
|
||||
return /(fix|feat)\((.*Node|nodes)\)/.test(log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches commit messages with feat(core) or feat(editor)
|
||||
*
|
||||
* @param {string} log
|
||||
*/
|
||||
export function hasCoreChanges(log) {
|
||||
return /feat\((core|editor)\)/.test(log);
|
||||
}
|
||||
|
||||
// only run when executed directly, not when imported by tests
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
determineReleaseVersionChanges();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { describe, it, mock, before } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
/**
|
||||
* Run these tests by running
|
||||
*
|
||||
* node --test --experimental-test-module-mocks ./.github/scripts/determine-release-version-changes.test.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: {
|
||||
ensureEnvVar: () => {}, // no-op
|
||||
sh: () => {}, // no-op
|
||||
writeGithubOutput: () => {}, // no-op
|
||||
},
|
||||
});
|
||||
|
||||
let hasNodeEnhancements, hasCoreChanges;
|
||||
before(async () => {
|
||||
({ hasNodeEnhancements, hasCoreChanges } = await import(
|
||||
'./determine-release-version-changes.mjs'
|
||||
));
|
||||
});
|
||||
|
||||
describe('Determine release version changes', () => {
|
||||
it('Matches nodes feature', () => {
|
||||
assert.ok(hasNodeEnhancements('feat(nodes): Added a utility for node'));
|
||||
});
|
||||
it('Matches nodes fix', () => {
|
||||
assert.ok(hasNodeEnhancements('fix(nodes): Fix said utility'));
|
||||
});
|
||||
it('Matches named node feature', () => {
|
||||
assert.ok(hasNodeEnhancements('feat(Github Actions Node): Add ability to call webhooks'));
|
||||
});
|
||||
it('Matches named node fix', () => {
|
||||
assert.ok(hasNodeEnhancements('fix(OpenAI Node): Allow credentials to pass through'));
|
||||
});
|
||||
|
||||
it('Matches core changes', () => {
|
||||
assert.ok(hasCoreChanges('feat(core): Add cli flag'));
|
||||
});
|
||||
it('Matches editor changes', () => {
|
||||
assert.ok(hasCoreChanges('feat(editor): Add button'));
|
||||
});
|
||||
});
|
||||
@@ -56,7 +56,10 @@ export function determineTrack(packageVersion) {
|
||||
tag: /** @type {import('./github-helpers.mjs').ReleaseVersion} */ (`n8n@${packageVersion}`),
|
||||
});
|
||||
|
||||
const previousVersion = trackToReleaseMap[track]?.version;
|
||||
|
||||
const output = {
|
||||
previous_version: previousVersion,
|
||||
version: packageVersion,
|
||||
track,
|
||||
bump,
|
||||
@@ -67,7 +70,7 @@ export function determineTrack(packageVersion) {
|
||||
|
||||
writeGithubOutput(output);
|
||||
console.log(
|
||||
`Determined track info: track=${track}, version=${packageVersion}, new_stable_version=${newStable}, release_type=${releaseType}, rc_branch=${rc_branch}`,
|
||||
`Determined track info: track=${track}, version=${packageVersion}, previous_version=${previousVersion}, new_stable_version=${newStable}, release_type=${releaseType}, rc_branch=${rc_branch}`,
|
||||
);
|
||||
|
||||
return output;
|
||||
|
||||
@@ -37,6 +37,7 @@ describe('determine-tracks', () => {
|
||||
|
||||
assert.equal(output.track, 'stable');
|
||||
assert.equal(output.version, '2.9.3');
|
||||
assert.equal(output.previous_version, '2.9.2');
|
||||
assert.equal(output.bump, 'patch');
|
||||
assert.equal(output.new_stable_version, null);
|
||||
assert.equal(output.release_type, 'stable');
|
||||
@@ -48,6 +49,7 @@ describe('determine-tracks', () => {
|
||||
|
||||
assert.equal(output.track, 'beta');
|
||||
assert.equal(output.version, '2.10.2');
|
||||
assert.equal(output.previous_version, '2.10.1');
|
||||
assert.equal(output.bump, 'patch');
|
||||
assert.equal(output.new_stable_version, null);
|
||||
assert.equal(output.release_type, 'stable');
|
||||
@@ -60,6 +62,7 @@ describe('determine-tracks', () => {
|
||||
|
||||
assert.equal(output.track, 'stable');
|
||||
assert.equal(output.version, '2.9.4');
|
||||
assert.equal(output.previous_version, '2.9.2');
|
||||
assert.equal(output.bump, 'patch');
|
||||
assert.equal(output.new_stable_version, null);
|
||||
assert.equal(output.release_type, 'stable');
|
||||
@@ -81,6 +84,7 @@ describe('determine-tracks', () => {
|
||||
|
||||
assert.equal(output.track, 'beta');
|
||||
assert.equal(output.version, '2.11.0');
|
||||
assert.equal(output.previous_version, '2.10.1');
|
||||
assert.equal(output.bump, 'minor');
|
||||
assert.equal(output.new_stable_version, '2.10.1');
|
||||
assert.equal(output.release_type, 'stable');
|
||||
@@ -92,6 +96,7 @@ describe('determine-tracks', () => {
|
||||
|
||||
assert.equal(output.track, 'beta');
|
||||
assert.equal(output.version, '2.10.2-rc.1');
|
||||
assert.equal(output.previous_version, '2.10.1');
|
||||
assert.equal(output.bump, 'patch');
|
||||
assert.equal(output.new_stable_version, null);
|
||||
assert.equal(output.release_type, 'rc');
|
||||
|
||||
@@ -205,7 +205,7 @@ export function trySh(cmd, args, opts = {}) {
|
||||
/**
|
||||
* Append outputs to GITHUB_OUTPUT if available.
|
||||
*
|
||||
* @param {Record<string, string>} obj
|
||||
* @param {Record<string, string | boolean>} obj
|
||||
*/
|
||||
export function writeGithubOutput(obj) {
|
||||
const path = process.env.GITHUB_OUTPUT;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ensureEnvVar } from './github-helpers.mjs';
|
||||
|
||||
async function populateCloudDatabases() {
|
||||
const payload = ensureEnvVar('PAYLOAD');
|
||||
const webhookData = ensureEnvVar('N8N_POPULATE_CLOUD_WEBHOOK_DATA');
|
||||
|
||||
const { user, secret, url } = JSON.parse(webhookData);
|
||||
|
||||
console.log('Payload: ', JSON.parse(payload));
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Basic ' + Buffer.from(`${user}:${secret}`).toString('base64'),
|
||||
},
|
||||
body: payload,
|
||||
});
|
||||
|
||||
const status = response.status;
|
||||
console.log('Webhook call returned status ' + status);
|
||||
|
||||
if (status !== 200) {
|
||||
const body = await response.text();
|
||||
throw new Error(`Webhook call failed:\n\n ${body}`);
|
||||
}
|
||||
}
|
||||
|
||||
// only run when executed directly, not when imported by tests
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
populateCloudDatabases();
|
||||
}
|
||||
Reference in New Issue
Block a user