name: GoFrame Release

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
    - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

env:
  TZ: Asia/Shanghai


jobs:
  build:
    name: Build And Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Github Code
        uses: actions/checkout@v4
      
      - name: Set Up Golang Environment
        uses: actions/setup-go@v5
        with:
          go-version: 1.23.4
      
      - name: Build CLI Binary
        run: |
          echo "Building linux amd64 binary..."
          cd cmd/gf
          GOOS=linux GOARCH=amd64 go build main.go
          chmod +x main
          ./main install -y

      - name: Build CLI Binary For All Platform
        run: |
          cd cmd/gf
          gf build main.go -n gf -a all -s all -p temp

      - name: Move Files Before Release
        run: |
          cd cmd/gf/temp
          for OS in *;do for FILE in $OS/*;\
          do if [[ ${OS} =~ 'windows' ]];\
          then mv $FILE gf_$OS.exe && rm -rf $OS;\
          else mv $FILE gf_$OS && rm -rf $OS;\
          fi;done;done

      - name: Create Github Release
        id: create_release
        uses: softprops/action-gh-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name:     ${{ github.ref }}
          name: GoFrame Release ${{ github.ref }}
          draft:        false
          prerelease:   false
      
      - name: Upload Release Asset
        id:   upload-release-asset
        uses: alexellis/upload-assets@0.4.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          asset_paths: '["cmd/gf/temp/gf_*"]'
