Skip to content

Commit 00a0e71

Browse files
authored
Add "release" makefile target and github action to run GoReleaser (#75)
This commit adds a goreleaser make target and updates the github actions workflows to run the deploy stages (GoReleaser and Docker) for tags and PRs (PR artifacts aren't pushed anywhere).
1 parent 8fbb1e3 commit 00a0e71

File tree

5 files changed

+130
-59
lines changed

5 files changed

+130
-59
lines changed

.github/workflows/ci.yml

-56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: CI
22

33
on:
4-
push: {}
54
pull_request:
65
branches: [ main ]
76

@@ -55,58 +54,3 @@ jobs:
5554
uses: golangci/golangci-lint-action@v2
5655
with:
5756
version: v1.35.2
58-
59-
deploy:
60-
name: Deploy
61-
needs:
62-
- test
63-
- lint
64-
runs-on: ubuntu-latest
65-
steps:
66-
67-
- name: Check out code into the Go module directory
68-
uses: actions/checkout@v2
69-
with:
70-
fetch-depth: 0
71-
72-
- name: Prepare
73-
id: prep
74-
run: |
75-
TAG=ci
76-
if [[ $GITHUB_REF == refs/tags/* ]]; then
77-
TAG=${GITHUB_REF#refs/tags/}
78-
elif [[ $GITHUB_REF == refs/heads/* ]]; then
79-
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
80-
elif [[ $GITHUB_REF == refs/pull/* ]]; then
81-
TAG=pr-${{ github.event.number }}
82-
fi
83-
84-
echo ::set-output name=tag::${TAG}
85-
echo ::set-output name=platforms::linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
86-
87-
- name: Set up Docker Buildx
88-
uses: docker/setup-buildx-action@v1
89-
90-
- name: Login to Quay
91-
if: github.event_name != 'pull_request'
92-
uses: docker/login-action@v1
93-
with:
94-
username: ${{ secrets.QUAY_USERNAME }}
95-
password: ${{ secrets.QUAY_PASSWORD }}
96-
registry: quay.io
97-
98-
- name: Build helm-operator image
99-
uses: docker/build-push-action@v2
100-
with:
101-
context: .
102-
platforms: ${{ steps.prep.outputs.platforms }}
103-
push: ${{ github.event_name != 'pull_request' }}
104-
tags: quay.io/joelanford/helm-operator:${{ steps.prep.outputs.tag }}
105-
106-
- name: Build example nginx-operator image
107-
uses: docker/build-push-action@v2
108-
with:
109-
context: ./example
110-
platforms: ${{ steps.prep.outputs.platforms }}
111-
push: ${{ github.event_name != 'pull_request' }}
112-
tags: quay.io/joelanford/nginx-operator:${{ steps.prep.outputs.tag }}

.github/workflows/deploy.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
goreleaser:
12+
name: GoReleaser
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out code into the Go module directory
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Install Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.15
24+
25+
- name: Create release
26+
run: |
27+
SNAPSHOT="--snapshot"
28+
if [[ $GITHUB_REF == refs/tags/* ]]; then
29+
SNAPSHOT=""
30+
fi
31+
GORELEASER_ARGS="--rm-dist ${SNAPSHOT}" make release
32+
33+
docker:
34+
name: Docker
35+
runs-on: ubuntu-latest
36+
steps:
37+
38+
- name: Check out code into the Go module directory
39+
uses: actions/checkout@v2
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Prepare
44+
id: prep
45+
run: |
46+
IMG=quay.io/joelanford/helm-operator
47+
if [[ $GITHUB_REF == refs/tags/* ]]; then
48+
TAG=${GITHUB_REF#refs/tags/}
49+
MAJOR_MINOR=${TAG%.*}
50+
echo ::set-output name=tags::${IMG}:${TAG},${IMG}:${MAJOR_MINOR}
51+
52+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
53+
TAG=pr-${{ github.event.number }}
54+
echo ::set-output name=tags::${IMG}:${TAG}
55+
fi
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v1
59+
60+
- name: Login to Quay
61+
if: github.event_name != 'pull_request'
62+
uses: docker/login-action@v1
63+
with:
64+
username: ${{ secrets.QUAY_USERNAME }}
65+
password: ${{ secrets.QUAY_PASSWORD }}
66+
registry: quay.io
67+
68+
- name: Build helm-operator image
69+
uses: docker/build-push-action@v2
70+
with:
71+
context: .
72+
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
73+
push: ${{ github.event_name != 'pull_request' }}
74+
tags: ${{ steps.prep.outputs.tags }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Binaries for programs and plugins
22
/bin
33
/tools/bin
4+
/dist
45

56
# Other IDE files
67
.idea

.goreleaser.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Global environment variables for builds.
2+
env:
3+
- CGO_ENABLED=0
4+
- GO111MODULE=on
5+
- GOPROXY=https://proxy.golang.org|direct
6+
- VERSION_PKG=github.com/joelanford/helm-operator/internal/version
7+
8+
# Hooks to run before any build is run.
9+
before:
10+
hooks:
11+
- go version | grep --quiet "go1\.15\.6" || echo "Go binary version must be 1.15.6"
12+
- go mod download
13+
14+
# Binary builds.
15+
builds:
16+
# operator-sdk build steps
17+
- id: helm-operator
18+
binary: helm-operator
19+
mod_timestamp: "{{ .CommitTimestamp }}"
20+
asmflags:
21+
- all=-trimpath={{ dir .Env.PWD }}
22+
gcflags:
23+
- all=-trimpath={{ dir .Env.PWD }}
24+
ldflags:
25+
- -s
26+
- -w
27+
- -X {{ .Env.VERSION_PKG }}.ScaffoldVersion={{ .Env.SCAFFOLD_VERSION }}
28+
- -X {{ .Env.VERSION_PKG }}.GitVersion={{ .Env.GIT_VERSION }}
29+
- -X {{ .Env.VERSION_PKG }}.GitCommit={{ .Env.GIT_COMMIT }}
30+
targets:
31+
- darwin_amd64
32+
- linux_amd64
33+
- linux_arm64
34+
- linux_ppc64le
35+
- linux_s390x
36+
37+
# Use most recent tag and short commit for snapshot version.
38+
snapshot:
39+
name_template: "{{ .Env.GIT_VERSION }}"
40+
41+
# We don't use archives, so skip creating them.
42+
archives:
43+
- format: binary
44+
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
45+
46+
checksum:
47+
name_template: "checksums.txt"

Makefile

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# GO_BUILD_ARGS should be set when running 'go build' or 'go install'.
22
VERSION_PKG = "$(shell go list -m)/internal/version"
3-
SCAFFOLD_VERSION = $(shell git describe --abbrev=0)
4-
GIT_VERSION = $(shell git describe --dirty --tags --always)
5-
GIT_COMMIT = $(shell git rev-parse HEAD)
3+
export SCAFFOLD_VERSION = $(shell git describe --abbrev=0)
4+
export GIT_VERSION = $(shell git describe --dirty --tags --always)
5+
export GIT_COMMIT = $(shell git rev-parse HEAD)
66
BUILD_DIR = $(PWD)/bin
77
GO_BUILD_ARGS = \
88
-gcflags "all=-trimpath=$(shell dirname $(shell pwd))" \
@@ -52,6 +52,11 @@ fix:
5252
lint:
5353
fetch golangci-lint 1.35.2 && golangci-lint run
5454

55+
.PHONY: release
56+
release: GORELEASER_ARGS ?= --snapshot --rm-dist
57+
release:
58+
fetch goreleaser 0.155.0 && goreleaser $(GORELEASER_ARGS)
59+
5560
.PHONY: clean
5661
clean:
5762
rm -rf $(TOOLS_BIN_DIR) $(BUILD_DIR)

0 commit comments

Comments
 (0)