mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 02:36:04 +10:00
ci: use semver for auto releases
This commit is contained in:
22
.github/workflows/windows-build.yml
vendored
22
.github/workflows/windows-build.yml
vendored
@@ -32,25 +32,37 @@ jobs:
|
|||||||
GH_TOKEN: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
$version = node scripts/ci/update-version.js
|
node scripts/ci/update-version.js $env:GITHUB_OUTPUT
|
||||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
|
||||||
|
|
||||||
- name: Build/release Electron app
|
- name: Build/release Electron app
|
||||||
uses: samuelmeuli/action-electron-builder@v1
|
uses: samuelmeuli/action-electron-builder@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
release: true
|
release: false
|
||||||
args: --win --x64 --publish always
|
args: --win --x64 --publish never
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Create GitHub release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
tag_name: v${{ steps.version.outputs.tag }}
|
||||||
|
name: ${{ steps.version.outputs.tag }}
|
||||||
|
prerelease: false
|
||||||
|
draft: false
|
||||||
|
files: |
|
||||||
|
dist/**/*.exe
|
||||||
|
dist/**/*.blockmap
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GH_TOKEN != '' && secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Upload installer artifact
|
- name: Upload installer artifact
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: windows-installer-${{ steps.version.outputs.version }}
|
name: windows-installer-${{ steps.version.outputs.tag }}
|
||||||
path: |
|
path: |
|
||||||
dist/**/*.exe
|
dist/**/*.exe
|
||||||
dist/**/*.blockmap
|
dist/**/*.blockmap
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ async function fetchReleases() {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const message = await response.text();
|
const message = await response.text();
|
||||||
console.error(`Failed to fetch releases: ${response.status} ${message}`);
|
console.warn(`Failed to fetch releases: ${response.status} ${message}`);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,18 @@ function determineNextVersion(releases) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${isoDate}-${String(index).padStart(2, '0')}`;
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toSemver(date, index) {
|
||||||
|
const [year, month, day] = date.split('-');
|
||||||
|
const base = `${Number(year)}.${Number(month)}.${Number(day)}`;
|
||||||
|
if (index <= 1) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = String(index).padStart(2, '0');
|
||||||
|
return `${base}-a${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateJson(filePath, version) {
|
function updateJson(filePath, version) {
|
||||||
@@ -65,13 +76,24 @@ function updateJson(filePath, version) {
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const releases = await fetchReleases();
|
const releases = await fetchReleases();
|
||||||
const version = determineNextVersion(releases);
|
const index = determineNextVersion(releases);
|
||||||
|
const indexString = String(index).padStart(2, '0');
|
||||||
|
const tag = `${isoDate}-${indexString}`;
|
||||||
|
const semver = toSemver(isoDate, index);
|
||||||
const root = process.cwd();
|
const root = process.cwd();
|
||||||
|
|
||||||
updateJson(path.join(root, 'package.json'), version);
|
updateJson(path.join(root, 'package.json'), semver);
|
||||||
updateJson(path.join(root, 'package-lock.json'), version);
|
updateJson(path.join(root, 'package-lock.json'), semver);
|
||||||
|
|
||||||
console.log(version);
|
const outputPath = process.argv[2];
|
||||||
|
|
||||||
|
if (outputPath) {
|
||||||
|
fs.appendFileSync(outputPath, `semver=${semver}\n`, 'utf8');
|
||||||
|
fs.appendFileSync(outputPath, `tag=${tag}\n`, 'utf8');
|
||||||
|
} else {
|
||||||
|
console.log(`SEMVER=${semver}`);
|
||||||
|
console.log(`TAG=${tag}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error instanceof Error ? error.message : String(error));
|
console.error(error instanceof Error ? error.message : String(error));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user