Skip to content

Release desktop

Release desktop #12

Workflow file for this run

name: Release desktop
on:
push:
tags:
- '[0-9]*.*.*'
workflow_dispatch:
concurrency:
group: release-desktop-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: write
jobs:
# One draft per tag. macOS and Windows only upload files to this release.
prepare-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Create a single draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if release_json="$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${TAG_NAME}" 2>/dev/null)"; then
release_id="$(printf '%s' "$release_json" | jq -r .id)"
is_draft="$(printf '%s' "$release_json" | jq -r .draft)"
if [ "$is_draft" = "true" ]; then
echo "Draft ${release_id} already exists for ${TAG_NAME}."
exit 0
fi
echo "Published release ${release_id} cannot accept more files. Deleting it (tag stays)."
gh api -X DELETE "repos/${GITHUB_REPOSITORY}/releases/${release_id}"
fi
gh api --method POST "repos/${GITHUB_REPOSITORY}/releases" \
-f tag_name="${TAG_NAME}" \
-f name="Dagr ${TAG_NAME}" \
-f body="Desktop installers for ${TAG_NAME}." \
-F draft=true
echo "Created draft for ${TAG_NAME}."
package:
needs: prepare-release
if: always() && (needs.prepare-release.result == 'success' || needs.prepare-release.result == 'skipped')
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up pnpm
uses: pnpm/action-setup@v6
with:
version: 10
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 20
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- name: Require version tag
if: github.event_name != 'workflow_dispatch'
shell: bash
env:
TAG_NAME: ${{ github.ref_name }}
run: |
# SemVer 2.0.0 without a v prefix: 1.2.3, 1.2.3-alpha.1, 1.2.3-rc.1+build.5
semver='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
if [[ ! "$TAG_NAME" =~ $semver ]]; then
echo "Tag must be SemVer 2.0.0 without a v prefix (for example 1.2.3, 1.2.3-alpha.1, 1.2.3-rc.1+build.5)."
exit 1
fi
- name: Set version from tag
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
TAG_NAME: ${{ github.ref_name }}
run: |
node -e '
const fs = require("fs")
const version = process.env.TAG_NAME.replace(/^v/i, "")
const path = "package.json"
const pkg = JSON.parse(fs.readFileSync(path, "utf8"))
pkg.version = version
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n")
'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Package
env:
CSC_IDENTITY_AUTO_DISCOVERY: 'false'
run: |
pnpm build
pnpm exec electron-builder --publish never
- name: Upload to the draft release
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
version="${TAG_NAME#v}"
out="release/${version}"
shopt -s nullglob
files=(
"${out}/Dagr_${version}.dmg"
"${out}/Dagr_${version}.zip"
"${out}/Dagr_${version}.exe"
"${out}/Dagr_${version}.dmg.blockmap"
"${out}/Dagr_${version}.zip.blockmap"
"${out}/Dagr_${version}.exe.blockmap"
"${out}/latest-mac.yml"
"${out}/latest.yml"
)
existing=()
for file in "${files[@]}"; do
if [ -f "$file" ]; then
existing+=("$file")
fi
done
if [ "${#existing[@]}" -eq 0 ]; then
echo "No installer files found under ${out}."
ls -la "${out}" || true
exit 1
fi
gh release upload "${TAG_NAME}" "${existing[@]}" --clobber