ci: migrate to Gitea Actions
CI / policy (push) Successful in 48s
CI / validate (push) Successful in 1m25s
CI / test (push) Successful in 3m43s
CI / build (push) Successful in 1m20s
CI / security (push) Successful in 1m31s
CI / benchmark (push) Failing after 5m52s
CI / images (push) Failing after 1m2s
CI / required (push) Failing after 1s
CI / policy (pull_request) Successful in 9s
CI / validate (pull_request) Successful in 1m6s
CI / test (pull_request) Successful in 3m30s
CI / benchmark (pull_request) Canceled after 3s
CI / build (pull_request) Successful in 1m5s
CI / security (pull_request) Successful in 1m27s
CI / images (pull_request) Successful in 2m24s
CI / required (pull_request) Successful in 5s
CI / policy (push) Successful in 48s
CI / validate (push) Successful in 1m25s
CI / test (push) Successful in 3m43s
CI / build (push) Successful in 1m20s
CI / security (push) Successful in 1m31s
CI / benchmark (push) Failing after 5m52s
CI / images (push) Failing after 1m2s
CI / required (push) Failing after 1s
CI / policy (pull_request) Successful in 9s
CI / validate (pull_request) Successful in 1m6s
CI / test (pull_request) Successful in 3m30s
CI / benchmark (pull_request) Canceled after 3s
CI / build (pull_request) Successful in 1m5s
CI / security (pull_request) Successful in 1m27s
CI / images (pull_request) Successful in 2m24s
CI / required (pull_request) Successful in 5s
This commit is contained in:
1 parent
7d60157863
commit
d74dfb9938
14 files changed
+662
-262
No files matched your search
+65
-38
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync, spawnSync } from 'node:child_process';
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
@@ -8,26 +8,48 @@ import { fileURLToPath } from 'node:url';
|
||||
const directory = mkdtempSync(join(tmpdir(), 'ci-policy-'));
|
||||
const script = fileURLToPath(new URL('./ci-policy.mjs', import.meta.url));
|
||||
const git = (...args) => execFileSync('git', args, { cwd: directory, encoding: 'utf8' }).trim();
|
||||
const check = (variables, expected = 0) => {
|
||||
const check = (variables = {}, expected = 0) => {
|
||||
const commit = git('rev-parse', 'HEAD');
|
||||
const branch = variables.branch ?? 'feature/test';
|
||||
const eventName = variables.eventName ?? 'push';
|
||||
const ref = variables.tag
|
||||
? `refs/tags/${variables.tag}`
|
||||
: eventName === 'pull_request'
|
||||
? 'refs/pull/42/head'
|
||||
: `refs/heads/${branch}`;
|
||||
const event = { ref, before: variables.before };
|
||||
if (eventName === 'pull_request') {
|
||||
event.pull_request = {
|
||||
title: variables.title ?? 'feat(test): add policy checks',
|
||||
head: {
|
||||
ref: branch,
|
||||
sha: variables.headSha ?? commit,
|
||||
repo: { full_name: variables.headRepository ?? 'nessar/vac-optimizer' },
|
||||
},
|
||||
base: { ref: variables.target ?? 'develop' },
|
||||
};
|
||||
}
|
||||
const eventPath = join(directory, 'event.json');
|
||||
const outputPath = join(directory, 'outputs');
|
||||
writeFileSync(eventPath, JSON.stringify(event));
|
||||
writeFileSync(outputPath, '');
|
||||
const result = spawnSync(process.execPath, [script], {
|
||||
cwd: directory,
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
CI_PIPELINE_SOURCE: 'push',
|
||||
CI_COMMIT_SHA: git('rev-parse', 'HEAD'),
|
||||
CI_COMMIT_BRANCH: 'feature/test',
|
||||
...variables,
|
||||
GITHUB_EVENT_NAME: eventName,
|
||||
GITHUB_EVENT_PATH: eventPath,
|
||||
GITHUB_REF: ref,
|
||||
GITHUB_SHA: variables.sha ?? commit,
|
||||
GITHUB_REPOSITORY: 'nessar/vac-optimizer',
|
||||
GITHUB_OUTPUT: outputPath,
|
||||
},
|
||||
});
|
||||
assert.equal(result.status, expected, result.stdout + result.stderr);
|
||||
return readFileSync(outputPath, 'utf8');
|
||||
};
|
||||
const mr = {
|
||||
CI_PIPELINE_SOURCE: 'merge_request_event',
|
||||
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'feature/test',
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'develop',
|
||||
CI_MERGE_REQUEST_TITLE: 'feat(test): add policy checks',
|
||||
};
|
||||
const pr = { eventName: 'pull_request' };
|
||||
|
||||
try {
|
||||
git('init', '--initial-branch=main');
|
||||
@@ -41,26 +63,31 @@ try {
|
||||
git('switch', '-c', 'feature/test');
|
||||
git('commit', '--allow-empty', '-m', 'feat(test)!: add checks');
|
||||
check({});
|
||||
check(mr);
|
||||
check({ ...mr, CI_MERGE_REQUEST_TITLE: 'Draft: feat: test policy' });
|
||||
check({ ...mr, CI_MERGE_REQUEST_TITLE: '(Draft) feat: test policy' });
|
||||
check({ ...mr, CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'main' }, 1);
|
||||
check({ ...mr, CI_MERGE_REQUEST_TITLE: 'Add checks' }, 1);
|
||||
check({ CI_COMMIT_TAG: 'v1.5.0' }, 1);
|
||||
check({ CI_COMMIT_SHA: '0'.repeat(40) }, 1);
|
||||
check(pr);
|
||||
check({ ...pr, headRepository: 'contributor/vac-optimizer' });
|
||||
check({ eventName: 'workflow_dispatch' });
|
||||
assert.match(check({ branch: 'Feature/My_calendar' }), /slug=feature-my-calendar\n/);
|
||||
check({ ...pr, headSha: '0'.repeat(40) }, 1);
|
||||
check({ eventName: 'pull_request_target' }, 1);
|
||||
check({ ...pr, title: 'Draft: feat: test policy' });
|
||||
check({ ...pr, title: '(Draft) feat: test policy' });
|
||||
check({ ...pr, target: 'main' }, 1);
|
||||
check({ ...pr, title: 'Add checks' }, 1);
|
||||
check({ tag: 'v1.5.0' }, 1);
|
||||
check({ sha: '0'.repeat(40) }, 1);
|
||||
|
||||
git('switch', 'develop');
|
||||
git('commit', '--allow-empty', '-m', 'fix: another change');
|
||||
git('switch', 'feature/test');
|
||||
check(mr, 1);
|
||||
check(pr, 1);
|
||||
git('rebase', 'develop');
|
||||
check(mr);
|
||||
check(pr);
|
||||
const before = git('rev-parse', 'HEAD');
|
||||
git('commit', '--allow-empty', '-m', 'not conventional');
|
||||
check({ CI_COMMIT_BEFORE_SHA: before }, 1);
|
||||
check(mr, 1);
|
||||
check({ before: before }, 1);
|
||||
check(pr, 1);
|
||||
git('commit', '--amend', '--allow-empty', '-m', 'ci: fix the commit title');
|
||||
check({ CI_COMMIT_BEFORE_SHA: before });
|
||||
check({ before: before });
|
||||
|
||||
git('switch', 'develop');
|
||||
git('merge', '--no-ff', 'feature/test', '-m', 'feat(test): add policy checks');
|
||||
@@ -69,33 +96,33 @@ try {
|
||||
git('add', 'package.json');
|
||||
git('commit', '-m', 'chore(release): prepare 1.6.0');
|
||||
check({
|
||||
...mr,
|
||||
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'release/1.6.0',
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'main',
|
||||
...pr,
|
||||
branch: 'release/1.6.0',
|
||||
target: 'main',
|
||||
});
|
||||
check({ ...mr, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'release/1.6.0' });
|
||||
check({ ...pr, branch: 'release/1.6.0' });
|
||||
git('switch', 'main');
|
||||
git('merge', '--no-ff', 'release/1.6.0', '-m', 'chore(release): publish 1.6.0');
|
||||
check({ CI_COMMIT_TAG: 'v1.6.0' });
|
||||
check({ CI_COMMIT_TAG: 'v1.5.0' }, 1);
|
||||
check({ CI_COMMIT_TAG: 'v01.6.0' }, 1);
|
||||
check({ CI_COMMIT_TAG: 'v1.6.0-rc.1' }, 1);
|
||||
check({ ...mr, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'main' });
|
||||
check({ tag: 'v1.6.0' });
|
||||
check({ tag: 'v1.5.0' }, 1);
|
||||
check({ tag: 'v01.6.0' }, 1);
|
||||
check({ tag: 'v1.6.0-rc.1' }, 1);
|
||||
check({ ...pr, branch: 'main' });
|
||||
|
||||
git('switch', '-c', 'hotfix/1.6.1');
|
||||
git('commit', '--allow-empty', '-m', 'fix: production issue');
|
||||
check({
|
||||
...mr,
|
||||
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'hotfix/1.6.1',
|
||||
CI_MERGE_REQUEST_TARGET_BRANCH_NAME: 'main',
|
||||
...pr,
|
||||
branch: 'hotfix/1.6.1',
|
||||
target: 'main',
|
||||
});
|
||||
check({ ...mr, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: 'hotfix/1.6.1' });
|
||||
check({ ...pr, branch: 'hotfix/1.6.1' });
|
||||
|
||||
// The working branch must not pass by merging develop instead of rebasing.
|
||||
git('switch', 'feature/test');
|
||||
git('commit', '--allow-empty', '-m', 'feat: keep working');
|
||||
git('merge', '--no-ff', 'develop', '-m', 'chore: merge develop');
|
||||
check(mr, 1);
|
||||
check(pr, 1);
|
||||
|
||||
console.log('CI policy integration checks passed.');
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user