Skip to content

ci(release): replace softprops/action-gh-release with gh cli #18

ci(release): replace softprops/action-gh-release with gh cli

ci(release): replace softprops/action-gh-release with gh cli #18

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:
jobs:
release:
if: >-
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
(
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.title, 'chore: release')
)
runs-on: macos-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from package.json
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
env:
GITHUB_TOKEN: ${{ github.token }}
run: bun install --frozen-lockfile
- name: Rebuild native modules for Electron
run: bun run rebuild:electron-deps
- name: Build desktop app
run: bun run build:desktop
- name: Package unpacked macOS app bundle
run: bunx --bun electron-builder --config electron-builder.yml --dir
- name: Prepare internal macOS release bundle
run: bun run scripts/prepare-macos-release-bundle.mjs
- name: Create GitHub release and upload app bundle zip
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
TAG="v${{ steps.version.outputs.version }}"
ASSET="release/Stave-macOS.zip"
set +e
RELEASE_VIEW_OUTPUT=$(gh release view "$TAG" 2>&1)
RELEASE_VIEW_STATUS=$?
set -e
if [ "$RELEASE_VIEW_STATUS" -eq 0 ]; then
echo "Release $TAG already exists; updating asset."
gh release upload "$TAG" "$ASSET" --clobber
elif printf '%s\n' "$RELEASE_VIEW_OUTPUT" | grep -Eqi '404|release not found'; then
echo "Creating release $TAG."
gh release create "$TAG" \
--title "$TAG" \
--generate-notes \
"$ASSET"
else
echo "Failed to query release $TAG with gh:" >&2
printf '%s\n' "$RELEASE_VIEW_OUTPUT" >&2
exit "$RELEASE_VIEW_STATUS"
fi