name: mac-main-release

concurrency:
  group: mac-main-release
  cancel-in-progress: true

on:
  push:
    branches:
    - main

jobs:
  release:
    runs-on: [self-hosted, macOS]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: "1.19"
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v2
      - name: Set up Keychain
        id: keychain
        uses: acorn-io/actions-setup-keychain@v1
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Install Cosign
        uses: sigstore/cosign-installer@main
        with:
          cosign-release: "v1.4.1"
      - name: Setup Cosign
        run: |
          echo "${COSIGN_KEY}" > "$GITHUB_WORKSPACE/cosign.key"
        env:
          COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
      - run: make validate-ci
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v4
        with:
          distribution: goreleaser
          version: latest
          args: release --rm-dist --snapshot
        env:
          NOTARIZE: "0"
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_PROJECT_TOKEN: ${{ secrets.GH_PROJECT_TOKEN }}
          COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
          AC_IDENTITY: ${{ secrets.AC_IDENTITY }}
          AC_PROJECT: ${{ secrets.AC_PROJECT }}
          AC_USERNAME: ${{ secrets.AC_USERNAME }}
          AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
          AC_P12: ${{ secrets.AC_P12 }}
          AC_P12_PASSWORD: ${{ secrets.AC_P12_PASSWORD }}
          KEYCHAIN: ${{ steps.keychain.outputs['keychain-name'] }}
          ACORN_DNS_ENDPOINT: https://alpha-dns.acrn.io/v1
      - name: report failure to slack
        if: failure()
        id: slack-failure
        uses: slackapi/slack-github-action@v1.23.0
        with:
          channel-id: '${{ secrets.SLACK_BOT_FAILURE_CHANNEL }}'
          slack-message: "❌ Main-Mac-Release failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
