ci: more fixes

This commit is contained in:
Michael Kriese 2023-12-07 12:23:44 +01:00
parent 7cfcffb23e
commit db93cf6145
No known key found for this signature in database
GPG key ID: B83F553A0724D44E
6 changed files with 190 additions and 5 deletions

View file

@ -58,6 +58,7 @@ jobs:
apt-get -q install -qq \
make \
python3 \
python3-wheel \
python3-venv \
unzip \
;
@ -111,6 +112,7 @@ jobs:
gnupg \
make \
python3 \
python3-wheel \
python3-venv \
unzip \
;
@ -227,16 +229,14 @@ jobs:
- run: helm dependency build
- run: helm package --version "${GITHUB_REF_NAME#v}" -d tmp/ ./
- run: npm ci
- run: npm run changelog "${GITHUB_REF_NAME#v}" tmp/changelog.md
- name: login to codeberg packages
run: echo ${TOKEN} | helm registry login -u viceice --password-stdin codeberg.org/forgejo-contrib
env:
TOKEN: ${{secrets.token}}
- name: publish chart
- name: publish forgejo helm chart
run: helm push tmp/forgejo-${GITHUB_REF_NAME#v}.tgz oci://codeberg.org/forgejo-contrib
- name: forgejo release
run: |
echo TODO: forgejo release
- name: publish forgejo release
run: npm run forgejo:release

19
package-lock.json generated
View file

@ -8,6 +8,7 @@
"license": "MIT",
"devDependencies": {
"@bitnami/readme-generator-for-helm": "^2.4.2",
"clipanion": "^3.2.1",
"conventional-changelog-conventionalcommits": "^7.0.0",
"conventional-changelog-core": "^7.0.0",
"husky": "^8.0.3",
@ -279,6 +280,18 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/clipanion": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/clipanion/-/clipanion-3.2.1.tgz",
"integrity": "sha512-dYFdjLb7y1ajfxQopN05mylEpK9ZX0sO1/RfMXdfmwjlIsPkbh4p7A682x++zFPLDCo1x3p82dtljHf5cW2LKA==",
"dev": true,
"dependencies": {
"typanion": "^3.8.0"
},
"peerDependencies": {
"typanion": "*"
}
},
"node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@ -2116,6 +2129,12 @@
"node": ">=8.0"
}
},
"node_modules/typanion": {
"version": "3.14.0",
"resolved": "https://registry.npmjs.org/typanion/-/typanion-3.14.0.tgz",
"integrity": "sha512-ZW/lVMRabETuYCd9O9ZvMhAh8GslSqaUjxmK/JLPCh6l73CvLBiuXswj/+7LdnWOgYsQ130FqLzFz5aGT4I3Ug==",
"dev": true
},
"node_modules/type-fest": {
"version": "4.8.3",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.8.3.tgz",

View file

@ -10,6 +10,7 @@
},
"scripts": {
"changelog": "node tools/changelog.mjs",
"forgejo:release": "node tools/gitea-release.js",
"prepare": "husky install",
"prettier": "prettier --check --ignore-unknown --cache \"**/*.*\"",
"prettier-fix": "prettier --write --ignore-unknown --cache \"**/*.*\"",
@ -18,6 +19,7 @@
},
"devDependencies": {
"@bitnami/readme-generator-for-helm": "^2.4.2",
"clipanion": "^3.2.1",
"conventional-changelog-conventionalcommits": "^7.0.0",
"conventional-changelog-core": "^7.0.0",
"husky": "^8.0.3",

78
tools/changelog/util.js Normal file
View file

@ -0,0 +1,78 @@
import conventionalChangelogPreset from 'conventional-changelog-conventionalcommits';
import conventionalChangelogCore from 'conventional-changelog-core';
/**
* @type {import('conventional-changelog-core').Options}
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
export const config = conventionalChangelogPreset({
types: [
{
type: 'feat',
section: 'Features',
},
{
type: 'feature',
section: 'Features',
},
{
type: 'fix',
section: 'Bug Fixes',
},
{
type: 'perf',
section: 'Performance Improvements',
},
{
type: 'revert',
section: 'Reverts',
},
{
type: 'docs',
section: 'Documentation',
},
{
type: 'style',
section: 'Styles',
},
{
type: 'chore',
section: 'Miscellaneous Chores',
},
{
type: 'refactor',
section: 'Code Refactoring',
},
{
type: 'test',
section: 'Tests',
},
{
type: 'build',
section: 'Build System',
},
{
type: 'ci',
section: 'Continuous Integration',
},
],
});
/**
*
* @param {string} version
* @param {boolean} onTag
* @returns
*/
export function getChangelog(version, onTag) {
return conventionalChangelogCore(
{
config,
releaseCount: onTag ? 2 : 1,
},
{ version, linkCompare: false },
undefined,
undefined,
{ headerPartial: '' },
);
}

83
tools/forgejo-release.js Normal file
View file

@ -0,0 +1,83 @@
import { Command, runExit } from 'clipanion';
import { getChangelog } from './changelog/util.js';
const api = 'https://https://codeberg.org/api/v1';
const repo = 'forgejo-contrib/forgejo-helm';
class GiteaReleaseCommand extends Command {
async execute() {
const token = process.env.GITHUB_TOKEN;
if (!token) {
this.context.stdout.write('GITHUB_TOKEN environment variable not set.\n');
return 1;
}
this.context.stdout.write(`Getting tag.\n`);
const tag = process.env.GITHUB_REF_NAME;
if (!tag) {
this.context.stdout.write(
'No tag found for this commit. Please tag the commit and try again.\n',
);
return 1;
}
this.context.stdout.write(`Checking remote tag ${tag}.\n`);
let resp = await fetch(`${api}/repos/${repo}/tags/${tag}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!resp.ok) {
this.context.stdout.write(`Tag ${tag} not found on remote.\n`);
return 1;
}
this.context.stdout.write(`Checking remote release ${tag}.\n`);
resp = await fetch(`${api}/repos/${repo}/releases/tags/${tag}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (resp.ok) {
this.context.stdout.write(`Release ${tag} already exists.\n`);
return 1;
} else if (resp.status !== 404) {
this.context.stdout.write(
`Error checking for release ${tag}.\n${resp.status}: ${resp.statusText}\n`,
);
return 1;
}
const stream = getChangelog(tag, true).setEncoding('utf8');
const changes = (await stream.toArray()).join('');
this.context.stdout.write(`Creating release ${tag}.\n`);
resp = await fetch(`${api}/repos/${repo}/releases`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
draft: false,
prerelease: tag.includes('-'),
tag_name: tag,
name: tag.replace(/^v/, ''),
body: changes,
target_commitish: 'main',
}),
});
if (!resp.ok) {
this.context.stdout.write(
`Error creating release ${tag}.\n${resp.status}: ${resp.statusText}\n`,
);
return 1;
}
}
}
void runExit(GiteaReleaseCommand);

3
tools/package.json Normal file
View file

@ -0,0 +1,3 @@
{
"type": "module"
}