name: Release Please

on:
    # Keep the release PR current after main changes. The stable Velopack build below
    # only runs when release-please actually creates a GitHub release.
    push:
        branches:
            - main

permissions:
    contents: read

concurrency:
    group: ${{ github.workflow }}-${{ github.ref }}
    cancel-in-progress: true

jobs:
    release-please:
        name: Release Please
        runs-on: ubuntu-latest
        permissions:
            contents: write
            issues: write
            pull-requests: write
        outputs:
            release_created: ${{ steps.release.outputs['apps/desktop--release_created'] }}
            version: ${{ steps.release.outputs['apps/desktop--version'] }}
            tag_name: ${{ steps.release.outputs['apps/desktop--tag_name'] }}
            sha: ${{ steps.release.outputs['apps/desktop--sha'] }}
        steps:
            - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
              with:
                  persist-credentials: false

            - uses: googleapis/release-please-action@5c625bfb5d1ff62eadeeb3772007f7f66fdcf071 # v4
              id: release
              with:
                  token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }}
                  config-file: release-please-config.json
                  manifest-file: .release-please-manifest.json

    publish-release:
        name: Publish stable release
        needs: release-please
        if: ${{ needs.release-please.outputs.release_created == 'true' }}
        permissions:
            contents: write
            deployments: write
        uses: ./.github/workflows/velopack-build.yml
        with:
            channel: stable
            version: ${{ needs.release-please.outputs.version }}
            tag: ${{ needs.release-please.outputs.tag_name }}
            prerelease: 'False'
            target-commitish: ${{ needs.release-please.outputs.sha }}
            deploy-production: true
        secrets: inherit
