Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 15 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading