Rework releases CI

This commit is contained in:
Alex Gleason
2023-01-08 16:34:50 -06:00
parent 039433988f
commit ced6f544d7
6 changed files with 273 additions and 37 deletions

31
scripts/do-release.ts Normal file
View File

@ -0,0 +1,31 @@
import { Gitlab } from '@gitbeaker/node';
import { getChanges } from './lib/changelog';
const {
CI_COMMIT_TAG,
CI_JOB_TOKEN,
CI_PROJECT_ID,
} = process.env;
const api = new Gitlab({
host: 'https://gitlab.com',
jobToken: CI_JOB_TOKEN,
});
async function main() {
await api.Releases.create(CI_PROJECT_ID!, {
name: CI_COMMIT_TAG,
tag_name: CI_COMMIT_TAG,
description: '## Changelog\n\n' + getChanges(CI_COMMIT_TAG!),
assets: {
links: [{
name: 'Build',
url: `https://gitlab.com/soapbox-pub/soapbox/-/jobs/artifacts/${CI_COMMIT_TAG}/download?job=build-production`,
link_type: 'package',
}],
},
});
}
main();

View File

@ -1,8 +1,7 @@
import fs from 'fs';
import { join } from 'path';
const version = process.argv[2].replace('v', '');
/** Parse the changelog into an object. */
function parseChangelog(changelog: string): Record<string, string> {
const result: Record<string, string> = {};
@ -19,12 +18,15 @@ function parseChangelog(changelog: string): Record<string, string> {
return result;
}
const changelog = fs.readFileSync(join(__dirname, '..', 'CHANGELOG.md'), 'utf8');
const parsed = parseChangelog(changelog);
// Log to stdout so we can redirect it in CI.
// eslint-disable-next-line no-console
console.log((parsed[version] || '').trim());
/** Get Markdown changes for a specific version. */
function getChanges(version: string) {
version = version.replace('v', '');
const content = fs.readFileSync(join(__dirname, '..', '..', 'CHANGELOG.md'), 'utf8');
const parsed = parseChangelog(content);
return (parsed[version] || '').trim();
}
export {
parseChangelog,
getChanges,
};