on:
  push:
    branches:
      - v0*
name: Release
jobs:
  release-macos:
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install Go
        uses: actions/setup-go@v2
      - name: Import codesign
        uses: apple-actions/import-codesign-certs@v1
        with:
          p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
          p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
      - name: Install dependencies
        run: |
          brew install goreleaser
          brew install pkg-config
          brew install keys-pub/tap/libfido2
      - name: Build
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git config --global user.email "keys.pub"
          git config --global user.name "keys.pub"
          git tag -a ${GITHUB_REF##*/} -m ${GITHUB_REF##*/}
          cd service
          goreleaser
          cd ../auth/rpc/plugin
          goreleaser
  release-linux:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install Go
        uses: actions/setup-go@v2
      - name: Install dependencies (goreleaser)
        run: |
          export BINDIR=$HOME
          curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
      - name: Install dependencies (libfido2)
        run: |
          sudo apt install software-properties-common
          sudo apt-add-repository ppa:yubico/stable
          sudo apt update
          sudo apt install libfido2-dev
      - name: Build
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git config --global user.email "keys.pub"
          git config --global user.name "keys.pub"
          git tag -a ${GITHUB_REF##*/} -m ${GITHUB_REF##*/}
          cd service
          $HOME/goreleaser --config=.goreleaser.linux.yml
          cd ../auth/rpc/plugin
          $HOME/goreleaser --config=.goreleaser.linux.yml
