name: Release
on:
  push:
    tags:
      - "v*.*.*"

jobs:
  binaries:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
      attestations: write
    steps:
      - uses: actions/checkout@v6
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.3'
      - run: gem install ronn
      - run: ronn ./man/actionlint.1.ronn
      - uses: actions/setup-go@v6
        with:
          go-version: '1.26'
          check-latest: true
      - name: Get version
        run: echo VERSION="${GITHUB_REF#refs/tags/v}" >> "$GITHUB_ENV"
      - uses: goreleaser/goreleaser-action@v7
        with:
          version: '~> v2'
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/attest-build-provenance@v4
        with:
          subject-checksums: ${{ format('./dist/actionlint_{0}_checksums.txt', env.VERSION) }}
      - name: Post-release download check
        run: bash ./scripts/download-actionlint.bash "$VERSION"
      - name: Clone nested repository to make version bump commit
        uses: actions/checkout@v6
        with:
          path: ./tmp-actionlint-for-update-ver
          ref: main
          fetch-depth: 0
      - name: Update version in download script
        run: |
          set -x
          cd ./tmp-actionlint-for-update-ver
          sed -i -E "s/version=\"[0-9]+\\.[0-9]+\\.[0-9]+\"/version=\"${VERSION}\"/" ./scripts/download-actionlint.bash
          git diff
          git add ./scripts/download-actionlint.bash
          git -c user.email='41898282+github-actions[bot]@users.noreply.github.com' -c user.name='github-actions[bot]' commit -m "update version to $VERSION in download-actionlint.bash"
          git log -n 1
          git push
  winget:
    runs-on: ubuntu-latest
    needs: binaries
    steps:
      - uses: vedantmgoyal9/winget-releaser@main
        with:
          identifier: rhysd.actionlint
          installers-regex: '_windows_\w+\.zip$'
          release-notes-url: 'https://github.com/rhysd/actionlint/blob/main/CHANGELOG.md#${{ github.ref_name }}'
          token: ${{ secrets.WINGET_TOKEN }}
  docker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - name: Get tag name
        id: tag
        run: |
          echo "name=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v4
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v4
      - name: Login to DockerHub
        uses: docker/login-action@v4
        with:
          username: rhysd
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@v7
        with:
          platforms: linux/amd64,linux/arm64
          build-args: |
            GOLANG_VER=1.26
            ACTIONLINT_VER=${{ steps.tag.outputs.name }}
          push: true
          tags: |
            rhysd/actionlint:${{ steps.tag.outputs.name }}
            rhysd/actionlint:latest
