Skip to content

CI: fix release building #3

CI: fix release building

CI: fix release building #3

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to (re)build (e.g. v2.0.0-beta.4)'
required: true
type: string
permissions:
contents: write
concurrency:
group: release-${{ github.event.inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
prepare:
name: Prepare release
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.context.outputs.tag }}
version: ${{ steps.context.outputs.version }}
is_prerelease: ${{ steps.context.outputs.is_prerelease }}
steps:
- name: Resolve tag and version
id: context
shell: bash
run: |
tag="${{ github.event.inputs.tag || github.ref_name }}"
if [[ "$tag" != v* ]]; then
echo "::error::Tag '$tag' must start with 'v'"
exit 1
fi
version="${tag#v}"
if [[ "$version" == *-* ]]; then
is_prerelease=true
else
is_prerelease=false
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "is_prerelease=$is_prerelease" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.context.outputs.tag }}
fetch-depth: 0
- name: Verify package.json version matches tag
shell: bash
env:
EXPECTED: ${{ steps.context.outputs.version }}
run: |
actual=$(node -p "require('./package.json').version")
if [[ "$actual" != "$EXPECTED" ]]; then
echo "::error::package.json version ($actual) does not match tag version ($EXPECTED)"
exit 1
fi
- name: Ensure draft release exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
TAG: ${{ steps.context.outputs.tag }}
VERSION: ${{ steps.context.outputs.version }}
IS_PRERELEASE: ${{ steps.context.outputs.is_prerelease }}
shell: bash
run: |
previous_tag=""
while read -r candidate_tag; do
if [[ "$candidate_tag" == "$TAG" ]]; then
break
fi
previous_tag="$candidate_tag"
done < <(git tag --list 'v[0-9]*' --sort=v:refname)
notes_args=(-f "tag_name=$TAG" -f "target_commitish=$TAG")
if [[ -n "$previous_tag" ]]; then
notes_args+=(-f "previous_tag_name=$previous_tag")
fi
generated_notes_file="$(mktemp)"
gh api "repos/$REPOSITORY/releases/generate-notes" "${notes_args[@]}" --jq '.body // ""' \
| awk '!/^\*\*Full Changelog\*\*: /' > "$generated_notes_file"
notes_marker="<!-- generated-release-notes:$TAG -->"
release_notes_file="$(mktemp)"
{
echo "$notes_marker"
cat "$generated_notes_file"
} > "$release_notes_file"
if ! gh release view "$TAG" >/dev/null 2>&1; then
flags=(--draft)
if [[ "$IS_PRERELEASE" == "true" ]]; then
flags+=(--prerelease)
fi
gh release create "$TAG" \
--title "Sigma File Manager v$VERSION" \
--notes-file "$release_notes_file" \
"${flags[@]}"
else
existing_notes_file="$(mktemp)"
cleaned_notes_file="$(mktemp)"
updated_notes_file="$(mktemp)"
gh release view "$TAG" --json body --jq '.body // ""' > "$existing_notes_file"
awk '!/^\*\*Full Changelog\*\*: /' "$existing_notes_file" > "$cleaned_notes_file"
if grep -Fq "$notes_marker" "$cleaned_notes_file"; then
cp "$cleaned_notes_file" "$updated_notes_file"
elif [[ -s "$cleaned_notes_file" ]]; then
{
cat "$cleaned_notes_file"
echo
cat "$release_notes_file"
} > "$updated_notes_file"
else
cp "$release_notes_file" "$updated_notes_file"
fi
gh release edit "$TAG" --notes-file "$updated_notes_file"
echo "Release $TAG already exists; assets will be added/replaced."
fi
build:
name: Build (${{ matrix.platform }})
needs: prepare
strategy:
fail-fast: false
matrix:
include:
- platform: windows
os: windows-latest
- platform: linux
os: ubuntu-22.04
runs-on: ${{ matrix.os }}
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
- name: Setup Volta
uses: volta-cli/action@v4
- name: Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.9
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
prefix-key: v1-rust
shared-key: release-${{ matrix.platform }}
workspaces: src-tauri
cache-on-failure: true
- name: Resolve npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> "$GITHUB_OUTPUT"
- name: Cache npm
uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Linux dependencies
if: matrix.platform == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
patchelf
- name: Install npm dependencies
run: npm ci
- name: Sync Cargo version with package.json
run: npm run sync-version
- name: Build Tauri bundles
env:
NO_STRIP: ${{ matrix.platform == 'linux' && 'true' || '' }}
PLATFORM: ${{ matrix.platform }}
shell: bash
run: |
if [[ "$PLATFORM" == "linux" ]]; then
npm run tauri:build:linux
else
npm run tauri:build
fi
- name: Upload Tauri bundles
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.prepare.outputs.tag }}
VERSION: ${{ needs.prepare.outputs.version }}
PLATFORM: ${{ matrix.platform }}
shell: bash
run: |
mkdir -p staged
shopt -s nullglob
if [[ "$PLATFORM" == "windows" ]]; then
bundles=(src-tauri/target/release/bundle/nsis/*.exe)
else
bundles=(
src-tauri/target/release/bundle/appimage/*.AppImage
src-tauri/target/release/bundle/deb/*.deb
)
fi
if (( ${#bundles[@]} == 0 )); then
echo "::error::No Tauri bundles found for $PLATFORM"
exit 1
fi
for bundle in "${bundles[@]}"; do
case "$bundle" in
*.AppImage)
staged_asset="staged/Sigma-File-Manager-${VERSION}-linux.AppImage"
;;
*.deb)
staged_asset="staged/Sigma-File-Manager-${VERSION}-linux.deb"
;;
*.exe)
staged_asset="staged/Sigma-File-Manager-${VERSION}-windows-setup.exe"
;;
*)
extension="${bundle##*.}"
staged_asset="staged/Sigma-File-Manager-${VERSION}-${PLATFORM}.${extension}"
;;
esac
cp "$bundle" "$staged_asset"
gh release upload "$TAG" "$staged_asset" --clobber
done
- name: Upload Linux binary
if: matrix.platform == 'linux'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.prepare.outputs.tag }}
VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
binary="src-tauri/target/release/sigma-file-manager"
if [[ ! -f "$binary" ]]; then
echo "::error::Linux binary not found at $binary"
exit 1
fi
chmod +x "$binary"
mkdir -p staged
staged_binary="staged/Sigma-File-Manager-${VERSION}-linux-binary"
cp "$binary" "$staged_binary"
gh release upload "$TAG" "$staged_binary" --clobber
- name: Install Flatpak toolchain
if: matrix.platform == 'linux'
run: |
sudo apt-get install -y flatpak flatpak-builder
flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install -y --noninteractive --user flathub org.gnome.Platform//48 org.gnome.Sdk//48
- name: Build Flatpak bundle
if: matrix.platform == 'linux'
run: bash flatpak/build-flatpak.sh
- name: Upload Flatpak bundle
if: matrix.platform == 'linux'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.prepare.outputs.tag }}
VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
flatpak_bundle="flatpak/output/Sigma-File-Manager-${VERSION}-linux.flatpak"
if [[ ! -f "$flatpak_bundle" ]]; then
echo "::error::Flatpak bundle not found at $flatpak_bundle"
exit 1
fi
gh release upload "$TAG" "$flatpak_bundle" --clobber