Skip to content

Commit 79bbe8b

Browse files
authored
Release artifacts and helm plugin hooks (#5)
Signed-off-by: Andrew Block <[email protected]>
1 parent b06f693 commit 79bbe8b

File tree

6 files changed

+234
-6
lines changed

6 files changed

+234
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ on:
33
push:
44
branches:
55
- "main"
6-
tags:
7-
- "*"
86
pull_request:
97
branches:
108
- "*"

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set up Go 1.16
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: 1.16
15+
id: go
16+
17+
- name: Check out code into the Go module directory
18+
uses: actions/checkout@v2
19+
20+
- name: Verify go.mod is sane
21+
run: go mod tidy && git diff --no-patch --exit-code
22+
23+
- name: Install dependencies
24+
run: go mod download
25+
26+
- name: Build
27+
run: make
28+
29+
- name: Test
30+
run: make test
31+
32+
- name: golangci-lint
33+
uses: golangci/[email protected]
34+
with:
35+
version: v1.39.0
36+
skip-go-installation: true
37+
skip-pkg-cache: true
38+
39+
- name: Make release binaries
40+
run: make dist
41+
env:
42+
MAKEFILE_SHELL: /bin/bash
43+
44+
- name: Get the version
45+
id: get_version
46+
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" |tee -a $GITHUB_ENV
47+
48+
- name: Generate Changelog
49+
run: |
50+
LATEST_TAG=$(git tag --sort=creatordate | sed '$!d')
51+
PREVIOUS_TAG=$(git tag --sort=creatordate | sed 'x;$!d')
52+
if [ -z "${PREVIOUS_TAG}" ]; then
53+
REV_RANGE=HEAD
54+
else
55+
REV_RANGE=${PREVIOUS_TAG}..${LATEST_TAG}
56+
fi
57+
git log --pretty=format:"- %s %H (%aN)" --no-merges ${REV_RANGE} > ${VERSION}-CHANGELOG.txt
58+
cat ${VERSION}-CHANGELOG.txt
59+
60+
- name: Create release
61+
uses: softprops/action-gh-release@v1
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
with:
65+
body_path: ${{ env.VERSION }}-CHANGELOG.txt
66+
draft: false
67+
prerelease: false
68+
69+
- name: Upload release binaries
70+
uses: svenstaro/upload-release-action@v2
71+
with:
72+
repo_token: ${{ secrets.GITHUB_TOKEN }}
73+
file: dist/*
74+
tag: ${{ github.ref }}
75+
overwrite: true
76+
file_glob: true

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# limitations under the License.
1515

1616
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
17+
ifdef MAKEFILE_SHELL
18+
SHELL=$(MAKEFILE_SHELL)
19+
endif
1720
ifeq (,$(shell go env GOBIN))
1821
GOBIN=$(shell go env GOPATH)/bin
1922
else
@@ -25,6 +28,8 @@ DISTDIR := $(CURDIR)/dist
2528
BINNAME := helm-sigstore
2629

2730
# Set version variables for LDFLAGS
31+
GO := go
32+
CGO_ENABLED := 0
2833
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
2934
GIT_HASH ?= $(shell git rev-parse HEAD)
3035
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
@@ -66,11 +71,19 @@ lint: golangci-lint ## Runs golangci-lint linter
6671
PLATFORMS=darwin linux windows
6772
ARCHITECTURES=amd64
6873

74+
define buildartifacts
75+
if [ "$(1)" == "windows" ]; then \
76+
PLATFORM_EXT=".exe"; \
77+
fi
78+
mkdir -p $(DISTDIR);
79+
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=$(CGO_ENABLED) $(GO) build \
80+
-ldflags $(LDFLAGS) -o $(DISTDIR)/$(BINNAME)-$(GOOS)-$(GOARCH)$$(if [ "$(1)" == "windows" ]; then echo ".exe"; fi) main.go;
81+
sha256sum $(DISTDIR)/$(BINNAME)-$(1)-$(2)$$(if [ "$(1)" == "windows" ]; then echo ".exe"; fi) | awk '{print $$1}' > $(DISTDIR)/$(BINNAME)-$(1)-$(2)$$(if [ "$(1)" == "windows" ]; then echo ".exe"; fi).sha256;
82+
endef
83+
6984
dist:
7085
$(foreach GOOS, $(PLATFORMS),\
71-
$(foreach GOARCH, $(ARCHITECTURES), $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); \
72-
go build -ldflags $(LDFLAGS) -o $(DISTDIR)/$(BINNAME)-$(GOOS)-$(GOARCH) main.go)))
73-
shasum -a 256 $(DISTDIR)/$(BINNAME)-* > $(DISTDIR)/$(BINNAME).sha2556
86+
$(foreach GOARCH, $(ARCHITECTURES), $(call buildartifacts,$(GOOS),$(GOARCH))))
7487

7588
test:
7689
go test ./...

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The plugin binary will be available in the `bin` directory
3939
Before installing `helm-sigstore` as a Helm plugin, ensure that Helm is installed and configured on your machine. Then install the plugin.
4040

4141
```shell
42-
$ helm plugin install .
42+
$ helm plugin install https://github.com/sigstore/helm-sigstore
4343
```
4444

4545
Confirm the plugin is available in Helm

plugin.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ usage: "Integrates Helm into Sigstore"
44
description: |-
55
This plugin integrates Helm into the Sigstore ecosystem.
66
command: "$HELM_PLUGIN_DIR/bin/helm-sigstore"
7+
hooks:
8+
install: "$HELM_PLUGIN_DIR/scripts/install-binary.sh"
9+
update: "$HELM_PLUGIN_DIR/scripts/install-binary.sh"

scripts/install-binary.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env sh
2+
3+
echo "Installing helm sigstore plugin"
4+
5+
PROJECT_NAME="helm-sigstore"
6+
PROJECT_ORG="${PROJECT_ORG:-sigstore}"
7+
PROJECT_GH="$PROJECT_ORG/$PROJECT_NAME"
8+
export GREP_COLOR="never"
9+
10+
HELM_MAJOR_VERSION=$("${HELM_BIN}" version --client --short | awk -F '.' '{print $1}')
11+
12+
: ${HELM_PLUGIN_DIR:="$("${HELM_BIN}" home --debug=false)/plugins/helm-diff"}
13+
14+
# Convert the HELM_PLUGIN_DIR to unix if cygpath is
15+
# available. This is the case when using MSYS2 or Cygwin
16+
# on Windows where helm returns a Windows path but we
17+
# need a Unix path
18+
19+
if type cygpath >/dev/null 2>&1; then
20+
HELM_PLUGIN_DIR=$(cygpath -u $HELM_PLUGIN_DIR)
21+
fi
22+
23+
if [ "$SKIP_BIN_INSTALL" = "1" ]; then
24+
echo "Skipping binary install"
25+
exit
26+
fi
27+
28+
# initArch discovers the architecture for this system.
29+
initArch() {
30+
ARCH=$(uname -m)
31+
case $ARCH in
32+
armv5*) ARCH="armv5" ;;
33+
armv6*) ARCH="armv6" ;;
34+
armv7*) ARCH="armv7" ;;
35+
aarch64) ARCH="arm64" ;;
36+
x86) ARCH="386" ;;
37+
x86_64) ARCH="amd64" ;;
38+
i686) ARCH="386" ;;
39+
i386) ARCH="386" ;;
40+
esac
41+
}
42+
43+
# initOS discovers the operating system for this system.
44+
initOS() {
45+
OS=$(uname | tr '[:upper:]' '[:lower:]')
46+
47+
case "$OS" in
48+
# Msys support
49+
msys*) OS='windows' ;;
50+
# Minimalist GNU for Windows
51+
mingw*) OS='windows' ;;
52+
darwin) OS='darwin' ;;
53+
esac
54+
}
55+
56+
# verifySupported checks that the os/arch combination is supported for
57+
# binary builds.
58+
verifySupported() {
59+
supported="linux-amd64\ndarwin-amd64\nwindows-amd64"
60+
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
61+
echo "No prebuild binary for ${OS}-${ARCH}."
62+
exit 1
63+
fi
64+
65+
if ! type "curl" >/dev/null && ! type "wget" >/dev/null; then
66+
echo "Either curl or wget is required"
67+
exit 1
68+
fi
69+
}
70+
71+
# getDownloadURL checks the latest available version.
72+
getDownloadURL() {
73+
#version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :)
74+
version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)"
75+
if [ -n "$version" ]; then
76+
DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/v$version/$PROJECT_NAME-$OS-$ARCH"
77+
else
78+
# Use the GitHub API to find the download url for this project.
79+
url="https://api.github.com/repos/$PROJECT_GH/releases/latest"
80+
if type "curl" >/dev/null; then
81+
DOWNLOAD_URL=$(curl -s $url | grep $OS-$ARCH\" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
82+
elif type "wget" >/dev/null; then
83+
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS-$ARCH\" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
84+
fi
85+
fi
86+
87+
}
88+
89+
# downloadFile downloads the latest binary package and also the checksum
90+
# for that binary.
91+
downloadFile() {
92+
BINDIR="$HELM_PLUGIN_DIR/bin"
93+
rm -rf "$BINDIR"
94+
mkdir -p "$BINDIR"
95+
echo "Downloading $DOWNLOAD_URL"
96+
if type "curl" >/dev/null; then
97+
HTTP_CODE=$(curl -sL --write-out "%{http_code}" "$DOWNLOAD_URL" --output "$BINDIR/$PROJECT_NAME")
98+
if [ ${HTTP_CODE} -ne 200 ]; then
99+
exit 1
100+
fi
101+
elif type "wget" >/dev/null; then
102+
wget -q -O "$BINDIR/$PROJECT_NAME" "$DOWNLOAD_URL"
103+
fi
104+
105+
chmod +x "$BINDIR/$PROJECT_NAME"
106+
107+
}
108+
109+
# fail_trap is executed if an error occurs.
110+
fail_trap() {
111+
result=$?
112+
if [ "$result" != "0" ]; then
113+
echo "Failed to install $PROJECT_NAME"
114+
printf "\tFor support, go to https://github.com/$PROJECT_GH.\n"
115+
fi
116+
exit $result
117+
}
118+
119+
# testVersion tests the installed client to make sure it is working.
120+
testVersion() {
121+
set +e
122+
echo "$PROJECT_NAME installed into $HELM_PLUGIN_DIR/$PROJECT_NAME"
123+
"${HELM_PLUGIN_DIR}/bin/$PROJECT_NAME" version
124+
set -e
125+
}
126+
127+
128+
# Execution
129+
130+
#Stop execution on any error
131+
trap "fail_trap" EXIT
132+
set -e
133+
initArch
134+
initOS
135+
verifySupported
136+
getDownloadURL
137+
downloadFile
138+
testVersion

0 commit comments

Comments
 (0)