Skip to content

Commit 5e2328d

Browse files
feat: add automated release workflow with binary artifacts (#25)
1 parent 12db223 commit 5e2328d

File tree

4 files changed

+165
-3
lines changed

4 files changed

+165
-3
lines changed

.github/workflows/release.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install mise
22+
uses: jdx/mise-action@v2
23+
24+
- name: Setup Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: "go.mod"
28+
cache: true
29+
30+
- name: Run tests
31+
run: mise run test
32+
33+
- name: Run GoReleaser
34+
uses: goreleaser/goreleaser-action@v6
35+
with:
36+
distribution: goreleaser
37+
version: "~> v2"
38+
args: release --clean
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Upload artifacts
43+
uses: actions/upload-artifact@v4
44+
if: always()
45+
with:
46+
name: release-artifacts
47+
path: |
48+
dist/
49+
!dist/*.txt
50+
retention-days: 30

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ coverage.html
44

55
# VSCode settings (user-specific)
66
.vscode/*
7-
!.vscode/settings.example.json
7+
!.vscode/settings.example.json
8+
# Added by goreleaser init:
9+
dist/

.goreleaser.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 2
10+
11+
before:
12+
hooks:
13+
# You may remove this if you don't use go modules.
14+
- go mod tidy
15+
16+
builds:
17+
- id: openapi-cli
18+
main: ./cmd/openapi
19+
binary: openapi
20+
env:
21+
- CGO_ENABLED=0
22+
goos:
23+
- linux
24+
- windows
25+
- darwin
26+
goarch:
27+
- amd64
28+
- arm64
29+
ldflags:
30+
- -s -w
31+
- -X main.version={{.Version}}
32+
- -X main.commit={{.Commit}}
33+
- -X main.date={{.Date}}
34+
35+
archives:
36+
- id: openapi-cli
37+
formats: [tar.gz]
38+
# this name template makes the OS and Arch compatible with the results of `uname`.
39+
name_template: >-
40+
{{ .ProjectName }}_
41+
{{- title .Os }}_
42+
{{- if eq .Arch "amd64" }}x86_64
43+
{{- else if eq .Arch "386" }}i386
44+
{{- else }}{{ .Arch }}{{ end }}
45+
{{- if .Arm }}v{{ .Arm }}{{ end }}
46+
# use zip for windows archives
47+
format_overrides:
48+
- goos: windows
49+
formats: [zip]
50+
files:
51+
- README.md
52+
- LICENSE*
53+
54+
changelog:
55+
sort: asc
56+
filters:
57+
exclude:
58+
- "^docs:"
59+
- "^test:"
60+
- "^chore:"
61+
- "^ci:"
62+
groups:
63+
- title: Features
64+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
65+
order: 0
66+
- title: Bug fixes
67+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
68+
order: 1
69+
- title: Others
70+
order: 999
71+
72+
release:
73+
github:
74+
owner: speakeasy-api
75+
name: openapi
76+
draft: false
77+
prerelease: auto
78+
mode: replace
79+
header: |
80+
## OpenAPI CLI {{ .Tag }}
81+
82+
This release includes binaries for Linux, macOS, and Windows on both x86_64 and ARM64 architectures.
83+
84+
### Installation
85+
86+
Download the appropriate binary for your platform from the assets below, extract it, and add it to your PATH.
87+
88+
### Changes
89+
footer: |
90+
91+
---
92+
93+
**Full Changelog**: https://github.com/speakeasy-api/openapi/compare/{{ .PreviousTag }}...{{ .Tag }}
94+
95+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
96+
97+
# Generate checksums for all artifacts
98+
checksum:
99+
name_template: "checksums.txt"
100+
# Generate Software Bill of Materials (SBOM)
101+
sboms:
102+
- artifacts: archive

cmd/openapi/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
var (
1414
version = "dev"
15+
commit = "none"
16+
date = "unknown"
1517
)
1618

1719
var rootCmd = &cobra.Command{
@@ -72,8 +74,14 @@ These commands help you validate and work with Arazzo documents.`,
7274
}
7375

7476
func init() {
75-
// Set version template
76-
rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}`)
77+
// Set version template with build info
78+
if commit != "none" && date != "unknown" {
79+
rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}
80+
Build: ` + commit + `
81+
Built: ` + date)
82+
} else {
83+
rootCmd.SetVersionTemplate(`{{printf "%s" .Version}}`)
84+
}
7785

7886
// Add OpenAPI spec validation command
7987
openapiCmd.Apply(openapiCmds)

0 commit comments

Comments
 (0)