gerbil/.github/workflows/release.yml

215 lines
6.6 KiB
YAML

name: Release
permissions:
contents: write
actions: read
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag version to release (e.g., v1.0.0)'
required: true
type: string
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Get Node.js version from .nvmrc
id: versions
shell: bash
run: |
NODE_VERSION=$(cat .nvmrc)
echo "node-version=$NODE_VERSION" >> $GITHUB_OUTPUT
echo "📦 Using Node.js $NODE_VERSION from .nvmrc"
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ steps.versions.outputs.node-version }}
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run type check and linter
run: pnpm check
- name: Build Electron app
run: pnpm package
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifacts (macOS)
if: matrix.os == 'macos-latest'
uses: actions/upload-artifact@v6
with:
name: macos-release
path: |
release/*.dmg
release/latest-mac.yml
- name: Upload artifacts (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v6
with:
name: windows-release
path: |
release/*.exe
release/latest.yml
- name: Upload artifacts (Linux)
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v6
with:
name: linux-release
path: |
release/*.AppImage
release/latest-linux.yml
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
outputs:
is_prerelease: ${{ steps.release_type.outputs.is_prerelease }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -la artifacts/**/*
- name: Determine tag name
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
else
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Determine release type
id: release_type
run: |
if [[ "${{ steps.tag.outputs.tag }}" =~ -alpha|-beta|-rc ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "📋 This will be marked as a pre-release"
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "📋 This will be marked as a full release"
fi
- name: Create Release with all assets
run: |
# Collect all assets
assets=()
for file in artifacts/macos-release/*.dmg artifacts/macos-release/latest-mac.yml \
artifacts/windows-release/*.exe artifacts/windows-release/latest.yml \
artifacts/linux-release/*.AppImage artifacts/linux-release/latest-linux.yml; do
if [ -f "$file" ]; then
assets+=("$file")
fi
done
# Create release with all assets at once
if [ "${{ steps.release_type.outputs.is_prerelease }}" = "true" ]; then
gh release create ${{ steps.tag.outputs.tag }} \
--title "Gerbil ${{ steps.tag.outputs.tag }}" \
--generate-notes \
--prerelease \
"${assets[@]}"
else
gh release create ${{ steps.tag.outputs.tag }} \
--title "Gerbil ${{ steps.tag.outputs.tag }}" \
--generate-notes \
"${assets[@]}"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-flatpak:
needs: release
runs-on: ubuntu-latest
if: needs.release.outputs.is_prerelease != 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: master
- name: Determine tag name
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
echo "version=${${{ github.event.inputs.tag }}#v}" >> $GITHUB_OUTPUT
else
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
fi
- name: Compute AppImage sha256
id: sha256
run: |
URL="https://github.com/lone-cloud/gerbil/releases/download/${{ steps.tag.outputs.tag }}/Gerbil-${{ steps.tag.outputs.version }}.AppImage"
echo "url=$URL" >> $GITHUB_OUTPUT
SHA=$(curl -sL "$URL" | sha256sum | awk '{print $1}')
echo "sha256=$SHA" >> $GITHUB_OUTPUT
- name: Update flatpak manifest
run: |
sed -i "s|url: https://github.com/lone-cloud/gerbil/releases/download/v[^/]*/Gerbil-.*\.AppImage|url: ${{ steps.sha256.outputs.url }}|" flatpak/app.lonecloud.gerbil.yml
# Only replace the sha256 that follows the AppImage url (not the uv one)
python3 - <<'EOF'
import re, pathlib
p = pathlib.Path('flatpak/app.lonecloud.gerbil.yml')
txt = p.read_text()
txt = re.sub(
r'(url: https://github\.com/lone-cloud/gerbil/releases/download/v[^\n]+\n\s+sha256: )[a-f0-9]{64}',
r'\g<1>${{ steps.sha256.outputs.sha256 }}',
txt
)
p.write_text(txt)
EOF
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add flatpak/app.lonecloud.gerbil.yml
git diff --cached --quiet && echo "No changes" && exit 0
git commit -m "chore: update flatpak manifest for ${{ steps.tag.outputs.tag }}"
git push origin master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
aur-release:
needs: release
if: needs.release.outputs.is_prerelease != 'true'
uses: ./.github/workflows/aur-release.yml
with:
tag: ${{ github.ref_name }}
pkgrel: '1'
secrets: inherit