Skip to content

Commit 7857623

Browse files
authored
Merge pull request #2911 from sbueringer/pr-publish-setup-envtest
✨ Publish setup-envtest binaries on releases
2 parents fdc8bd7 + 30d154d commit 7857623

File tree

5 files changed

+113
-5
lines changed

5 files changed

+113
-5
lines changed

.github/workflows/golangci-lint.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ jobs:
2323
- ""
2424
- tools/setup-envtest
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

+4-1
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

+33
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
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
29+
- name: Release
30+
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # tag=v2.0.8
31+
with:
32+
draft: false
33+
files: tools/setup-envtest/out/*

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
# Tools binaries.
2424
hack/tools/bin
2525

26+
# Release artifacts
27+
tools/setup-envtest/out
28+
2629
junit-report.xml
27-
/artifacts
30+
/artifacts

Makefile

+67
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
TOOLS_DIR := hack/tools
3951
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
@@ -123,6 +135,48 @@ modules: ## Runs go mod to ensure modules are up to date.
123135
cd $(ENVTEST_DIR); go mod tidy
124136
cd $(SCRATCH_ENV_DIR); go mod tidy
125137

138+
## --------------------------------------
139+
## Release
140+
## --------------------------------------
141+
142+
RELEASE_DIR := tools/setup-envtest/out
143+
144+
.PHONY: $(RELEASE_DIR)
145+
$(RELEASE_DIR):
146+
mkdir -p $(RELEASE_DIR)/
147+
148+
.PHONY: release
149+
release: clean-release $(RELEASE_DIR) ## Build release.
150+
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
151+
152+
# Build binaries first.
153+
$(MAKE) release-binaries
154+
155+
.PHONY: release-binaries
156+
release-binaries: ## Build release binaries.
157+
RELEASE_BINARY=setup-envtest-linux-amd64 GOOS=linux GOARCH=amd64 $(MAKE) release-binary
158+
RELEASE_BINARY=setup-envtest-linux-arm64 GOOS=linux GOARCH=arm64 $(MAKE) release-binary
159+
RELEASE_BINARY=setup-envtest-linux-ppc64le GOOS=linux GOARCH=ppc64le $(MAKE) release-binary
160+
RELEASE_BINARY=setup-envtest-linux-s390x GOOS=linux GOARCH=s390x $(MAKE) release-binary
161+
RELEASE_BINARY=setup-envtest-darwin-amd64 GOOS=darwin GOARCH=amd64 $(MAKE) release-binary
162+
RELEASE_BINARY=setup-envtest-darwin-arm64 GOOS=darwin GOARCH=arm64 $(MAKE) release-binary
163+
RELEASE_BINARY=setup-envtest-windows-amd64.exe GOOS=windows GOARCH=amd64 $(MAKE) release-binary
164+
165+
.PHONY: release-binary
166+
release-binary: $(RELEASE_DIR)
167+
docker run \
168+
--rm \
169+
-e CGO_ENABLED=0 \
170+
-e GOOS=$(GOOS) \
171+
-e GOARCH=$(GOARCH) \
172+
-e GOCACHE=/tmp/ \
173+
--user $$(id -u):$$(id -g) \
174+
-v "$$(pwd):/workspace$(DOCKER_VOL_OPTS)" \
175+
-w /workspace/tools/setup-envtest \
176+
golang:$(GO_VERSION) \
177+
go build -a -trimpath -ldflags "-extldflags '-static'" \
178+
-o ./out/$(RELEASE_BINARY) ./
179+
126180
## --------------------------------------
127181
## Cleanup / Verification
128182
## --------------------------------------
@@ -136,6 +190,10 @@ clean: ## Cleanup.
136190
clean-bin: ## Remove all generated binaries.
137191
rm -rf hack/tools/bin
138192

193+
.PHONY: clean-release
194+
clean-release: ## Remove the release folder
195+
rm -rf $(RELEASE_DIR)
196+
139197
.PHONY: verify-modules
140198
verify-modules: modules $(GO_MOD_CHECK) ## Verify go modules are up to date
141199
@if !(git diff --quiet HEAD -- go.sum go.mod $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum $(ENVTEST_DIR)/go.mod $(ENVTEST_DIR)/go.sum $(SCRATCH_ENV_DIR)/go.sum); then \
@@ -149,3 +207,12 @@ APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
149207
.PHONY: apidiff
150208
verify-apidiff: $(GO_APIDIFF) ## Check for API differences
151209
$(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible
210+
211+
## --------------------------------------
212+
## Helpers
213+
## --------------------------------------
214+
215+
##@ helpers:
216+
217+
go-version: ## Print the go version we use to compile our binaries and images
218+
@echo $(GO_VERSION)

0 commit comments

Comments
 (0)