@@ -4,20 +4,30 @@ const path = require('node:path');
|
|||||||
function releaseEnvironment(context) {
|
function releaseEnvironment(context) {
|
||||||
const env = context.env ?? process.env;
|
const env = context.env ?? process.env;
|
||||||
const serverUrl = env.GITEA_URL?.replace(/\/$/, '');
|
const serverUrl = env.GITEA_URL?.replace(/\/$/, '');
|
||||||
|
const publicUrl = env.GITEA_PUBLIC_URL?.replace(/\/$/, '');
|
||||||
const repository = env.GITEA_REPOSITORY;
|
const repository = env.GITEA_REPOSITORY;
|
||||||
const token = env.GITEA_TOKEN;
|
const token = env.GITEA_TOKEN;
|
||||||
|
|
||||||
if (!serverUrl || !repository || !token) {
|
if (!serverUrl || !publicUrl || !repository || !token) {
|
||||||
throw new Error('GITEA_URL, GITEA_REPOSITORY, and GITEA_TOKEN are required');
|
throw new Error(
|
||||||
|
'GITEA_URL, GITEA_PUBLIC_URL, GITEA_REPOSITORY, and GITEA_TOKEN are required',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!/^https?:\/\//.test(serverUrl)) {
|
if (!/^https?:\/\//.test(serverUrl)) {
|
||||||
throw new Error('GITEA_URL must be an HTTP(S) URL');
|
throw new Error('GITEA_URL must be an HTTP(S) URL');
|
||||||
}
|
}
|
||||||
|
if (!/^https?:\/\//.test(publicUrl)) {
|
||||||
|
throw new Error('GITEA_PUBLIC_URL must be an HTTP(S) URL');
|
||||||
|
}
|
||||||
if (!/^[^/]+\/[^/]+$/.test(repository)) {
|
if (!/^[^/]+\/[^/]+$/.test(repository)) {
|
||||||
throw new Error('GITEA_REPOSITORY must use the owner/repository format');
|
throw new Error('GITEA_REPOSITORY must use the owner/repository format');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { serverUrl, repository, token };
|
return { serverUrl, publicUrl, repository, token };
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeUrlsPublic(value, serverUrl, publicUrl) {
|
||||||
|
return value?.split(serverUrl).join(publicUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function giteaRequest(url, token, options = {}) {
|
async function giteaRequest(url, token, options = {}) {
|
||||||
@@ -43,10 +53,11 @@ module.exports.verifyConditions = async (_pluginConfig, context) => {
|
|||||||
|
|
||||||
module.exports.prepare = async (pluginConfig, context) => {
|
module.exports.prepare = async (pluginConfig, context) => {
|
||||||
const { nextRelease, cwd } = context;
|
const { nextRelease, cwd } = context;
|
||||||
const notes = nextRelease.notes?.trim();
|
const rawNotes = nextRelease.notes?.trim();
|
||||||
if (!notes) return;
|
if (!rawNotes) return;
|
||||||
|
|
||||||
const { serverUrl, repository } = releaseEnvironment(context);
|
const { serverUrl, publicUrl, repository } = releaseEnvironment(context);
|
||||||
|
const notes = makeUrlsPublic(rawNotes, serverUrl, publicUrl);
|
||||||
const changelogPath = path.resolve(cwd, pluginConfig.changelogFile ?? 'CHANGELOG.md');
|
const changelogPath = path.resolve(cwd, pluginConfig.changelogFile ?? 'CHANGELOG.md');
|
||||||
const releaseJsonPath = path.resolve(cwd, pluginConfig.releaseJsonPath ?? 'patches-bundle.json');
|
const releaseJsonPath = path.resolve(cwd, pluginConfig.releaseJsonPath ?? 'patches-bundle.json');
|
||||||
|
|
||||||
@@ -67,7 +78,7 @@ module.exports.prepare = async (pluginConfig, context) => {
|
|||||||
const releaseData = {
|
const releaseData = {
|
||||||
created_at: new Date().toISOString().replace(/\.\d{3}Z$/, ''),
|
created_at: new Date().toISOString().replace(/\.\d{3}Z$/, ''),
|
||||||
description: notes,
|
description: notes,
|
||||||
download_url: `${serverUrl}/${repository}/releases/download/${nextRelease.gitTag}/${assetName}`,
|
download_url: `${publicUrl}/${repository}/releases/download/${nextRelease.gitTag}/${assetName}`,
|
||||||
signature_download_url: '',
|
signature_download_url: '',
|
||||||
version,
|
version,
|
||||||
};
|
};
|
||||||
@@ -75,7 +86,7 @@ module.exports.prepare = async (pluginConfig, context) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.publish = async (pluginConfig, context) => {
|
module.exports.publish = async (pluginConfig, context) => {
|
||||||
const { serverUrl, repository, token } = releaseEnvironment(context);
|
const { serverUrl, publicUrl, repository, token } = releaseEnvironment(context);
|
||||||
const { branch, cwd, nextRelease } = context;
|
const { branch, cwd, nextRelease } = context;
|
||||||
const repositoryPath = repository.split('/').map(encodeURIComponent).join('/');
|
const repositoryPath = repository.split('/').map(encodeURIComponent).join('/');
|
||||||
const apiUrl = `${serverUrl}/api/v1/repos/${repositoryPath}`;
|
const apiUrl = `${serverUrl}/api/v1/repos/${repositoryPath}`;
|
||||||
@@ -96,7 +107,7 @@ module.exports.publish = async (pluginConfig, context) => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
body: nextRelease.notes,
|
body: makeUrlsPublic(nextRelease.notes, serverUrl, publicUrl),
|
||||||
draft: false,
|
draft: false,
|
||||||
name: nextRelease.name,
|
name: nextRelease.name,
|
||||||
prerelease: false,
|
prerelease: false,
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
GITEA_URL: ${{ gitea.server_url }}
|
GITEA_URL: ${{ gitea.server_url }}
|
||||||
|
GITEA_PUBLIC_URL: https://git.krtss.de
|
||||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||||
run: npx semantic-release
|
run: npx semantic-release
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@
|
|||||||
[
|
[
|
||||||
"@semantic-release/exec",
|
"@semantic-release/exec",
|
||||||
{
|
{
|
||||||
"prepareCmd": "./gradlew generatePatchesList && jq '.version=\"${nextRelease.version}\"' patches-list.json > patches-list.json.tmp && mv patches-list.json.tmp patches-list.json && python3 .gitea/scripts/generate_patches_readme.py \"$GITEA_URL\" \"$GITEA_REPOSITORY\" \"$GITEA_REF_NAME\" patches-list.json README.md"
|
"prepareCmd": "./gradlew generatePatchesList && jq '.version=\"${nextRelease.version}\"' patches-list.json > patches-list.json.tmp && mv patches-list.json.tmp patches-list.json && python3 .gitea/scripts/generate_patches_readme.py \"$GITEA_PUBLIC_URL\" \"$GITEA_REPOSITORY\" \"$GITEA_REF_NAME\" patches-list.json README.md"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user