Skip to content

Commit 10b26e6

Browse files
authored
Merge pull request #16 from itaysk/goreleaser
use goreleaser
2 parents 9c9639f + 8f9c105 commit 10b26e6

File tree

8 files changed

+60
-36
lines changed

8 files changed

+60
-36
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.vscode
22
dist
3-
krew
43
kubectl-neat_*

.goreleaser.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
builds:
2+
- main: ./main.go
3+
env:
4+
- CGO_ENABLED=0
5+
goos:
6+
- darwin
7+
- linux
8+
goarch:
9+
- amd64
10+
archives:
11+
- name_template: "{{ .ProjectName }}_{{ .Os }}"
12+
checksum:
13+
name_template: 'checksums.txt'
14+
snapshot:
15+
name_template: "{{ .Tag }}-next"
16+
changelog:
17+
filters:
18+
exclude:
19+
- '^docs:'
20+
- '^test:'

Makefile

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11

2-
.PHONY: test test-unit test-component test-kubectl test-install build dist clean
2+
.PHONY: test test-unit test-component test-kubectl test-install build release clean
3+
os ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
34

45
test: test-unit test-component test-kubectl test-install
56

67
test-unit:
78
go test ./...
89

9-
test-component: dist
10+
test-component: kubectl-neat_$(os)
1011
bats ./test/component.bats
1112

12-
test-kubectl: dist
13+
test-kubectl: kubectl-neat_$(os)
1314
bats ./test/kubectl.bats
1415

15-
test-install: dist
16+
test-install: dist/kubectl-neat_$(os).tar.gz dist/checksums.txt
1617
bats ./test/install.bats
1718

18-
os ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
19-
dist: dist/$(os)
20-
21-
dist/%: kubectl-neat_%
22-
mkdir -p dist/$*
23-
cp kubectl-neat_$* dist/$*/kubectl-neat
24-
2519
build: kubectl-neat_$(os)
2620

2721
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
2822
kubectl-neat_%: $(SRC)
2923
GOOS=$* go build -o $(@F)
3024

31-
clean:
32-
rm -rf ./dist ./krew
33-
rm kubectl-neat*
34-
35-
krew: dist/darwin dist/linux
36-
mkdir -p ./krew
37-
./krew-package.sh 'darwin' 'neat' 'krew'
38-
./krew-package.sh 'linux' 'neat' 'krew'
39-
25+
# release by default will not publish. run with `publish=1` to publish
26+
goreleaserflags = --skip-publish --snapshot
27+
ifdef publish
28+
goreleaserflags =
29+
endif
30+
# relase always re-builds (no dependencies on purpose)
31+
release:
32+
goreleaser --rm-dist $(goreleaserflags)
33+
34+
dist/kubectl-neat_darwin.tar.gz dist/kubectl-neat_linux.tar.gz dist/checksums.txt: release
35+
# no op recipe
36+
@:
37+
38+
krew: dist/kubectl-neat_darwin.tar.gz dist/kubectl-neat_linux.tar.gz dist/checksums.txt
39+
./krew-package.sh 'darwin' 'neat' './dist'
40+
./krew-package.sh 'linux' 'neat' './dist'
4041
# merge
41-
yq r --tojson "krew/kubectl-neat_darwin.yaml" > krew/darwin.json
42-
yq r --tojson "krew/kubectl-neat_linux.yaml" > krew/linux.json
43-
rm krew/kubectl-neat_darwin.yaml krew/kubectl-neat_linux.yaml
44-
jq --slurp '.[0].spec.platforms += .[1].spec.platforms | .[0]' 'krew/darwin.json' 'krew/linux.json' > 'krew/kubectl-neat.json'
45-
yq r krew/kubectl-neat.json > krew/kubectl-neat.yaml
46-
rm krew/kubectl-neat.json krew/darwin.json krew/linux.json
42+
yq r --tojson "dist/kubectl-neat_darwin.yaml" > dist/darwin.json
43+
yq r --tojson "dist/kubectl-neat_linux.yaml" > dist/linux.json
44+
rm dist/kubectl-neat_darwin.yaml dist/kubectl-neat_linux.yaml
45+
jq --slurp '.[0].spec.platforms += .[1].spec.platforms | .[0]' 'dist/darwin.json' 'dist/linux.json' > 'dist/kubectl-neat.json'
46+
yq r dist/kubectl-neat.json > dist/kubectl-neat.yaml
47+
rm dist/kubectl-neat.json dist/darwin.json dist/linux.json
48+
49+
clean:
50+
rm -rf dist
51+
rm kubectl-neat*

krew-package.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#! /bin/bash
22
# This script makes a platform specific krew package
3+
# it assumes goreleaser had already run and created the archives and the checksums
34
# Arguments:
45
# 1. target os (`linux`/`darwin`)
56
# 2. plugin name (rename the plugin in tests to avoid conflicts with existing installation)
6-
# 3. directory where to create artifacts
7+
# 3. path to goreleaser dist directory
78

89
os="$1"
910
plugin="$2"
1011
dir="$3"
1112

12-
tar -czf "$dir/kubectl-neat_$os.tar.gz" "dist/$os"
13-
sha256=$(sha256sum "$dir/kubectl-neat_$os.tar.gz" | awk '{print $1}')
13+
sha256=$(grep "$os" "$dir/checksums.txt" | cut -f1 -d ' ')
1414
tmp="$dir/kubectl-${plugin}_${os}.json"
1515
yq r --tojson krew-template.yaml >"$tmp"
1616
jq 'delpaths([path(.spec.platforms[] | select( .selector.matchLabels.os != $os ))])' --arg os "$os" "$tmp" | sponge "$tmp"

krew-template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
uri: https://github.com/itaysk/kubectl-neat/releases/download/v1.0.0/kubectl-neat_darwin.tar.gz
2222
sha256: ${sha256}
2323
files:
24-
- from: "/dist/darwin/*"
24+
- from: "/*"
2525
to: "."
2626
bin: "./kubectl-neat"
2727
- selector:
@@ -31,6 +31,6 @@ spec:
3131
uri: https://github.com/itaysk/kubectl-neat/releases/download/v1.0.0/kubectl-neat_linux.tar.gz
3232
sha256: ${sha256}
3333
files:
34-
- from: "/dist/linux/*"
34+
- from: "/*"
3535
to: "."
3636
bin: "./kubectl-neat"

test/component.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bats
22
runtime_os=$(uname -s | tr '[:upper:]' '[:lower:]')
3-
exe="dist/$runtime_os/kubectl-neat"
3+
exe="./kubectl-neat_${runtime_os}"
44

55
@test "pod - json" {
66
KUBECTL_OUTPUT=json run "$exe" <./test/fixtures/pod-1-raw.json

test/install.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bats
22

33
@test "krew install" {
4-
dir=$(mktemp -d)
4+
dir="dist"
55
plugin="neat2"
66
runtime_os=$(uname -s | tr '[:upper:]' '[:lower:]')
77
./krew-package.sh "$runtime_os" "$plugin" "$dir"
8-
kubectl krew install --manifest="$dir/kubectl-${plugin}_${runtime_os}.yaml" --archive="$dir/kubectl-neat_$runtime_os.tar.gz"
8+
kubectl krew install --manifest="$dir/kubectl-${plugin}_${runtime_os}.yaml" --archive="$dir/kubectl-neat_${runtime_os}.tar.gz"
99

1010
run kubectl "$plugin" svc kubernetes -oyaml
1111

test/kubectl.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function setup() {
66
# rename the plugin to avoid conflicts with existing installation
77
plugin_name="neat2"
88
plugin="$tmpdir"/kubectl-"$plugin_name"
9-
ln -s "$(pwd)/dist/$runtime_os/kubectl-neat" "$plugin"
9+
ln -s "$(pwd)/kubectl-neat_${runtime_os}" "$plugin"
1010
# PATH modification here has no external affect since bats runs in a subshell
1111
PATH="$PATH":"$tmpdir"
1212
kubectl delete -f ./test/fixtures/pod-1-neat.json 2>/dev/null || true

0 commit comments

Comments
 (0)