Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Install frontend dependencies
run: pnpm install

- name: Sync version to release tag
run: node scripts/set-version.mjs "${{ github.event.inputs.version }}"

- name: Build Tauri App
run: pnpm tauri build --bundles deb rpm appimage
env:
Expand Down Expand Up @@ -108,6 +111,14 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24

- name: Sync version to release tag
run: node scripts/set-version.mjs "${{ github.event.inputs.version }}"

- name: Install flatpak tooling
run: |
sudo apt-get update
Expand Down Expand Up @@ -162,6 +173,8 @@ jobs:
- build-flatpak
permissions:
contents: write
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}

steps:
- name: Checkout repository
Expand Down Expand Up @@ -189,6 +202,9 @@ jobs:
- name: Install frontend dependencies
run: pnpm install

- name: Sync version to release tag
run: node scripts/set-version.mjs "${{ github.event.inputs.version }}"

- name: Build Tauri App
run: pnpm tauri build
env:
Expand Down Expand Up @@ -259,6 +275,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Notify Discord
if: ${{ env.DISCORD_WEBHOOK_URL != '' }}
shell: pwsh
run: |
$version = "${{ github.event.inputs.version }}"
Expand All @@ -280,4 +297,4 @@ jobs:
)
} | ConvertTo-Json -Depth 5

Invoke-RestMethod -Uri "${{ secrets.DISCORD_WEBHOOK_URL }}" -Method Post -ContentType "application/json" -Body $payload
Invoke-RestMethod -Uri $env:DISCORD_WEBHOOK_URL -Method Post -ContentType "application/json" -Body $payload
28 changes: 28 additions & 0 deletions scripts/set-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Sets the app version across every manifest from a single argument so the
// release tag can't drift from the built binary. Usage: node scripts/set-version.mjs v0.1.6
import { readFileSync, writeFileSync } from "node:fs";

const raw = process.argv[2] ?? "";
const version = raw.replace(/^v/, "");

if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(version)) {
console.error(`set-version: invalid version "${raw}" (expected e.g. v0.1.6)`);
process.exit(1);
}

const edits = [
["package.json", /"version": "[^"]*"/, `"version": "${version}"`],
["src-tauri/tauri.conf.json", /"version": "[^"]*"/, `"version": "${version}"`],
["src-tauri/Cargo.toml", /^version = "[^"]*"/m, `version = "${version}"`],
["src-tauri/Cargo.lock", /(name = "moon-translator"\r?\nversion = ")[^"]*/, `$1${version}`],
];

for (const [file, pattern, replacement] of edits) {
const text = readFileSync(file, "utf8");
if (!pattern.test(text)) {
console.error(`set-version: version pattern not found in ${file}`);
process.exit(1);
}
writeFileSync(file, text.replace(pattern, replacement));
console.log(`set ${file} -> ${version}`);
}
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading