.github/workflows/auto-release.yml

name: Auto release

# Every push to main builds the next patch from that commit, then tags and
# publishes it after all installer jobs pass. Minor and major releases stay manual.
on:
  push:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: auto-release
  cancel-in-progress: false

jobs:
  version:
    if: "!startsWith(github.event.head_commit.message, 'Release ')"
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
          ref: ${{ github.sha }}
          persist-credentials: false
      - uses: actions/setup-node@v5
        with:
          node-version: 24
      - id: version
        run: |
          VERSION="$(node scripts/release-version.mjs)"
          echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"

  build:
    needs: version
    uses: ./.github/workflows/ci.yml
    with:
      ref: ${{ github.sha }}
      release_version: ${{ needs.version.outputs.version }}

  publish:
    needs: [version, build]
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v5
        with:
          ref: ${{ github.sha }}
          fetch-depth: 0
      - uses: actions/download-artifact@v5
        with:
          pattern: installer-*
          path: release
          merge-multiple: true
      - name: Create release checksums
        working-directory: release
        run: sha256sum *.exe *.dmg *.AppImage latest.yml latest-linux.yml > SHA256SUMS.txt
      - name: Create the release tag
        env:
          RELEASE_VERSION: ${{ needs.version.outputs.version }}
        run: |
          TAG="v${RELEASE_VERSION}"
          if git show-ref --verify --quiet "refs/tags/${TAG}"; then
            test "$(git rev-parse "${TAG}^{commit}")" = "${GITHUB_SHA}"
          else
            git tag "${TAG}" "${GITHUB_SHA}"
            git push origin "refs/tags/${TAG}"
          fi
      - name: Publish the release
        working-directory: release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release create "v${{ needs.version.outputs.version }}" \
            *.exe *.dmg *.AppImage latest.yml latest-linux.yml SHA256SUMS.txt \
            --repo "${GITHUB_REPOSITORY}" --verify-tag \
            --title "v${{ needs.version.outputs.version }}" \
            --generate-notes