Pre-Release #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Pre-Release" | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
required: true | |
description: "Version to build" | |
jobs: | |
validate-inputs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate version format | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
# regex obtained from https://semver.org | |
run: | | |
SEMVER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" | |
if [[ ! "$VERSION" =~ $SEMVER_REGEX ]]; then | |
echo "Error: The version '${VERSION}' is not a valid SemVer format (MAJOR.MINOR.PATCH)." | |
exit 1 | |
fi | |
- name: Check if tag exists | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
run: | | |
if git ls-remote --tags origin | grep -q "refs/tags/$VERSION"; then | |
echo "Error: Tag '${VERSION}' already exists." | |
exit 1 | |
fi | |
continuous-integration: | |
needs: validate-inputs | |
uses: ./.github/workflows/ci.yml | |
create-pre-release: | |
needs: continuous-integration | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
outputs: | |
release_id: ${{ steps.create-pre-release.outputs.result }} | |
env: | |
VERSION: ${{ github.event.inputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Change version | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const version = process.env.VERSION; | |
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
packageJson.version = version; | |
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2)); | |
let cargoTomlContent = fs.readFileSync('Cargo.toml', 'utf-8'); | |
cargoTomlContent = cargoTomlContent.replace(/^version\s*=\s*".*"/m, `version = "${version}"`); | |
fs.writeFileSync('Cargo.toml', cargoTomlContent); | |
- name: Create release | |
id: create-pre-release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
const changelogContent = fs.readFileSync('changelog.md', 'utf-8'); | |
const regex = new RegExp(`(?<=\\[Unreleased\\]\\s)([\\s\\S]*?)(?=\\s## \\[)`, 'g'); | |
const releaseNotes = changelogContent.match(regex)?.[0].trim() || ''; | |
const { data } = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: `v${process.env.VERSION}`, | |
name: `Seelen UI v${process.env.VERSION}`, | |
body: releaseNotes, | |
generate_release_notes: true, | |
draft: true, | |
prerelease: true, | |
}); | |
return data.id; | |
build-installers: | |
needs: create-pre-release | |
permissions: | |
contents: write | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- platform: "windows-latest" | |
args: "" | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: "npm" | |
- name: Install Rust Nightly | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: nightly-2024-06-25 | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install frontend dependencies | |
run: npm clean-install | |
- uses: tauri-apps/tauri-action@v0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} | |
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} | |
with: | |
releaseId: ${{ needs.create-pre-release.outputs.release_id }} | |
args: ${{ matrix.args }} | |
publish-release: | |
needs: [build-installers, create-pre-release] | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Publish pre-release | |
uses: actions/github-script@v7 | |
env: | |
releaseId: ${{ needs.create-pre-release.outputs.release_id }} | |
with: | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
script: | | |
const result = await github.rest.repos.listReleaseAssets({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: process.env.releaseId, | |
}); | |
result.data.forEach(async (asset) => { | |
if (asset.name.endsWith('.sig')) { | |
await github.rest.repos.deleteReleaseAsset({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
asset_id: asset.id, | |
}); | |
} | |
}); | |
await github.rest.repos.updateRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: process.env.releaseId, | |
draft: false, | |
}); |