This commit is contained in:
+44
-21
@@ -111,19 +111,24 @@ async function giteaRequest(url, options, { allowNotFound = false } = {}) {
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
const payload = text ? (() => {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return { raw: text };
|
||||
}
|
||||
})() : null;
|
||||
const payload = text
|
||||
? (() => {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return { raw: text };
|
||||
}
|
||||
})()
|
||||
: null;
|
||||
|
||||
if (!response.ok) {
|
||||
const detail = payload && typeof payload === 'object' && payload.error
|
||||
? payload.error
|
||||
: payload?.raw ?? text ?? '';
|
||||
throw new Error(`Gitea API request failed (${response.status} ${response.statusText}): ${detail}`);
|
||||
const detail =
|
||||
payload && typeof payload === 'object' && payload.error
|
||||
? payload.error
|
||||
: (payload?.raw ?? text ?? '');
|
||||
throw new Error(
|
||||
`Gitea API request failed (${response.status} ${response.statusText}): ${detail}`
|
||||
);
|
||||
}
|
||||
|
||||
return payload;
|
||||
@@ -148,7 +153,9 @@ async function run() {
|
||||
const lock = await readFile(options.lockFile, 'utf8');
|
||||
const lockJson = JSON.parse(lock);
|
||||
if (!SEMVER.test(lockJson.releaseVersion)) {
|
||||
throw new Error(`Invalid releaseVersion in lock: ${lockJson.releaseVersion}`);
|
||||
throw new Error(
|
||||
`Invalid releaseVersion in lock: ${lockJson.releaseVersion}`
|
||||
);
|
||||
}
|
||||
|
||||
const releaseVersion = parseReleaseVersionFromLock(lockJson);
|
||||
@@ -192,8 +199,12 @@ async function run() {
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
console.log(`DRY-RUN: would ensure or create release ${releaseTag} on ${options.owner}/${options.repo}.`);
|
||||
console.log(`DRY-RUN: would upload assets ${path.basename(archive)} and ${path.basename(checksumFile)}.`);
|
||||
console.log(
|
||||
`DRY-RUN: would ensure or create release ${releaseTag} on ${options.owner}/${options.repo}.`
|
||||
);
|
||||
console.log(
|
||||
`DRY-RUN: would upload assets ${path.basename(archive)} and ${path.basename(checksumFile)}.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,13 +227,15 @@ async function run() {
|
||||
target_commitish: options.target || 'main',
|
||||
name: options.name,
|
||||
body:
|
||||
options.body
|
||||
|| `Automated release of add-ideas toolbox ${releaseTag} from lock release ${releaseVersion}.`,
|
||||
options.body ||
|
||||
`Automated release of add-ideas toolbox ${releaseTag} from lock release ${releaseVersion}.`,
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
};
|
||||
if (dryRun) {
|
||||
console.log(`DRY-RUN: would create release ${releaseTag} on ${options.owner}/${options.repo}`);
|
||||
console.log(
|
||||
`DRY-RUN: would create release ${releaseTag} on ${options.owner}/${options.repo}`
|
||||
);
|
||||
release = { id: '<dry-run>', assets: [] };
|
||||
} else {
|
||||
release = await giteaRequest(`${releasePrefix}/releases`, {
|
||||
@@ -238,14 +251,20 @@ async function run() {
|
||||
} else {
|
||||
release = tagLookup;
|
||||
if (dryRun) {
|
||||
console.log(`DRY-RUN: would reuse existing release ${releaseTag} (${release?.id ?? 'unknown'})`);
|
||||
console.log(
|
||||
`DRY-RUN: would reuse existing release ${releaseTag} (${release?.id ?? 'unknown'})`
|
||||
);
|
||||
} else {
|
||||
console.log(`Using existing release ${releaseTag} (${release.id})`);
|
||||
}
|
||||
}
|
||||
|
||||
if (dryRun) {
|
||||
console.log('DRY-RUN: would upload assets:', options.archive, options.checksum);
|
||||
console.log(
|
||||
'DRY-RUN: would upload assets:',
|
||||
options.archive,
|
||||
options.checksum
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -258,7 +277,9 @@ async function run() {
|
||||
for (const asset of candidateAssets) {
|
||||
const duplicate = existingAssets.find((entry) => entry.name === asset.name);
|
||||
if (duplicate) {
|
||||
console.log(`Deleting existing asset ${asset.name} from release ${releaseTag}`);
|
||||
console.log(
|
||||
`Deleting existing asset ${asset.name} from release ${releaseTag}`
|
||||
);
|
||||
await giteaRequest(
|
||||
`${releasePrefix}/releases/assets/${duplicate.id}`,
|
||||
{ method: 'DELETE', headers },
|
||||
@@ -281,7 +302,9 @@ async function run() {
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Release ${releaseTag} published on ${options.owner}/${options.repo}`);
|
||||
console.log(
|
||||
`Release ${releaseTag} published on ${options.owner}/${options.repo}`
|
||||
);
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user