---

if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: [test]

defaults:
  run:
    shell: bash

container:
  image: luzifer/gh-arch-env
  env:
    CGO_ENABLED: 0
    GOPATH: /go

permissions:
  contents: write

runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v4
    with:
      show-progress: false

  - name: Marking workdir safe
    run: |
      git config --global --add safe.directory /__w/twitch-bot/twitch-bot

  - name: Build release
    run: make publish

  - name: Extract changelog
    run: 'awk "/^#/ && ++c==2{exit}; /^#/f" "History.md" | tail -n +2 >release_changelog.md'

  - name: Update stable branch
    run: |
      git branch -f stable ${GITHUB_SHA}
      git push -f origin stable

  - name: Release
    uses: ncipollo/release-action@v1
    with:
      artifacts: '.build/*'
      bodyFile: release_changelog.md
      draft: false
      generateReleaseNotes: false

...