Auto Release #59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Release | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - README.md | |
| - .github/** | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Tag to release (e.g. v0.4.0). Blank = auto-bump patch.' | |
| required: false | |
| default: '' | |
| release_name: | |
| description: 'Release title override. Blank = tag name.' | |
| required: false | |
| default: '' | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.bump.outputs.tag }} | |
| ver: ${{ steps.bump.outputs.ver }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve version | |
| id: bump | |
| env: | |
| INPUT_VERSION: ${{ inputs.version }} | |
| run: | | |
| if [ -n "$INPUT_VERSION" ]; then | |
| tag="$INPUT_VERSION" | |
| ver="${tag#v}" | |
| else | |
| latest=$(git tag -l 'v*' --sort=-v:refname | head -n1) | |
| if [ -z "$latest" ]; then | |
| tag="v0.1.1" | |
| ver="0.1.1" | |
| else | |
| IFS='.' read -r major minor patch <<< "${latest#v}" | |
| patch=$((patch + 1)) | |
| tag="v${major}.${minor}.${patch}" | |
| ver="${major}.${minor}.${patch}" | |
| fi | |
| fi | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| echo "ver=$ver" >> "$GITHUB_OUTPUT" | |
| - name: Push tag | |
| run: | | |
| git tag "${{ steps.bump.outputs.tag }}" | |
| git push origin "${{ steps.bump.outputs.tag }}" | |
| build: | |
| needs: version | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - { goos: darwin, goarch: amd64 } | |
| - { goos: darwin, goarch: arm64 } | |
| - { goos: linux, goarch: amd64 } | |
| - { goos: linux, goarch: arm64 } | |
| - { goos: windows, goarch: amd64 } | |
| - { goos: windows, goarch: arm64 } | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Install NSIS | |
| if: matrix.goos == 'windows' | |
| run: | | |
| sudo apt-get update -q && sudo apt-get install -y --no-install-recommends nsis | |
| curl -fsSL https://github.com/GsNSIS/EnVar/releases/download/v0.3.1/EnVar-Plugin.zip -o /tmp/envar.zip | |
| sudo unzip -o /tmp/envar.zip "Plugins/*" -d /usr/share/nsis/ | |
| - name: Build binary | |
| run: | | |
| ext="" | |
| [ "${{ matrix.goos }}" = "windows" ] && ext=".exe" | |
| out="./bin/${{ matrix.goos }}-${{ matrix.goarch }}/gpk${ext}" | |
| mkdir -p "$(dirname "$out")" | |
| GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \ | |
| -ldflags "-s -w -X main.version=${{ needs.version.outputs.tag }}" \ | |
| -o "$out" \ | |
| ./cmd/gpk | |
| - name: Build Windows installer | |
| if: matrix.goos == 'windows' | |
| env: | |
| TAG: ${{ needs.version.outputs.tag }} | |
| ARCH: ${{ matrix.goarch }} | |
| run: | | |
| envsubst '$TAG $ARCH' < .github/templates/gpk.nsi > gpk.nsi | |
| makensis gpk.nsi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: gpk-${{ matrix.goos }}-${{ matrix.goarch }} | |
| if-no-files-found: error | |
| path: | | |
| ./bin/${{ matrix.goos }}-${{ matrix.goarch }}/gpk* | |
| gpk-*-setup.exe | |
| release: | |
| needs: [version, build] | |
| runs-on: ubuntu-latest | |
| env: | |
| TAG: ${{ needs.version.outputs.tag }} | |
| VER: ${{ needs.version.outputs.ver }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download all build artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| path: ./artifacts | |
| - name: Stage release assets | |
| run: | | |
| mkdir -p ./dist | |
| for platform in darwin-amd64 darwin-arm64 linux-amd64 linux-arm64; do | |
| cp "./artifacts/gpk-${platform}/bin/${platform}/gpk" "./dist/gpk-${platform}" | |
| chmod +x "./dist/gpk-${platform}" | |
| done | |
| for arch in amd64 arm64; do | |
| cp "./artifacts/gpk-windows-${arch}/bin/windows-${arch}/gpk.exe" "./dist/gpk-windows-${arch}.exe" | |
| setup="./artifacts/gpk-windows-${arch}/gpk-${TAG}-${arch}-setup.exe" | |
| [ -f "$setup" ] && cp "$setup" ./dist/ | |
| done | |
| (cd ./dist && sha256sum * > checksums.txt) | |
| ls -lh ./dist | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.TAG }} | |
| name: ${{ inputs.release_name != '' && inputs.release_name || env.TAG }} | |
| generate_release_notes: true | |
| files: ./dist/* | |
| - name: Generate AUR PKGBUILD | |
| run: | | |
| export SHA_AMD64=$(sha256sum ./dist/gpk-linux-amd64 | awk '{print $1}') | |
| export SHA_ARM64=$(sha256sum ./dist/gpk-linux-arm64 | awk '{print $1}') | |
| envsubst '$TAG $VER $SHA_AMD64 $SHA_ARM64' < .github/templates/PKGBUILD > PKGBUILD | |
| - name: Publish to AUR | |
| uses: KSXGitHub/github-actions-deploy-aur@v4.1.2 | |
| with: | |
| pkgname: gpk-bin | |
| pkgbuild: ./PKGBUILD | |
| commit_username: neur0map | |
| commit_email: 90535780+neur0map@users.noreply.github.com | |
| ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
| commit_message: "Update to ${{ env.TAG }}" | |
| force_push: true | |
| - name: Update Homebrew tap | |
| env: | |
| HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| run: | | |
| export SHA_DARWIN_AMD64=$(sha256sum ./dist/gpk-darwin-amd64 | awk '{print $1}') | |
| export SHA_DARWIN_ARM64=$(sha256sum ./dist/gpk-darwin-arm64 | awk '{print $1}') | |
| export SHA_LINUX_AMD64=$(sha256sum ./dist/gpk-linux-amd64 | awk '{print $1}') | |
| export SHA_LINUX_ARM64=$(sha256sum ./dist/gpk-linux-arm64 | awk '{print $1}') | |
| envsubst '$VER $TAG $SHA_DARWIN_AMD64 $SHA_DARWIN_ARM64 $SHA_LINUX_AMD64 $SHA_LINUX_ARM64' < .github/templates/gpk.rb > gpk.rb | |
| git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/neur0map/homebrew-tap.git" tap | |
| mkdir -p tap/Formula | |
| cp gpk.rb tap/Formula/gpk.rb | |
| cd tap | |
| git config user.name "neur0map" | |
| git config user.email "90535780+neur0map@users.noreply.github.com" | |
| git add Formula/gpk.rb | |
| git commit -m "gpk ${VER}" | |
| git push |