Skip to content

Commit

Permalink
Using goreleaser to handle the release process
Browse files Browse the repository at this point in the history
  • Loading branch information
airycanon committed May 16, 2024
1 parent 284491a commit 4faf3cb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- name: Checkout
uses: actions/checkout@v4
with:
go-version: 1.22.x
- run: go mod download
- run: go test -v ./...
- run: go build -v .
- run: ./test.sh
fetch-depth: 0

- name: Create release
uses: actions/create-release@v1
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
go-version: "1.22"
id: go

- name: Cache Go Modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go test -v ./...
- run: ./test.sh

- name: Upload artifacts
uses: actions/upload-release-asset@v1.0.1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./crd-ref-docs
asset_name: crd-ref-docs
asset_content_type: application/octet-stream
version: '~> v1'
args: release --clean
29 changes: 29 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
before:
hooks:
- go mod tidy
builds:
- main: ./main.go
goos:
- linux
- windows
- darwin
ldflags: -s -w -X main.buildVersion={{.Tag}} -X main.buildCommit={{.ShortCommit}} -X main.buildDate={{.Date}}
archives:
- name_template: >-
{{- .ProjectName }}_
{{- .Version }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
files:
- LICENSE
- README.md
checksum:
name_template: 'checksums.txt'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"fmt"
"os"
"strings"
"time"
Expand All @@ -36,9 +37,12 @@ func main() {
Use: "crd-ref-docs",
Short: "Generate CRD reference documentation",
SilenceUsage: true,
Version: version(),
RunE: doRun,
}

cmd.SetVersionTemplate("{{ .Version}}\n")

cmd.Flags().StringVar(&args.LogLevel, "log-level", "INFO", "Log level")
cmd.Flags().StringVar(&args.Config, "config", "config.yaml", "Path to config file")
cmd.Flags().StringVar(&args.SourcePath, "source-path", "", "Path to source directory containing CRDs")
Expand Down Expand Up @@ -136,3 +140,13 @@ func initLogging(level string) {
zap.ReplaceGlobals(logger.Named("crd-ref-docs"))
zap.RedirectStdLog(logger.Named("stdlog"))
}

var (
buildVersion string
buildDate string
buildCommit string
)

func version() string {
return fmt.Sprintf("Version: %s, Commit: %s, BuildDate: %s", buildVersion, buildCommit, buildDate)
}

0 comments on commit 4faf3cb

Please sign in to comment.