name: Publish release binaries

on:
  release:
    types:
      - published

jobs:
  publish:
    strategy:
      matrix:
        os: [ ubuntu-latest, macos-latest, windows-latest ]
    runs-on: ${{ matrix.os }}
    name: ${{ matrix.os }} - go${{ matrix.go }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: 'stable'
          check-latest: true
      - name: Run go build for amd64
        run: |
          go build -o gokey-amd64 ./cmd/gokey
        env:
          CGO_ENABLED: 0
      - name: Run go build for arm64
        run: |
          go build -o gokey-arm64 ./cmd/gokey
        env:
          CGO_ENABLED: 0
          GOARCH: arm64
      - name: Upload Linux binary
        if: runner.os == 'Linux'
        run: |
          ls
          mv gokey-amd64 gokey-${{ github.ref_name }}-linux-amd64
          mv gokey-arm64 gokey-${{ github.ref_name }}-linux-arm64
          gh release upload ${{ github.ref_name }} gokey-${{ github.ref_name }}-linux-amd64 gokey-${{ github.ref_name }}-linux-arm64
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Upload Windows binary
        if: runner.os == 'Windows'
        run: |
          mv gokey-amd64 gokey-${{ github.ref_name }}-windows-amd64.exe
          mv gokey-arm64 gokey-${{ github.ref_name }}-windows-arm64.exe
          gh release upload ${{ github.ref_name }} gokey-${{ github.ref_name }}-windows-amd64.exe gokey-${{ github.ref_name }}-windows-arm64.exe
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Upload MacOS binary
        if: runner.os == 'macOS'
        run: |
          mv gokey-amd64 gokey-${{ github.ref_name }}-darwin-amd64
          mv gokey-arm64 gokey-${{ github.ref_name }}-darwin-arm64
          gh release upload ${{ github.ref_name }} gokey-${{ github.ref_name }}-darwin-amd64 gokey-${{ github.ref_name }}-darwin-arm64
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
