mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-09-24 15:49:09 +00:00
d4b64d564b
The workflow triggers on `v*` tags and build.yml extracts version from any v-prefixed tag. Updated the regex from `^v\d+\.\d+\.\d+` to `^v\d` to accept tags like v1, v1.2, v1.2.3, etc. This ensures version parsing stays in sync with build.yml behavior. Co-Authored-By: Claude <noreply@anthropic.com>
107 lines
4.2 KiB
JavaScript
107 lines
4.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Check if refName is a version tag (matches v* pattern used by workflow trigger)
|
|
// This keeps parsing in sync with build.yml which triggers on tags: v*
|
|
function isVersionTag(refName) {
|
|
return refName && /^v\d/.test(refName);
|
|
}
|
|
|
|
// Determine version priority:
|
|
// 1. VERSION env variable
|
|
// 2. Any v* tag (v1, v1.2, v1.2.3, etc. - matches build.yml trigger)
|
|
// 3. Short commit ID (first 7 chars of GITHUB_SHA)
|
|
// 4. package.json version as fallback
|
|
function getVersion() {
|
|
if (process.env.VERSION) {
|
|
return process.env.VERSION;
|
|
}
|
|
|
|
const refName = process.env.GITHUB_REF_NAME;
|
|
// Accept any v* tag to match build.yml behavior
|
|
if (isVersionTag(refName)) {
|
|
return refName.replace(/^v/, '');
|
|
}
|
|
|
|
// Use short commit ID
|
|
const sha = process.env.GITHUB_SHA;
|
|
if (sha) {
|
|
return sha.substring(0, 7);
|
|
}
|
|
|
|
// Fall back to package.json version
|
|
try {
|
|
const pkgPath = path.join(__dirname, '..', '..', 'package.json');
|
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
return pkg.version;
|
|
} catch {
|
|
return '0.0.0';
|
|
}
|
|
}
|
|
|
|
const version = getVersion();
|
|
const repo = process.env.GITHUB_REPOSITORY || 'binaricat/netcatty';
|
|
// For tag releases, use the tag; for workflow_dispatch, create a tag from version
|
|
const tag = isVersionTag(process.env.GITHUB_REF_NAME)
|
|
? process.env.GITHUB_REF_NAME
|
|
: `v${version}`;
|
|
const baseUrl = `https://github.com/${repo}/releases/download/${tag}`;
|
|
|
|
// Filename patterns based on electron-builder.config.cjs artifactName: '${productName}-${version}-${os}-${arch}.${ext}'
|
|
const files = {
|
|
mac: {
|
|
arm64: `Netcatty-${version}-mac-arm64.dmg`,
|
|
x64: `Netcatty-${version}-mac-x64.dmg`
|
|
},
|
|
win: {
|
|
x64: `Netcatty-${version}-win-x64.exe`,
|
|
arm64: `Netcatty-${version}-win-arm64.exe`
|
|
},
|
|
linux: {
|
|
appimage: {
|
|
x64: `Netcatty-${version}-linux-x64.AppImage`,
|
|
arm64: `Netcatty-${version}-linux-arm64.AppImage`
|
|
},
|
|
deb: {
|
|
x64: `Netcatty-${version}-linux-x64.deb`,
|
|
arm64: `Netcatty-${version}-linux-arm64.deb`
|
|
},
|
|
rpm: {
|
|
x64: `Netcatty-${version}-linux-x64.rpm`,
|
|
arm64: `Netcatty-${version}-linux-arm64.rpm`
|
|
}
|
|
}
|
|
};
|
|
|
|
const badges = {
|
|
win: {
|
|
setup_x64: `[](${baseUrl}/${files.win.x64})`,
|
|
setup_arm64: `[](${baseUrl}/${files.win.arm64})`
|
|
},
|
|
mac: {
|
|
apple_silicon: `[](${baseUrl}/${files.mac.arm64})`,
|
|
intel: `[](${baseUrl}/${files.mac.x64})`
|
|
},
|
|
linux: {
|
|
appimage_x64: `[](${baseUrl}/${files.linux.appimage.x64})`,
|
|
appimage_arm64: `[](${baseUrl}/${files.linux.appimage.arm64})`,
|
|
deb_x64: `[](${baseUrl}/${files.linux.deb.x64})`,
|
|
deb_arm64: `[](${baseUrl}/${files.linux.deb.arm64})`,
|
|
rpm_x64: `[](${baseUrl}/${files.linux.rpm.x64})`,
|
|
rpm_arm64: `[](${baseUrl}/${files.linux.rpm.arm64})`
|
|
}
|
|
};
|
|
|
|
const content = `
|
|
## Download based on your OS:
|
|
|
|
| OS | Download |
|
|
| :--- | :--- |
|
|
| **Windows** | ${badges.win.setup_x64} ${badges.win.setup_arm64} |
|
|
| **macOS** | ${badges.mac.apple_silicon} ${badges.mac.intel} |
|
|
| **Linux** | ${badges.linux.appimage_x64} ${badges.linux.deb_x64} ${badges.linux.rpm_x64} <br> ${badges.linux.appimage_arm64} ${badges.linux.deb_arm64} ${badges.linux.rpm_arm64} |
|
|
`;
|
|
|
|
fs.writeFileSync('release_notes.md', content);
|
|
console.log('Generated release_notes.md');
|