# SPDX-FileCopyrightText: 2024 Shun Sakai
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

name: CD

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  release:
    name: Release
    runs-on: ubuntu-24.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - name: Setup Go environment
        uses: actions/setup-go@v5
        with:
          go-version: "stable"
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.3
      - name: Install Asciidoctor
        run: |
          gem install asciidoctor
          asciidoctor -V
      - name: Check `.goreleaser.yaml`
        uses: goreleaser/goreleaser-action@v6.4.0
        with:
          distribution: "goreleaser"
          version: "latest"
          args: check
      - name: Check GoReleaser
        uses: goreleaser/goreleaser-action@v6.4.0
        if: ${{ !startsWith(github.ref, 'refs/tags/') }}
        with:
          distribution: "goreleaser"
          version: "latest"
          args: release --clean --snapshot
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v6.4.0
        if: startsWith(github.ref, 'refs/tags/')
        with:
          distribution: "goreleaser"
          version: "latest"
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
