name: Snapshot

on: [push, pull_request]

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

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: "1.21.5"
      - name: Test
        run: go test ./...
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v4
        with:
          version: v1.14.1
          args: release --snapshot --rm-dist
      - name: Get name (push)
        if: github.event_name == 'push'
        run: |
          echo -n ${GITHUB_REF#refs/heads/} | tr / - > dist/NAME
          echo -n ${GITHUB_SHA} > dist/SHA
      - name: Get name (pull request)
        if: github.event_name == 'pull_request'
        run: |
          echo -n pr-${{ github.event.number }} > dist/NAME
          echo -n ${{ github.event.number }} > dist/PR
          echo -n ${{ github.event.pull_request.head.sha }} > dist/SHA
      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: dist
          path: dist/
