Skip to content

Build & Release Tauri app #98

Build & Release Tauri app

Build & Release Tauri app #98

Workflow file for this run

name: 'Build & Release Tauri app'
on:
workflow_dispatch:
inputs:
release_message:
description: 'Message to write in the release'
required: true
type: string
default: 'v__VERSION__ contains bug fixes and new UI features. [Changelog](https://github.com/UnofficialCrusaderPatch/UCP3-GUI/wiki/Changelog#)'
pre_release:
description: 'Pre release?'
required: true
default: true
type: boolean
env:
RELEASE_BODY: ''
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [windows-latest, ubuntu-20.04]
steps:
- name: Checkout git repo
uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: install app dependencies
run: |
npm ci
- name: Test
shell: pwsh
run: |
npm run test -- --test-timeout=10000
- name: Create changelog URL (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
m="[Changelog](https://github.com/UnofficialCrusaderPatch/UCP3-GUI/wiki/Changelog#)"
echo "RELEASE_BODY=$m" >> $GITHUB_ENV
- name: Create changelog URL (Windows)
if: matrix.os == 'windows-latest'
run: |
# First set the version environment variable
Install-Module -Name PSToml -Scope CurrentUser -Force
Import-Module PSToml
## Get the version
$conf = Get-Content -Raw -Path "src-tauri/Cargo.toml" | ConvertFrom-Toml
$v = $conf.package.version
echo "UCP3_GUI_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Then, produce the URL
$m = "${{ inputs.release_message }}"
$t = "[Changelog](https://github.com/UnofficialCrusaderPatch/UCP3-GUI/wiki/Changelog#)"
if ( $m.Contains($t) ) {
$vm = $v.Replace(".", "") # Needed this way for pound urls
## Create the version URL
$url = $t.Replace("#", "#v$vm")
$n = $m.Replace($t, $url)
## Write the url
echo "RELEASE_BODY=$n" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
} else {
echo "RELEASE_BODY=$m" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
shell: pwsh
- name: Build the app and publish it
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
with:
includeRelease: true
includeUpdaterJson: true
updaterJsonPreferNsis: true
tagName: v__VERSION__
releaseName: 'UCP3-GUI: v__VERSION__'
releaseBody: '${{ env.RELEASE_BODY }}'
releaseDraft: false
prerelease: ${{ inputs.pre_release }}
push_release:
runs-on: windows-latest
needs: build
steps:
- name: Checkout git repo
uses: actions/checkout@v4
- name: Extract version from Cargo.toml
shell: pwsh
run: |
Install-Module -Name PSToml -Scope CurrentUser -Force
Import-Module PSToml
## Get the version
$conf = Get-Content -Raw -Path "src-tauri/Cargo.toml" | ConvertFrom-Toml
$v = $conf.package.version
echo "UCP3_GUI_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Fetch latest.json
uses: actions/github-script@v7
id: latest-json
with:
script: |
const fs = require('fs');
const release = await github.rest.repos.getReleaseByTag({
owner: 'UnofficialCrusaderPatch',
repo: 'UCP3-GUI',
tag: 'v${{ env.UCP3_GUI_VERSION }}',
});
const assets = await github.rest.repos.listReleaseAssets({
owner: 'UnofficialCrusaderPatch',
repo: 'UCP3-GUI',
release_id: release.data.id,
});
const asset = assets.data.filter((r) => r.name === 'latest.json')[0];
const contents = await github.rest.repos.getReleaseAsset({
owner: 'UnofficialCrusaderPatch',
repo: 'UCP3-GUI',
asset_id: asset.id,
headers: {
Accept: 'application/octet-stream',
},
});
fs.writeFileSync('latest.json', Buffer.from(contents.data));
return JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(contents.data)));
- name: Push release to Tauri auto updater
if: ${{ inputs.pre_release == false }}
uses: exuanbo/actions-deploy-gist@v1
with:
token: '${{ secrets.UCP3_MACHINE_GIST_TOKEN }}'
gist_id: 2a179c892f49448c85dfcc9e5f9a3c6b
file_path: latest.json
file_type: text