name: goreleaser

on:
  push:
    tags:
      - 'v2.*'

permissions:
  contents: write

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: 'stable'
          check-latest: true

      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # Cloudsmith CLI tooling for pushing releases
      # See https://help.cloudsmith.io/docs/cli
      - name: Install Cloudsmith CLI
        run: pip install --upgrade cloudsmith-cli


      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v6
        with:
          distribution: goreleaser
          version: 'latest'
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}


      # Publish to the "stable" repo on Cloudsmith
      # See https://cloudsmith.io/~html-to-markdown/repos/stable/
      - name: Publish .deb to Cloudsmith
        env:
          CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
        run: |
          for filename in dist/*.deb; do
            # armv6 and armv7 are both "armhf" so we can skip the duplicate
            if [[ "$filename" == *"armv6"* ]]; then
              echo "Skipping $filename"
              continue
            fi

            echo "Pushing $filename to 'stable'"
            cloudsmith push deb html-to-markdown/stable/any-distro/any-version $filename
          done
