name: Release upload
"on":
  release:
    types:
    - published

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v4
    - name: Install Go
      if: success()
      uses: actions/setup-go@v4
      with:
        go-version: "1.21"
    - name: Set environment variables
      shell: bash
      run: |
        echo "GOPATH=${{ runner.workspace }}" >> $GITHUB_ENV
        echo "${{ runner.workspace }}/bin" >> $GITHUB_PATH
    - name: Setup XGO
      run: go install github.com/crazy-max/xgo@latest
    - name: Run dist
      run: make dist
    - name: Upload Asset to Release with a wildcard
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: dist/*.zip
    - name: update homebrew
      run: |
        bash .github/update-homebrew-tap.sh
    - name: Pushes homebrew-tap
      uses: dmnemec/copy_file_to_another_repo_action@main
      env:
        API_TOKEN_GITHUB: ${{ secrets.TAP_GITHUB_TOKEN }}
      with:
        source_file: '.github/trdsql.rb'
        destination_repo: 'noborus/homebrew-tap'
        destination_branch: 'master'
        user_email: 'noborusai@gmail.com'
        user_name: 'Noboru Saito'
        commit_message: 'Brew formula update for trdsql'
  