Skip to content

Commit

Permalink
chore: setup automated releases
Browse files Browse the repository at this point in the history
Gorelease with release please
  • Loading branch information
aclevername authored Jul 30, 2024
2 parents 1031d97 + e1e001f commit 6c96ff0
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 5 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: release

on:
push:
branches:
- main
- '[0-9]+.[0-9]+.x'
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
release-please:
permissions:
contents: write # for google-github-actions/release-please-action to create release commit
pull-requests: write # for google-github-actions/release-please-action to create release PR
runs-on: ubuntu-latest
outputs:
releases_created: ${{ steps.release.outputs.releases_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
# Release-please creates a PR that tracks all changes
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: google-github-actions/release-please-action@e4dc86ba9405554aeba3c6bb2d169500e7d3b4ee # v4.1.1
id: release
with:
command: manifest
token: ${{secrets.RELEASE_CREATOR_TOKEN}}
default-branch: main

goreleaser:
if: needs.release-please.outputs.releases_created == 'true'
permissions:
contents: write
needs:
- release-please
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5
with:
go-version: '1.22'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_CREATOR_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bin/
.idea/

dist/
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
project_name: kratix-cli

version: 2

before:
hooks:
- go mod tidy
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
ldflags:
- -X main.version={{.Version}}

archives:
- format: tar.gz
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 }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^.github"
- "^.circleci"
- "^test"
10 changes: 6 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cmd
import (
"bytes"
"embed"
"github.com/Masterminds/sprig/v3"
"github.com/spf13/cobra"
"os"
"path/filepath"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/spf13/cobra"
)

const filePerm = 0644
Expand All @@ -17,13 +18,14 @@ var rootCmd = &cobra.Command{
Use: "kratix",
Short: "A CLI tool for Kratix",
Long: `A CLI tool for Kratix`,
Version: "v0.0.1",
Version: "",
Example: ` # To initialize a new promise
kratix init promise promise-name --group myorg.com --kind Database
`,
}

func Execute() {
func Execute(version string) {
rootCmd.Version = version
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"github.com/syntasso/kratix-cli/cmd"
)

// set at build time by goreleaser, equal to tag name without the v prefix
var version = ""

func main() {
cmd.Execute()
cmd.Execute(version)
}

0 comments on commit 6c96ff0

Please sign in to comment.