# Continuous integration handling for GoReleaser
name: GoReleaser CI

on:
  push:
    branches:
      - main
      - 'release/**'
  pull_request:
    paths:
      - .github/workflows/goreleaser-ci.yml
      - .goreleaser.yml
      - go.sum
      - main.go
      - internal/**
      - names/**
      - skaff/**
      - tools/**

jobs:
  changes:
    runs-on: ubuntu-latest
    outputs:
      goreleaser: ${{ steps.filter.outputs.goreleaser }}
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
        id: filter
        with:
          filters: |
            goreleaser:
              - '.github/workflows/goreleaser-ci.yml'
              - '.goreleaser.yml'

  check:
    needs: changes
    if: ${{ needs.changes.outputs.goreleaser == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
        with:
          go-version-file: go.mod
      - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
        continue-on-error: true
        timeout-minutes: 2
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
      - name: goreleaser check
        uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
        with:
          args: check

  build-32-bit:
    # Run a single compiler check for 32-bit architecture (FreeBSD/ARM)
    # Ref: https://github.com/hashicorp/terraform-provider-aws/issues/8988
    runs-on: [custom, linux, small]
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
        with:
          go-version-file: go.mod
      - uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
        continue-on-error: true
        timeout-minutes: 2
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
      - name: goreleaser build
        uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
        with:
          args: build --config .github/goreleaser-cross-compiler-test.yml --id 32-bit-arch --snapshot