diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 488403a..e047cd6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,3 @@ -# .github/workflows/release.yml name: Build & Release Go Binary on: @@ -11,40 +10,84 @@ permissions: packages: write jobs: - release: + prepare_release: + name: Prepare release (create tag + release) + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.set_tag.outputs.TAG }} + steps: + - name: Checkout (full history required for tagging) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set TAG + id: set_tag + run: | + TAG="v$(date +'%Y%m%d%H%M%S')" + echo "TAG=${TAG}" >> $GITHUB_OUTPUT + + - name: Configure git user + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Create and push tag + run: | + git tag ${{ steps.set_tag.outputs.TAG }} + git push origin ${{ steps.set_tag.outputs.TAG }} + + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.set_tag.outputs.TAG }} + name: ${{ steps.set_tag.outputs.TAG }} + token: ${{ secrets.GITHUB_TOKEN }} + + build_and_upload: + name: Build and upload artifacts + needs: prepare_release runs-on: ubuntu-latest strategy: matrix: goos: [linux, windows, darwin] - goarch: ['386', amd64, arm64] + goarch: [amd64, arm64] exclude: - goos: darwin goarch: '386' - goos: windows goarch: arm64 steps: - - uses: actions/checkout@v4 - - name: Set version tag - id: version - run: | - VERSION="v$(date +'%Y%m%d%H%M%S')" - echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Build Go Binary - uses: wangyoucao577/go-release-action@v1 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - goversion: "https://dl.google.com/go/go1.24.8.linux-amd64.tar.gz" - project_path: "./" - binary_name: "pinata" - extra_files: LICENSE README.md - - name: Create Git Tag + go-version: '1.24.8' + + - name: Build binary run: | - git tag ${{ env.VERSION }} - git push origin ${{ env.VERSION }} - - name: Create GitHub Release - uses: ncipollo/release-action@v1 + set -e + EXT="" + if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi + OUT_DIR=build-artifacts + mkdir -p ${OUT_DIR} + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ + go build -o ${OUT_DIR}/pinata-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} ./cmd/pinata + + - name: Package artifact (tar/gzip) + if: matrix.goos == 'linux' + run: | + cd build-artifacts + tar -czf ../pinata-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz pinata-${{ matrix.goos }}-${{ matrix.goarch }} + ls -lh .. + + - name: Upload artifact to the Release + # softprops/action-gh-release will find the release by tag and upload files + uses: softprops/action-gh-release@v1 with: - tag: ${{ env.VERSION }} - token: ${{ secrets.GITHUB_TOKEN }} + files: | + build-artifacts/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}