feat(cli): tighten preflight, readiness checks, and concise errors #2
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: Package (${{ matrix.goos }}/${{ matrix.goarch }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - goos: windows | |
| goarch: amd64 | |
| asset_name: hackctl_windows_amd64.zip | |
| - goos: darwin | |
| goarch: amd64 | |
| asset_name: hackctl_darwin_amd64.tar.gz | |
| - goos: darwin | |
| goarch: arm64 | |
| asset_name: hackctl_darwin_arm64.tar.gz | |
| - goos: linux | |
| goarch: amd64 | |
| asset_name: hackctl_linux_amd64.tar.gz | |
| - goos: linux | |
| goarch: arm64 | |
| asset_name: hackctl_linux_arm64.tar.gz | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Build metadata | |
| id: meta | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| echo "version=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" | |
| echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" | |
| - name: Build binary | |
| shell: bash | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| CGO_ENABLED: 0 | |
| VERSION: ${{ steps.meta.outputs.version }} | |
| COMMIT: ${{ github.sha }} | |
| BUILD_DATE: ${{ steps.meta.outputs.build_date }} | |
| run: | | |
| set -euo pipefail | |
| mkdir -p build | |
| binary_name="hackctl" | |
| if [ "$GOOS" = "windows" ]; then | |
| binary_name="hackctl.exe" | |
| fi | |
| ldflags="-s -w" | |
| ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Version=${VERSION}" | |
| ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Commit=${COMMIT}" | |
| ldflags+=" -X github.com/hackctl/hackctl/cli/internal/buildinfo.Date=${BUILD_DATE}" | |
| go build -trimpath -ldflags "$ldflags" -o "build/${binary_name}" ./cmd/hackctl | |
| - name: Package archive | |
| shell: bash | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| ASSET_NAME: ${{ matrix.asset_name }} | |
| run: | | |
| set -euo pipefail | |
| rm -rf package dist | |
| mkdir -p package dist | |
| if [ "$GOOS" = "windows" ]; then | |
| cp build/hackctl.exe package/hackctl.exe | |
| ( | |
| cd package | |
| zip -q "../dist/${ASSET_NAME}" hackctl.exe | |
| ) | |
| else | |
| cp build/hackctl package/hackctl | |
| chmod +x package/hackctl | |
| ( | |
| cd package | |
| tar -czf "../dist/${ASSET_NAME}" hackctl | |
| ) | |
| fi | |
| - name: Upload packaged artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: dist/${{ matrix.asset_name }} | |
| if-no-files-found: error | |
| release: | |
| name: Create GitHub release | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download packaged artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Generate checksums | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| cd dist | |
| sha256sum * > checksums.txt | |
| - name: Publish release assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: dist/* | |
| generate_release_notes: true | |
| prerelease: ${{ contains(github.ref_name, '-') }} |