Skip to content

Commit 4fd18cd

Browse files
committed
Publish controller-gen binaries on release
Signed-off-by: Stefan Büringer [email protected]
1 parent 5bfba2d commit 4fd18cd

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ jobs:
2323
working-directory:
2424
- ""
2525
steps:
26+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
27+
- name: Calculate go version
28+
id: vars
29+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
2630
- name: Set up Go
2731
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # tag=v5.0.2
2832
with:
29-
go-version: "1.22"
30-
cache: false
31-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
33+
go-version: ${{ steps.vars.outputs.go_version }}
3234
- name: golangci-lint
3335
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # tag=v6.1.0
3436
with:

.github/workflows/pr-dependabot.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ jobs:
2020
steps:
2121
- name: Check out code
2222
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
23+
- name: Calculate go version
24+
id: vars
25+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
2326
- name: Set up Go
2427
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # tag=v5.0.2
2528
with:
26-
go-version: '1.22'
29+
go-version: ${{ steps.vars.outputs.go_version }}
2730
- name: Update all modules
2831
run: make modules
2932
- uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # tag=v9.1.4

.github/workflows/release.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Upload binaries to release
2+
3+
on:
4+
push:
5+
# Sequence of patterns matched against refs/tags
6+
tags:
7+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 (not envtest-*)
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
build:
14+
name: Upload binaries to release
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
19+
- name: Calculate go version
20+
id: vars
21+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
22+
- name: Set up Go
23+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # tag=v5.0.2
24+
with:
25+
go-version: ${{ steps.vars.outputs.go_version }}
26+
- name: Generate release binaries
27+
run: |
28+
make release-controller-gen
29+
- name: Release
30+
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # tag=v2.0.8
31+
with:
32+
draft: false
33+
files: out/*

Makefile

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
SHELL:=/usr/bin/env bash
2525
.DEFAULT_GOAL:=help
2626

27+
#
28+
# Go.
29+
#
30+
GO_VERSION ?= 1.22.5
31+
2732
# Use GOPROXY environment variable if set
2833
GOPROXY := $(shell go env GOPROXY)
2934
ifeq ($(GOPROXY),)
@@ -34,6 +39,13 @@ export GOPROXY
3439
# Active module mode, as we use go modules to manage dependencies
3540
export GO111MODULE=on
3641

42+
# Hosts running SELinux need :z added to volume mounts
43+
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
44+
45+
ifeq ($(SELINUX_ENABLED),1)
46+
DOCKER_VOL_OPTS?=:z
47+
endif
48+
3749
# Tools.
3850
ENVTEST_DIR := hack/envtest
3951
ENVTEST_MATRIX_DIR := $(ENVTEST_DIR)/_matrix
@@ -100,7 +112,7 @@ clean-release: ## Remove all generated release binaries.
100112
rm -rf $(RELEASE_DIR)
101113

102114
## --------------------------------------
103-
## Envtest Build
115+
## Release
104116
## --------------------------------------
105117

106118
RELEASE_DIR := out
@@ -135,3 +147,37 @@ release-envtest-docker-build: $(RELEASE_DIR) ## Build the envtest binaries.
135147
--tag sigs.k8s.io/controller-tools/envtest:$(KUBERNETES_VERSION)-$(OS)-$(ARCH) \
136148
--output type=local,dest=$(RELEASE_DIR) \
137149
.
150+
151+
.PHONY: release-controller-gen
152+
release-controller-gen: clean-release ## Build controller-gen binaries.
153+
RELEASE_BINARY=controller-gen-linux-amd64 GOOS=linux GOARCH=amd64 $(MAKE) release-binary
154+
RELEASE_BINARY=controller-gen-linux-arm64 GOOS=linux GOARCH=arm64 $(MAKE) release-binary
155+
RELEASE_BINARY=controller-gen-linux-ppc64le GOOS=linux GOARCH=ppc64le $(MAKE) release-binary
156+
RELEASE_BINARY=controller-gen-linux-s390x GOOS=linux GOARCH=s390x $(MAKE) release-binary
157+
RELEASE_BINARY=controller-gen-darwin-amd64 GOOS=darwin GOARCH=amd64 $(MAKE) release-binary
158+
RELEASE_BINARY=controller-gen-darwin-arm64 GOOS=darwin GOARCH=arm64 $(MAKE) release-binary
159+
RELEASE_BINARY=controller-gen-windows-amd64.exe GOOS=windows GOARCH=amd64 $(MAKE) release-binary
160+
161+
.PHONY: release-binary
162+
release-binary: $(RELEASE_DIR)
163+
docker run \
164+
--rm \
165+
-e CGO_ENABLED=0 \
166+
-e GOOS=$(GOOS) \
167+
-e GOARCH=$(GOARCH) \
168+
-e GOCACHE=/tmp/ \
169+
--user $$(id -u):$$(id -g) \
170+
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
171+
-w /workspace \
172+
golang:$(GO_VERSION) \
173+
go build -a -trimpath -ldflags "-extldflags '-static'" \
174+
-o ./out/$(RELEASE_BINARY) ./cmd/controller-gen
175+
176+
## --------------------------------------
177+
## Helpers
178+
## --------------------------------------
179+
180+
##@ helpers:
181+
182+
go-version: ## Print the go version we use to compile our binaries and images
183+
@echo $(GO_VERSION)

0 commit comments

Comments
 (0)