Skip to content

Commit e0b3f25

Browse files
committed
Implement CI to build release assets (#1)
This commit includes a number of fixes + enhancements all centered around making `helm plugin install <repo>` functional and more robust. Changes Included: - Github actions for build + testing + compilation of release assets. Whenever a new release/tag is created, goreleaser will build the appropriate static libraries for all of the different architectures/operating systems. - Tests the plugin install on all platforms using github actions - Linting support for both golang and shell scripts to increase quality - Enhancements to the local development makefile including a manual release process + dist packaging if actions based goreleaser is not desirable. Signed-off-by: David Dobmeier <david.dobmeier@dcsg.com>
1 parent 260bbd8 commit e0b3f25

File tree

17 files changed

+574
-41
lines changed

17 files changed

+574
-41
lines changed

.github/workflows/ci.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
name: CI
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
name: "Build & Test"
13+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-go@v5
18+
with:
19+
go-version-file: 'go.mod'
20+
21+
- name: Install dependencies
22+
run: make bootstrap
23+
24+
- name: Run unit tests
25+
run: make test
26+
27+
- name: Verify installation
28+
run: |
29+
mkdir -p helmplugindir
30+
make install HELM_3_PLUGINS=helmplugindir
31+
helmplugindir/helm-set-status/bin/helm-set-status version
32+
33+
helm-install:
34+
name: helm install
35+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
36+
needs: [build]
37+
runs-on: ${{ matrix.os }}
38+
container: ${{ matrix.container }}
39+
continue-on-error: ${{ matrix.experimental }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
os: [ubuntu-latest, macos-latest, windows-latest]
44+
shell: [ default ]
45+
experimental: [ false ]
46+
helm-version: [ v3.17.2, v3.16.4 ]
47+
include:
48+
- os: windows-latest
49+
shell: wsl
50+
experimental: false
51+
helm-version: v3.17.2
52+
- os: windows-latest
53+
shell: cygwin
54+
experimental: false
55+
helm-version: v3.17.2
56+
- os: ubuntu-latest
57+
container: alpine
58+
shell: sh
59+
experimental: false
60+
helm-version: v3.17.2
61+
- os: windows-latest
62+
shell: wsl
63+
experimental: false
64+
helm-version: v3.16.4
65+
- os: windows-latest
66+
shell: cygwin
67+
experimental: false
68+
helm-version: v3.16.4
69+
- os: ubuntu-latest
70+
container: alpine
71+
shell: sh
72+
experimental: false
73+
helm-version: v3.16.4
74+
75+
steps:
76+
- name: Disable autocrlf
77+
if: "contains(matrix.os, 'windows-latest')"
78+
run: |-
79+
git config --global core.autocrlf false
80+
git config --global core.eol lf
81+
82+
- uses: actions/checkout@v4
83+
84+
- name: Setup Helm
85+
uses: azure/setup-helm@v4
86+
with:
87+
version: ${{ matrix.helm-version }}
88+
89+
- name: Setup WSL
90+
if: "contains(matrix.shell, 'wsl')"
91+
uses: Vampire/setup-wsl@v5
92+
93+
- name: Setup Cygwin
94+
if: "contains(matrix.shell, 'cygwin')"
95+
uses: egor-tensin/setup-cygwin@v4
96+
97+
- name: helm plugin install
98+
run: helm plugin install .

.github/workflows/lint-sh.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint sh
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths: ['scripts/install_plugin.sh']
7+
pull_request:
8+
branches: [main]
9+
paths: ['scripts/install_plugin.sh']
10+
11+
jobs:
12+
lint-sh:
13+
name: Lint scripts/install_plugin.sh
14+
runs-on: ubuntu-latest
15+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: luizm/action-sh-checker@v0.9.0
19+
with:
20+
sh_checker_checkbashisms_enable: true

.github/workflows/lint.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Lint
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
paths-ignore: [ '**.md' ]
8+
pull_request:
9+
branches: [ main ]
10+
paths-ignore: [ '**.md' ]
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
20+
with:
21+
go-version-file: 'go.mod'
22+
- uses: golangci/golangci-lint-action@v7
23+
with:
24+
version: v2.0.1

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
17+
run: echo "flags=--snapshot" >> $GITHUB_ENV
18+
-
19+
name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
-
24+
name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: 'go.mod'
28+
-
29+
name: Run GoReleaser
30+
uses: goreleaser/goreleaser-action@v6
31+
with:
32+
distribution: goreleaser
33+
version: '~> v1'
34+
args: release --clean ${{ env.flags }}
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
/bin
22
/dist
3+
/build
4+
/cover.out
5+
docker-run-release-cache/
6+
/release

.goreleaser.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# To test this manually, run:
2+
# go install github.com/goreleaser/goreleaser@latest
3+
# goreleaser --snapshot --clean
4+
# for f in dist/helm-set-status*.tgz; do echo Testing $f...; tar tzvf $f; done
5+
project_name: helm-set-status
6+
builds:
7+
- id: default
8+
main: ./cmd/helm-set-status
9+
binary: bin/helm-set-status
10+
env:
11+
- CGO_ENABLED=0
12+
flags:
13+
- -trimpath
14+
ldflags:
15+
- -X main.version=${VERSION}
16+
goos:
17+
- freebsd
18+
- darwin
19+
- linux
20+
- windows
21+
goarch:
22+
- amd64
23+
- arm64
24+
25+
archives:
26+
- id: default
27+
builds:
28+
- default
29+
format: tgz
30+
name_template: '{{ .ProjectName }}-{{ if eq .Os "darwin" }}macos{{ else }}{{ .Os }}{{ end }}-{{ .Arch }}'
31+
wrap_in_directory: helm-set-status
32+
files:
33+
- README.md
34+
- plugin.yaml
35+
- LICENSE
36+
changelog:
37+
use: github-native
38+
39+
release:
40+
prerelease: auto

Makefile

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,74 @@
1+
HELM_HOME ?= $(shell helm home)
12
BINARY := helm-set-status
3+
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
24

3-
HELM_PLUGIN := $(shell helm env | sed -n -e 's/HELM_PLUGINS=[ "]*\([^"]*\).*/\1/p')
4-
HELM_PLUGIN_PATH ?= $(HELM_PLUGIN)/$(BINARY)
5+
HELM_3_PLUGINS := $(shell helm env HELM_PLUGINS)
6+
LDFLAGS := -X main.version=${VERSION}
57

6-
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
7-
LDFLAGS := "-X main.version=${VERSION} -extldflags -static -w -s"
8-
TAGS := "static_build netcgo osusergo"
9-
OS_PLATFORM := $(shell uname -sp | tr '[:upper:] ' '[:lower:]-' | sed 's/x86_64/amd64/')
8+
GO ?= go
109

11-
GO111MODULE = on
12-
CGO_ENABLED = 1
10+
.PHONY: format
11+
format:
12+
test -z "$$(find . -type f -o -name '*.go' -exec gofmt -d {} + | tee /dev/stderr)" || \
13+
test -z "$$(find . -type f -o -name '*.go' -exec gofmt -w {} + | tee /dev/stderr)"
1314

1415
.PHONY: install
1516
install: build
16-
[ -e $(HELM_PLUGIN_PATH) ] || mkdir -p $(HELM_PLUGIN_PATH)
17-
cp bin/$(BINARY) $(HELM_PLUGIN_PATH)/
18-
cp plugin.yaml $(HELM_PLUGIN_PATH)/
19-
20-
.PHONY: package
21-
package: build
22-
[ -e dist ] || mkdir -p dist
23-
tar -czvf dist/$(BINARY)-$(OS_PLATFORM).tgz -C bin/ helm-set-status
24-
25-
.PHONY: build
26-
build:
27-
go build -o bin/$(BINARY) -tags $(TAGS) -ldflags $(LDFLAGS) ./cmd/helm-set-status
17+
mkdir -p $(HELM_3_PLUGINS)/helm-set-status/bin
18+
cp bin/$(BINARY) $(HELM_3_PLUGINS)/helm-set-status/bin
19+
cp plugin.yaml $(HELM_3_PLUGINS)/helm-set-status/
2820

2921
.PHONY: lint
3022
lint:
31-
golangci-lint run -v ./pkg/... ./cmd/...
23+
scripts/update-gofmt.sh
24+
scripts/verify-gofmt.sh
25+
scripts/verify-govet.sh
26+
scripts/verify-staticcheck.sh
27+
28+
.PHONY: build
29+
build: lint
30+
mkdir -p bin/
31+
go build -v -o bin/$(BINARY) -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
3232

3333
.PHONY: test
3434
test:
35-
go test -v ./cmd/... ./pkg/...
35+
go test -v ./... -coverprofile cover.out -race
36+
go tool cover -func cover.out
37+
38+
.PHONY: bootstrap
39+
bootstrap:
40+
go mod download
41+
command -v staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest
42+
43+
.PHONY: dist
44+
dist: export COPYFILE_DISABLE=1 #teach OSX tar to not put ._* files in tar archive
45+
dist: export CGO_ENABLED=0
46+
dist:
47+
rm -rf build/$(BINARY)/* release/*
48+
mkdir -p build/$(BINARY)/bin release/
49+
cp README.md LICENSE plugin.yaml build/$(BINARY)
50+
GOOS=linux GOARCH=amd64 $(GO) build -o build/$(BINARY)/bin/$(BINARY) -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
51+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-linux-amd64.tgz $(BINARY)/
52+
GOOS=linux GOARCH=arm64 $(GO) build -o build/$(BINARY)/bin/$(BINARY) -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
53+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-linux-arm64.tgz $(BINARY)/
54+
GOOS=freebsd GOARCH=amd64 $(GO) build -o build/$(BINARY)/bin/$(BINARY) -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
55+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-freebsd-amd64.tgz $(BINARY)/
56+
GOOS=darwin GOARCH=amd64 $(GO) build -o build/$(BINARY)/bin/$(BINARY) -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
57+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-macos-amd64.tgz $(BINARY)/
58+
GOOS=darwin GOARCH=arm64 $(GO) build -o build/$(BINARY)/bin/$(BINARY) -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
59+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-macos-arm64.tgz $(BINARY)/
60+
rm build/$(BINARY)/bin/$(BINARY)
61+
GOOS=windows GOARCH=amd64 $(GO) build -o build/$(BINARY)/bin/$(BINARY).exe -trimpath -ldflags="$(LDFLAGS)" ./cmd/helm-set-status
62+
tar -C build/ -zcvf $(CURDIR)/release/helm-set-status-windows-amd64.tgz $(BINARY)/
63+
rm -rf build/
64+
65+
# Manual release process - CI uses goreleaser to do multiarch compilation and release
66+
.PHONY: release
67+
release: lint dist
68+
scripts/release.sh v$(VERSION)
69+
70+
# Test for the plugin installation with `helm plugin install -v THIS_BRANCH` works
71+
# Useful for verifying modified `install-binary.sh` still works against various environments
72+
.PHONY: test-plugin-installation
73+
test-plugin-installation:
74+
docker build -f testdata/Dockerfile.install .

cmd/helm-set-status/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
56
"io"
67
"os"
78

@@ -20,7 +21,10 @@ func NewRootCmd(out io.Writer, args []string) *cobra.Command {
2021
SilenceUsage: true,
2122
Args: func(cmd *cobra.Command, args []string) error {
2223
if len(args) == 0 {
23-
cmd.Help()
24+
err := cmd.Help()
25+
if err != nil {
26+
fmt.Println("Unable to print help information")
27+
}
2428
os.Exit(1)
2529
} else if len(args) != 2 {
2630
return errors.New("release and status must be specified")
@@ -30,7 +34,10 @@ func NewRootCmd(out io.Writer, args []string) *cobra.Command {
3034
RunE: runSetStatus,
3135
}
3236
flags := cmd.PersistentFlags()
33-
flags.Parse(args)
37+
err := flags.Parse(args)
38+
if err != nil {
39+
fmt.Println("Failed to parse arguments!")
40+
}
3441
settings = new(EnvSettings)
3542
settings.AddFlags(flags)
3643

@@ -68,6 +75,7 @@ func SetStatus(helmOptions common.HelmOptions, kubeConfig common.KubeConfig) err
6875

6976
func main() {
7077
setStatusCmd := NewRootCmd(os.Stdout, os.Args[1:])
78+
setStatusCmd.AddCommand(newVersionCmd())
7179

7280
if err := setStatusCmd.Execute(); err != nil {
7381
os.Exit(1)

cmd/helm-set-status/version.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Version identifier populated via the CI/CD process.
10+
var version = "HEAD"
11+
12+
func newVersionCmd() *cobra.Command {
13+
return &cobra.Command{
14+
Use: "version",
15+
Short: "Show version of the helm diff plugin",
16+
Run: func(*cobra.Command, []string) {
17+
fmt.Println(version)
18+
},
19+
}
20+
}

0 commit comments

Comments
 (0)