Skip to content

Commit 6c96ff0

Browse files
authored
chore: setup automated releases
Gorelease with release please
2 parents 1031d97 + e1e001f commit 6c96ff0

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

.github/workflows/release.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '[0-9]+.[0-9]+.x'
8+
workflow_dispatch:
9+
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
jobs:
15+
release-please:
16+
permissions:
17+
contents: write # for google-github-actions/release-please-action to create release commit
18+
pull-requests: write # for google-github-actions/release-please-action to create release PR
19+
runs-on: ubuntu-latest
20+
outputs:
21+
releases_created: ${{ steps.release.outputs.releases_created }}
22+
tag_name: ${{ steps.release.outputs.tag_name }}
23+
# Release-please creates a PR that tracks all changes
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
27+
- uses: google-github-actions/release-please-action@e4dc86ba9405554aeba3c6bb2d169500e7d3b4ee # v4.1.1
28+
id: release
29+
with:
30+
command: manifest
31+
token: ${{secrets.RELEASE_CREATOR_TOKEN}}
32+
default-branch: main
33+
34+
goreleaser:
35+
if: needs.release-please.outputs.releases_created == 'true'
36+
permissions:
37+
contents: write
38+
needs:
39+
- release-please
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
44+
with:
45+
fetch-depth: 0
46+
- name: Set up Go
47+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5
48+
with:
49+
go-version: '1.22'
50+
- name: Run GoReleaser
51+
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6
52+
with:
53+
# either 'goreleaser' (default) or 'goreleaser-pro'
54+
distribution: goreleaser
55+
version: latest
56+
args: release --clean
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.RELEASE_CREATOR_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
bin/
22
.idea/
3+
4+
dist/

.goreleaser.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
project_name: kratix-cli
2+
3+
version: 2
4+
5+
before:
6+
hooks:
7+
- go mod tidy
8+
- go generate ./...
9+
10+
builds:
11+
- env:
12+
- CGO_ENABLED=0
13+
goos:
14+
- linux
15+
- darwin
16+
ldflags:
17+
- -X main.version={{.Version}}
18+
19+
archives:
20+
- format: tar.gz
21+
name_template: >-
22+
{{ .ProjectName }}_
23+
{{- title .Os }}_
24+
{{- if eq .Arch "amd64" }}x86_64
25+
{{- else if eq .Arch "386" }}i386
26+
{{- else }}{{ .Arch }}{{ end }}
27+
{{- if .Arm }}v{{ .Arm }}{{ end }}
28+
29+
changelog:
30+
sort: asc
31+
filters:
32+
exclude:
33+
- "^docs:"
34+
- "^test:"
35+
- "^.github"
36+
- "^.circleci"
37+
- "^test"

cmd/root.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package cmd
33
import (
44
"bytes"
55
"embed"
6-
"github.com/Masterminds/sprig/v3"
7-
"github.com/spf13/cobra"
86
"os"
97
"path/filepath"
108
"text/template"
9+
10+
"github.com/Masterminds/sprig/v3"
11+
"github.com/spf13/cobra"
1112
)
1213

1314
const filePerm = 0644
@@ -17,13 +18,14 @@ var rootCmd = &cobra.Command{
1718
Use: "kratix",
1819
Short: "A CLI tool for Kratix",
1920
Long: `A CLI tool for Kratix`,
20-
Version: "v0.0.1",
21+
Version: "",
2122
Example: ` # To initialize a new promise
2223
kratix init promise promise-name --group myorg.com --kind Database
2324
`,
2425
}
2526

26-
func Execute() {
27+
func Execute(version string) {
28+
rootCmd.Version = version
2729
err := rootCmd.Execute()
2830
if err != nil {
2931
os.Exit(1)

main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"github.com/syntasso/kratix-cli/cmd"
2121
)
2222

23+
// set at build time by goreleaser, equal to tag name without the v prefix
24+
var version = ""
25+
2326
func main() {
24-
cmd.Execute()
27+
cmd.Execute(version)
2528
}

0 commit comments

Comments
 (0)