diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..f80997e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,50 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Install mise + uses: jdx/mise-action@v2 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache: true + + - name: Run tests + run: mise run test + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: release-artifacts + path: | + dist/ + !dist/*.txt + retention-days: 30 diff --git a/.gitignore b/.gitignore index 2ee5157..afeb483 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ coverage.html # VSCode settings (user-specific) .vscode/* -!.vscode/settings.example.json \ No newline at end of file +!.vscode/settings.example.json +# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d6f8535 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,102 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +builds: + - id: openapi-cli + main: ./cmd/openapi + binary: openapi + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X main.commit={{.Commit}} + - -X main.date={{.Date}} + +archives: + - id: openapi-cli + formats: [tar.gz] + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + formats: [zip] + files: + - README.md + - LICENSE* + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + - "^chore:" + - "^ci:" + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: Bug fixes + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: Others + order: 999 + +release: + github: + owner: speakeasy-api + name: openapi + draft: false + prerelease: auto + mode: replace + header: | + ## OpenAPI CLI {{ .Tag }} + + This release includes binaries for Linux, macOS, and Windows on both x86_64 and ARM64 architectures. + + ### Installation + + Download the appropriate binary for your platform from the assets below, extract it, and add it to your PATH. + + ### Changes + footer: | + + --- + + **Full Changelog**: https://github.com/speakeasy-api/openapi/compare/{{ .PreviousTag }}...{{ .Tag }} + + Released by [GoReleaser](https://github.com/goreleaser/goreleaser). + +# Generate checksums for all artifacts +checksum: + name_template: "checksums.txt" +# Generate Software Bill of Materials (SBOM) +sboms: + - artifacts: archive diff --git a/cmd/openapi/main.go b/cmd/openapi/main.go index ef9ba8f..c47dd02 100644 --- a/cmd/openapi/main.go +++ b/cmd/openapi/main.go @@ -12,6 +12,8 @@ import ( var ( version = "dev" + commit = "none" + date = "unknown" ) var rootCmd = &cobra.Command{ @@ -72,8 +74,14 @@ These commands help you validate and work with Arazzo documents.`, } func init() { - // Set version template - rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}`) + // Set version template with build info + if commit != "none" && date != "unknown" { + rootCmd.SetVersionTemplate(`{{printf "%s" .Version}} +Build: ` + commit + ` +Built: ` + date) + } else { + rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}`) + } // Add OpenAPI spec validation command openapiCmd.Apply(openapiCmds)