Skip to content

Release

Release #18

Workflow file for this run

name: Release
on:
push:
paths:
- 'src-tauri/tauri.conf.json'
branches:
- main
workflow_dispatch:
jobs:
release:
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract version from tauri.conf.json
id: version
shell: pwsh
run: |
$config = Get-Content src-tauri/tauri.conf.json | ConvertFrom-Json
$version = $config.version
echo "version=$version" >> $env:GITHUB_OUTPUT
echo "Version: $version"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'
cache: 'pnpm'
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
# 编译缓存
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: "src-tauri -> target"
- name: Install dependencies
run: pnpm install
- name: Build application
run: pnpm build
- name: Create and push tag
id: create_tag
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$version = "${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$version" -m "Release v$version"
git push origin "v$version"
- name: Create Release
id: create_release
if: steps.create_tag.outcome == 'success'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
release_name: Majdata Hub v${{ steps.version.outputs.version }}
draft: false
prerelease: false
- name: Get MSI files
id: msi_files
if: steps.create_tag.outcome == 'success'
shell: pwsh
run: |
$msiPath = "src-tauri/target/release/bundle/msi"
if (Test-Path $msiPath) {
$files = Get-ChildItem -Path $msiPath -File
$fileList = $files | ForEach-Object { $_.FullName }
echo "Files found: $($files.Name -join ', ')"
echo "files=$($fileList -join ';')" >> $env:GITHUB_OUTPUT
} else {
echo "No MSI directory found"
echo "files=" >> $env:GITHUB_OUTPUT
}
- name: Get NSIS files
id: nsis_files
if: steps.create_tag.outcome == 'success'
shell: pwsh
run: |
$nsisPath = "src-tauri/target/release/bundle/nsis"
if (Test-Path $nsisPath) {
$files = Get-ChildItem -Path $nsisPath -File
$fileList = $files | ForEach-Object { $_.FullName }
echo "Files found: $($files.Name -join ', ')"
echo "files=$($fileList -join ';')" >> $env:GITHUB_OUTPUT
} else {
echo "No NSIS directory found"
echo "files=" >> $env:GITHUB_OUTPUT
}
- name: Upload MSI files to Release
if: steps.create_tag.outcome == 'success' && steps.msi_files.outputs.files != ''
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$files = "${{ steps.msi_files.outputs.files }}" -split ';'
foreach ($file in $files) {
if ($file -and (Test-Path $file)) {
$fileName = Split-Path $file -Leaf
echo "Uploading $fileName..."
gh release upload v${{ steps.version.outputs.version }} "$file" --clobber
}
}
- name: Upload NSIS files to Release
if: steps.create_tag.outcome == 'success' && steps.nsis_files.outputs.files != ''
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$files = "${{ steps.nsis_files.outputs.files }}" -split ';'
foreach ($file in $files) {
if ($file -and (Test-Path $file)) {
$fileName = Split-Path $file -Leaf
echo "Uploading $fileName..."
gh release upload v${{ steps.version.outputs.version }} "$file" --clobber
}
}
- name: Move uploaded files to temp folder
if: steps.create_tag.outcome == 'success'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path "temp" | Out-Null
$msiPath = "src-tauri/target/release/bundle/msi"
$nsisPath = "src-tauri/target/release/bundle/nsis"
if (Test-Path $msiPath) {
Get-ChildItem -Path $msiPath -File | ForEach-Object {
Move-Item -Path $_.FullName -Destination "temp/" -Force
echo "Moved $($_.Name) to temp/"
}
}
if (Test-Path $nsisPath) {
Get-ChildItem -Path $nsisPath -File | ForEach-Object {
Move-Item -Path $_.FullName -Destination "temp/" -Force
echo "Moved $($_.Name) to temp/"
}
}
- name: Commit files in temp folder
if: steps.create_tag.outcome == 'success'
shell: bash
env:
MIRROR_URL: ${{ vars.CNB_URL }}
MIRROR_TOKEN: ${{ vars.CNB_TOKEN }}
run: |
version="${{ steps.version.outputs.version }}"
cd temp
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "$version"
AUTH_URL=$(echo "$MIRROR_URL" | sed -E "s#^https://#https://x-access-token:${MIRROR_TOKEN}@#")
git remote remove mirror 2>/dev/null || true
git remote add mirror "$AUTH_URL"
git push mirror --all --force