ci(default): added in default configs so they work across everything
This commit is contained in:
28
.vscode/settings.json
vendored
Normal file
28
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"workbench.colorTheme": "Default Dark+",
|
||||||
|
"prettier.tabWidth": 4,
|
||||||
|
"terminal.integrated.env.windows": {},
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[javascriptreact]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[typescript]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[typescriptreact]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[json]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[graphql]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[handlebars]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,18 +3,20 @@ if (!version) {
|
|||||||
console.error("Version not passed to create-gitea-release.js");
|
console.error("Version not passed to create-gitea-release.js");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
import fs from 'fs-extra';
|
import fs from "fs-extra";
|
||||||
import { spawnSync } from 'child_process';
|
import path from "path";
|
||||||
import fetch from 'node-fetch';
|
import { spawnSync } from "child_process";
|
||||||
import dotenv from 'dotenv';
|
import { fileURLToPath } from "url";
|
||||||
dotenv.config({ path: './.env' });
|
import fetch from "node-fetch";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
dotenv.config({ path: "./.env" });
|
||||||
|
|
||||||
// Load package.json version
|
// Load package.json version
|
||||||
// const pkg = await fs.readJson('package.json');
|
// const pkg = await fs.readJson('package.json');
|
||||||
// const version = pkg.version;
|
// const version = pkg.version;
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
console.error('Version not found in package.json');
|
console.error("Version not found in package.json");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,15 +25,15 @@ const __filename = fileURLToPath(import.meta.url);
|
|||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
// Absolute path to BUILD_NUMBER
|
// Absolute path to BUILD_NUMBER
|
||||||
const buildNumberPath = path.resolve(__dirname, '../BUILD_NUMBER');
|
const buildNumberPath = path.resolve(__dirname, "../BUILD_NUMBER");
|
||||||
|
|
||||||
// Load build number from BUILD_NUMBER file
|
// Load build number from BUILD_NUMBER file
|
||||||
let buildNumber = '0';
|
let buildNumber = "0";
|
||||||
try {
|
try {
|
||||||
rawBuild = (await fs.readFile(buildNumberPath, 'utf8')).trim();
|
rawBuild = (await fs.readFile(buildNumberPath, "utf8")).trim();
|
||||||
console.log("Raw build" ,rawBuild)
|
console.log("Raw build", rawBuild);
|
||||||
if (rawBuild) {
|
if (rawBuild) {
|
||||||
const [numPart, namePart] = rawBuild.split('-');
|
const [numPart, namePart] = rawBuild.split("-");
|
||||||
const num = parseInt(numPart, 10);
|
const num = parseInt(numPart, 10);
|
||||||
|
|
||||||
if (!isNaN(num) && namePart) {
|
if (!isNaN(num) && namePart) {
|
||||||
@@ -39,45 +41,46 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
console.warn('BUILD_NUMBER file not found, defaulting to 0');
|
console.warn("BUILD_NUMBER file not found, defaulting to 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compose full version string with build number
|
// Compose full version string with build number
|
||||||
const fullVersion = `${version}.${buildNumber}`;
|
const fullVersion = `${version}.${buildNumber}`;
|
||||||
|
|
||||||
const {
|
const { GITEA_URL, GITEA_USERNAME, GITEA_REPO, GITEA_TOKEN } = process.env;
|
||||||
GITEA_URL,
|
|
||||||
GITEA_USERNAME,
|
|
||||||
GITEA_REPO,
|
|
||||||
GITEA_TOKEN
|
|
||||||
} = process.env;
|
|
||||||
|
|
||||||
if (!GITEA_URL || !GITEA_USERNAME || !GITEA_REPO || !GITEA_TOKEN) {
|
if (!GITEA_URL || !GITEA_USERNAME || !GITEA_REPO || !GITEA_TOKEN) {
|
||||||
console.error('Missing required environment variables (GITEA_URL, GITEA_USERNAME, GITEA_REPO, GITEA_TOKEN)');
|
console.error(
|
||||||
|
"Missing required environment variables (GITEA_URL, GITEA_USERNAME, GITEA_REPO, GITEA_TOKEN)"
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1) Generate or update CHANGELOG.md using conventional-changelog CLI
|
// 1) Generate or update CHANGELOG.md using conventional-changelog CLI
|
||||||
console.log('Generating CHANGELOG.md...');
|
console.log("Generating CHANGELOG.md...");
|
||||||
const result = spawnSync('npx', [
|
const result = spawnSync(
|
||||||
'conventional-changelog',
|
"npx",
|
||||||
'-p',
|
[
|
||||||
'conventionalcommits',
|
"conventional-changelog",
|
||||||
'-i',
|
"-p",
|
||||||
'CHANGELOG.md',
|
"conventionalcommits",
|
||||||
'-s',
|
"-i",
|
||||||
'-r',
|
"CHANGELOG.md",
|
||||||
'0'
|
"-s",
|
||||||
], { stdio: 'inherit', shell: true });
|
"-r",
|
||||||
|
"0",
|
||||||
|
],
|
||||||
|
{ stdio: "inherit", shell: true }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.status !== 0) {
|
if (result.status !== 0) {
|
||||||
console.error('Failed to generate changelog');
|
console.error("Failed to generate changelog");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) Read changelog content for the current version
|
// 2) Read changelog content for the current version
|
||||||
const changelog = await fs.readFile('CHANGELOG.md', 'utf8');
|
const changelog = await fs.readFile("CHANGELOG.md", "utf8");
|
||||||
const regex = new RegExp(`## \\[${version}\\][\\s\\S]*?(?=## \\[|$)`, 'm');
|
const regex = new RegExp(`## \\[${version}\\][\\s\\S]*?(?=## \\[|$)`, "m");
|
||||||
const releaseNotes = changelog.match(regex)?.[0] || changelog;
|
const releaseNotes = changelog.match(regex)?.[0] || changelog;
|
||||||
|
|
||||||
console.log(`Release notes for v${version} saved`);
|
console.log(`Release notes for v${version} saved`);
|
||||||
@@ -94,21 +97,23 @@ const createRelease = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${GITEA_TOKEN}`,
|
Authorization: `token ${GITEA_TOKEN}`,
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(releaseData),
|
body: JSON.stringify(releaseData),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
throw new Error(`Failed to create release: ${response.status} - ${errorText}`);
|
throw new Error(
|
||||||
|
`Failed to create release: ${response.status} - ${errorText}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const release = await response.json();
|
const release = await response.json();
|
||||||
console.log('Release created:', release.html_url || release.url);
|
console.log("Release created:", release.html_url || release.url);
|
||||||
return release;
|
return release;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,18 +122,18 @@ const uploadAsset = async (release) => {
|
|||||||
const apiUrl = `https://${GITEA_URL}/api/v1/repos/${GITEA_USERNAME}/${GITEA_REPO}/releases/assets?tag=${release.tag_name}`;
|
const apiUrl = `https://${GITEA_URL}/api/v1/repos/${GITEA_USERNAME}/${GITEA_REPO}/releases/assets?tag=${release.tag_name}`;
|
||||||
const filePath = `releases/release-${fullVersion}.zip`;
|
const filePath = `releases/release-${fullVersion}.zip`;
|
||||||
|
|
||||||
if (!await fs.pathExists(filePath)) {
|
if (!(await fs.pathExists(filePath))) {
|
||||||
console.warn(`Zip file not found: ${filePath}. Skipping asset upload.`);
|
console.warn(`Zip file not found: ${filePath}. Skipping asset upload.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FormData = (await import('form-data')).default;
|
const FormData = (await import("form-data")).default;
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('name', `release-${fullVersion}.zip`);
|
form.append("name", `release-${fullVersion}.zip`);
|
||||||
form.append('attachment', fs.createReadStream(filePath));
|
form.append("attachment", fs.createReadStream(filePath));
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${GITEA_TOKEN}`,
|
Authorization: `token ${GITEA_TOKEN}`,
|
||||||
...form.getHeaders(),
|
...form.getHeaders(),
|
||||||
@@ -138,11 +143,13 @@ const uploadAsset = async (release) => {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
throw new Error(`Failed to upload asset: ${response.status} - ${errorText}`);
|
throw new Error(
|
||||||
|
`Failed to upload asset: ${response.status} - ${errorText}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const asset = await response.json();
|
const asset = await response.json();
|
||||||
console.log('Asset uploaded:', asset.browser_download_url || asset.url);
|
console.log("Asset uploaded:", asset.browser_download_url || asset.url);
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user