From 2c5e089f0a5040eceba9f772ff12606b31525174 Mon Sep 17 00:00:00 2001 From: Michael McQuade Date: Tue, 20 Oct 2026 19:49:38 -0500 Subject: [PATCH] feat: releases ship prebuilt binaries, so CI can download the generator instead of compiling it When release-please creates a release, a follow-up job cross-compiles linux, darwin and windows on amd64 and arm64 and uploads tarballs plus checksums.txt to it. A cold `go tool` run spends nearly all its time compiling the generator and libopenapi; a download skips that. `--version` reports the release tag, or the module version for `go install` and `go tool` builds, so a pipeline can confirm which generator it ran. --- .github/workflows/release-please.yml | 51 ++++++++++++++++++++++++++++ cmd/root.go | 15 ++++++++ 2 files changed, 66 insertions(+) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 7d7037f..34dd0ef 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -21,3 +21,54 @@ jobs: pull-requests: write # open and update the release PR steps: - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 + id: release + + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + + # Prebuilt binaries let CI download the generator instead of compiling it + # and libopenapi with `go tool` on every cold run. + binaries: + needs: release-please + if: ${{ needs.release-please.outputs.release_created == 'true' }} + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: write # upload release assets + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ needs.release-please.outputs.tag_name }} + + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + cache: false + + - name: Build + env: + TAG: ${{ needs.release-please.outputs.tag_name }} + CGO_ENABLED: '0' + run: | + set -euo pipefail + mkdir dist + for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do + GOOS=${target%/*} GOARCH=${target#*/} + name="openapi-client-generator_${TAG#v}_${GOOS}_${GOARCH}" + ext=""; [ "$GOOS" = windows ] && ext=".exe" + mkdir "$name" + GOOS=$GOOS GOARCH=$GOARCH go build -trimpath \ + -ldflags "-s -w -X github.com/parallelworks/openapi-client-generator/cmd.version=${TAG}" \ + -o "$name/openapi-client-generator$ext" . + cp LICENSE README.md "$name/" + tar -czf "dist/$name.tar.gz" "$name" + done + (cd dist && sha256sum -- *.tar.gz > checksums.txt) + + - name: Upload + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ needs.release-please.outputs.tag_name }} + run: gh release upload "$TAG" dist/* --clobber --repo "$GITHUB_REPOSITORY" diff --git a/cmd/root.go b/cmd/root.go index 0f3cea0..cb66740 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,9 +1,24 @@ package cmd import ( + "runtime/debug" + "github.com/spf13/cobra" ) +// version is set by the release build; `go install` and `go tool` builds +// report their module version instead. +var version string + +func init() { + if version == "" { + if info, ok := debug.ReadBuildInfo(); ok { + version = info.Main.Version + } + } + rootCmd.Version = version +} + var rootCmd = &cobra.Command{ Use: "openapi-client-generator", Short: "Generate Go HTTP clients from OpenAPI 3.1 specs",