Skip to content

Commit d43dd52

Browse files
committed
feat: add gorelease to release binary
Signed-off-by: Abirdcfly <[email protected]>
1 parent 646060c commit d43dd52

File tree

5 files changed

+278
-3
lines changed

5 files changed

+278
-3
lines changed

.github/workflows/release.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- 'v*'
8+
9+
permissions:
10+
contents: write
11+
# packages: write
12+
# issues: write
13+
14+
jobs:
15+
goreleaser:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
- run: git fetch --force --tags
22+
- uses: actions/setup-go@v4
23+
with:
24+
go-version-file: "go.mod"
25+
# More assembly might be required: Docker logins, GPG, etc. It all depends
26+
# on your needs.
27+
- uses: goreleaser/goreleaser-action@v4
28+
with:
29+
# either 'goreleaser' (default) or 'goreleaser-pro':
30+
distribution: goreleaser
31+
version: latest
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
36+
# distribution:
37+
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
38+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,5 @@ Network Trash Folder
244244
Temporary Items
245245
.apdisk
246246

247+
248+
dist/

.goreleaser.yaml

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
#before:
4+
# hooks:
5+
# # You may remove this if you don't use go modules.
6+
# - go mod tidy
7+
# # you may remove this if you don't need go generate
8+
# - go generate ./...
9+
builds:
10+
- env:
11+
- CGO_ENABLED=0
12+
main: ./cmd/bc-cli/
13+
ldflags:
14+
- -s -w -X k8s.io/component-base/version.gitVersion={{.Version}} -X k8s.io/component-base/version.gitCommit={{.Commit}} -X k8s.io/component-base/version.buildDate={{.Date}}
15+
goos:
16+
- linux
17+
- windows
18+
- darwin
19+
20+
archives:
21+
- format: tar.gz
22+
# this name template makes the OS and Arch compatible with the results of uname.
23+
name_template: >-
24+
{{ .ProjectName }}_
25+
{{- title .Os }}_
26+
{{- if eq .Arch "amd64" }}x86_64
27+
{{- else if eq .Arch "386" }}i386
28+
{{- else }}{{ .Arch }}{{ end }}
29+
{{- if .Arm }}v{{ .Arm }}{{ end }}
30+
# use zip for windows archives
31+
format_overrides:
32+
- goos: windows
33+
format: zip
34+
checksum:
35+
name_template: 'checksums.txt'
36+
snapshot:
37+
name_template: "{{ incpatch .Version }}-next"
38+
changelog:
39+
# Sorts the changelog by the commit's messages.
40+
# Could either be asc, desc or empty
41+
sort: asc
42+
# Changelog generation implementation to use.
43+
#
44+
# Valid options are:
45+
# - `git`: uses `git log`;
46+
# - `github`: uses the compare GitHub API, appending the author login to the changelog.
47+
# - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog.
48+
# - `github-native`: uses the GitHub release notes generation API, disables the groups feature.
49+
#
50+
# Default: 'git'
51+
use: github
52+
# Group commits messages by given regex and title.
53+
# Order value defines the order of the groups.
54+
# Providing no regex means all commits will be grouped under the default group.
55+
# Groups are disabled when using github-native, as it already groups things by itself.
56+
# Matches are performed against strings of the form: "<abbrev-commit>[:] <title-commit>".
57+
# Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax.
58+
groups:
59+
- title: New Features
60+
regexp: "^.*feat[(\\w)]*:+.*$"
61+
order: 0
62+
- title: 'Bug Fixes'
63+
regexp: "^.*fix[(\\w)]*:+.*$"
64+
order: 1
65+
- title: Others
66+
order: 999
67+
filters:
68+
# Commit messages matching the regexp listed here will be removed from
69+
# the changelog
70+
exclude:
71+
- '^Merge pull request'
72+
release:
73+
# Repo in which the release will be created.
74+
# Default is extracted from the origin remote URL or empty if its private hosted.
75+
# github:
76+
# owner: user
77+
# name: repo
78+
79+
# IDs of the archives to use.
80+
# Empty means all IDs.
81+
#
82+
# Default: []
83+
# ids:
84+
# - foo
85+
# - bar
86+
87+
# If set to true, will not auto-publish the release.
88+
# Available only for GitHub and Gitea.
89+
#
90+
# Default: false
91+
draft: true
92+
93+
# Whether to remove existing draft releases with the same name before creating
94+
# a new one.
95+
# Only effective if `draft` is set to true.
96+
# Available only for GitHub.
97+
#
98+
# Default: false
99+
# Since: v1.11
100+
replace_existing_draft: false
101+
102+
# Useful if you want to delay the creation of the tag in the remote.
103+
# You can create the tag locally, but not push it, and run GoReleaser.
104+
# It'll then set the `target_commitish` portion of the GitHub release to the
105+
# value of this field.
106+
# Only works on GitHub.
107+
#
108+
# Default: ''
109+
# Since: v1.11
110+
# Templates: allowed
111+
# target_commitish: '{{ .Commit }}'
112+
113+
# This allows to change which tag GitHub will create.
114+
# Usually you'll use this together with `target_commitish`, or if you want to
115+
# publish a binary from a monorepo into a public repository somewhere, without
116+
# the tag prefix.
117+
#
118+
# Default: '{{ .PrefixedCurrentTag }}'
119+
# Since: v1.19 (pro)
120+
# Templates: allowed
121+
# tag: '{{ .CurrentTag }}'
122+
123+
# If set, will create a release discussion in the category specified.
124+
#
125+
# Warning: do not use categories in the 'Announcement' format.
126+
# Check https://github.com/goreleaser/goreleaser/issues/2304 for more info.
127+
#
128+
# Default is empty.
129+
# discussion_category_name: General
130+
131+
# If set to auto, will mark the release as not ready for production
132+
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
133+
# If set to true, will mark the release as not ready for production.
134+
# Default is false.
135+
# prerelease: auto
136+
137+
# What to do with the release notes in case there the release already exists.
138+
#
139+
# Valid options are:
140+
# - `keep-existing`: keep the existing notes
141+
# - `append`: append the current release notes to the existing notes
142+
# - `prepend`: prepend the current release notes to the existing notes
143+
# - `replace`: replace existing notes
144+
#
145+
# Default is `keep-existing`.
146+
mode: append
147+
148+
# Header for the release body.
149+
#
150+
# Templates: allowed
151+
header: |
152+
## {{.ProjectName}}-v{{.Version}}
153+
154+
Welcome to this new release!
155+
156+
### Breaking Changes:
157+
None
158+
# Footer for the release body.
159+
#
160+
# Templates: allowed
161+
footer: |
162+
## Thanks to our Contributors!
163+
164+
Thank you to everyone who contributed to {{.Tag}}! ❤️
165+
166+
And thank you very much to everyone else not listed here who contributed in other ways like filing issues, giving feedback, testing fixes, helping users in slack, etc. 🙏
167+
# You can change the name of the release.
168+
#
169+
# Default: '{{.Tag}}' ('{{.PrefixedTag}}' on Pro)
170+
# Templates: allowed
171+
name_template: "v{{.Version}}"
172+
173+
# You can disable this pipe in order to not create the release on any SCM.
174+
# Keep in mind that this might also break things that depend on the release
175+
# URL, for instance, homebrew taps.
176+
#
177+
# Templates: allowed (since v1.15)
178+
# disable: true
179+
180+
# Set this to true if you want to disable just the artifact upload to the SCM.
181+
# If this is true, GoReleaser will still create the release with the
182+
# changelog, but won't upload anything to it.
183+
#
184+
# Since: v1.11
185+
# Templates: allowed (since v1.15)
186+
# skip_upload: true
187+
188+
# You can add extra pre-existing files to the release.
189+
# The filename on the release will be the last part of the path (base).
190+
# If another file with the same name exists, the last one found will be used.
191+
#
192+
# Templates: allowed
193+
# extra_files:
194+
# - glob: ./path/to/file.txt
195+
# - glob: ./glob/**/to/**/file/**/*
196+
# - glob: ./glob/foo/to/bar/file/foobar/override_from_previous
197+
# - glob: ./single_file.txt
198+
# name_template: file.txt # note that this only works if glob matches 1 file only
199+
200+
201+
# Additional templated extra files to add to the release.
202+
# Those files will have their contents pass through the template engine,
203+
# and its results will be added to the release.
204+
#
205+
# Since: v1.17 (pro)
206+
# This feature is only available in GoReleaser Pro.
207+
# Templates: allowed
208+
# templated_extra_files:
209+
# - src: LICENSE.tpl
210+
# dst: LICENSE.txt
211+
212+
# The lines beneath this are called `modelines`. See `:help modeline`
213+
# Feel free to remove those if you don't want/use them.
214+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
215+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

cmd/bc-cli/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
goflags "flag"
23+
"fmt"
24+
"os"
2325
"path"
2426

2527
"github.com/bestchains/bc-cli/cmd/bc-cli/create"
@@ -29,6 +31,7 @@ import (
2931
"github.com/bestchains/bc-cli/pkg/common"
3032
"github.com/spf13/cobra"
3133
"github.com/spf13/viper"
34+
"k8s.io/component-base/version"
3235
"k8s.io/klog/v2"
3336
)
3437

@@ -94,6 +97,7 @@ func NewCmd() *cobra.Command {
9497
cmd.AddCommand(create.NewCreateCmd())
9598
cmd.AddCommand(get.NewGetCmd())
9699
cmd.AddCommand(delcmd.NewDeleteCmd())
100+
cmd.AddCommand(newCmdVersion())
97101
return cmd
98102
}
99103

@@ -122,3 +126,19 @@ func loadConfig(configFile string) (config *common.Config, err error) {
122126
klog.V(3).Infof("all config: %+v", config)
123127
return config, nil
124128
}
129+
130+
// newCmdVersion provides the version information of bc-cli
131+
func newCmdVersion() *cobra.Command {
132+
cmd := &cobra.Command{
133+
Use: "version",
134+
Short: "Print the version of bc-cli",
135+
Run: func(cmd *cobra.Command, args []string) {
136+
fmt.Printf("version: %s\n", version.Get())
137+
fmt.Printf("commit: %s\n", version.Get().GitCommit)
138+
fmt.Printf("date: %s\n", version.Get().BuildDate)
139+
os.Exit(0)
140+
},
141+
Args: cobra.NoArgs,
142+
}
143+
return cmd
144+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ require (
88
github.com/golangci/golangci-lint v1.52.2
99
github.com/int128/oauth2cli v1.14.0
1010
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
11+
github.com/pkg/errors v0.9.1
1112
github.com/spf13/cobra v1.7.0
1213
github.com/spf13/viper v1.12.0
14+
github.com/stretchr/testify v1.8.2
1315
golang.org/x/oauth2 v0.8.0
1416
golang.org/x/sync v0.1.0
1517
gopkg.in/yaml.v2 v2.4.0
1618
k8s.io/api v0.27.1
1719
k8s.io/apimachinery v0.27.1
1820
k8s.io/cli-runtime v0.27.1
1921
k8s.io/client-go v0.27.1
22+
k8s.io/component-base v0.27.1
2023
k8s.io/klog/v2 v2.90.1
2124
k8s.io/kubectl v0.27.1
2225
)
@@ -168,7 +171,6 @@ require (
168171
github.com/pelletier/go-toml v1.9.5 // indirect
169172
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
170173
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
171-
github.com/pkg/errors v0.9.1 // indirect
172174
github.com/pmezard/go-difflib v1.0.0 // indirect
173175
github.com/polyfloyd/go-errorlint v1.4.0 // indirect
174176
github.com/prometheus/client_golang v1.14.0 // indirect
@@ -201,7 +203,6 @@ require (
201203
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
202204
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
203205
github.com/stretchr/objx v0.5.0 // indirect
204-
github.com/stretchr/testify v1.8.2 // indirect
205206
github.com/subosito/gotenv v1.4.1 // indirect
206207
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
207208
github.com/tdakkota/asciicheck v0.2.0 // indirect
@@ -242,7 +243,6 @@ require (
242243
gopkg.in/ini.v1 v1.67.0 // indirect
243244
gopkg.in/yaml.v3 v3.0.1 // indirect
244245
honnef.co/go/tools v0.4.3 // indirect
245-
k8s.io/component-base v0.27.1 // indirect
246246
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
247247
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
248248
mvdan.cc/gofumpt v0.4.0 // indirect

0 commit comments

Comments
 (0)