Skip to content

Commit ad5da45

Browse files
authored
Merge pull request #22 from setoru/add-release
Add CI Workflow for Automated Releases
2 parents 2e220cb + b23fa3c commit ad5da45

12 files changed

Lines changed: 1614 additions & 1 deletion

File tree

.github/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
changelog:
2+
categories:
3+
- title: ❗ API Changes
4+
labels:
5+
- kind/api-change
6+
- title: 🚀 Features
7+
labels:
8+
- kind/feature
9+
- title: 🧰 Enhancements
10+
labels:
11+
- kind/enhancement
12+
- title: 🐛 Bug Fixes
13+
labels:
14+
- kind/bug
15+
- kind/regression
16+
- title: 📖 Documentation
17+
labels:
18+
- kind/documentation
19+
- title: Dependencies
20+
labels:
21+
- area/dependency
22+
- title: 🌱 Others
23+
labels:
24+
- "*"

.github/workflows/release.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Releases
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
releases:
14+
name: Create draft release
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Clone the code
18+
uses: actions/checkout@v4
19+
- name: Set version info
20+
run: |
21+
echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
22+
PREVIOUS_VERSION=$(git tag --sort=-creatordate | sed -n 2p)
23+
if [ -z "$PREVIOUS_VERSION" ]; then
24+
PREVIOUS_VERSION=$(git rev-list --max-parents=0 HEAD)
25+
fi
26+
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
27+
echo "RELEASE_BRANCH=release-$(echo ${GITHUB_REF_NAME} | grep -Eo '[0-9]\.[0-9]+')" >> $GITHUB_ENV
28+
echo "RELEASE_TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
29+
echo "IMAGE_REPO=$(echo ${GITHUB_REPOSITORY} | awk -F "/" '{print $1}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
30+
echo "GH_ORG_NAME=${GITHUB_REPOSITORY%%/*}" >> $GITHUB_ENV
31+
- name: Setup Go
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version: '~1.22'
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
- name: Log into registry ghcr.io
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
- name: Build and push
46+
run: |
47+
echo "Release tag is: $RELEASE_TAG"
48+
make docker-buildx
49+
- name: Run release
50+
run: |
51+
echo "Version is: $VERSION"
52+
echo "Previous version is: $PREVIOUS_VERSION"
53+
echo "Release branch is: $RELEASE_BRANCH"
54+
echo "Release tag is: $RELEASE_TAG"
55+
make release
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
builds: []
2+
3+
archives: []
4+
5+
release:
6+
discussion_category_name: General
7+
extra_files:
8+
- glob: ./out/*
9+
draft: true

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ROOT_DIR_RELATIVE := .
2+
include $(ROOT_DIR_RELATIVE)/common.mk
3+
14
GO ?= $(shell which go)
25
OS ?= $(shell $(GO) env GOOS)
36
ARCH ?= $(shell $(GO) env GOARCH)
@@ -11,6 +14,22 @@ KUBEBUILDER_VERSION=1.28.0
1114

1215
HELM_FILES := $(shell find charts/huaweicloud-webhook)
1316

17+
# Release variables
18+
RELEASE_DIR := out
19+
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
20+
REPO_ROOT := $(shell git rev-parse --show-toplevel)
21+
GH_ORG_NAME ?= HuaweiCloudDeveloper
22+
GH_REPO_NAME ?= cert-manager-webhook-huawei
23+
24+
GH_REPO ?= $(GH_ORG_NAME)/$(GH_REPO_NAME)
25+
TOOLS_DIR := hack/tools
26+
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
27+
GORELEASER_CONFIG := .goreleaser.yaml
28+
29+
# Tools binaries
30+
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
31+
GORELEASER := $(TOOLS_BIN_DIR)/goreleaser
32+
1433
test: _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kube-apiserver _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kubectl
1534
TEST_ASSET_ETCD=_test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd \
1635
TEST_ASSET_KUBE_APISERVER=_test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kube-apiserver \
@@ -26,11 +45,25 @@ _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd _test/kubebuilder-$(
2645
.PHONY: clean
2746
clean:
2847
rm -r _test $(OUT)
48+
rm -rf $(RELEASE_DIR)
49+
rm -rf hack/tools/bin
50+
2951

3052
.PHONY: build
3153
build:
3254
docker build -t "$(IMAGE_NAME):$(IMAGE_TAG)" .
3355

56+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
57+
.PHONY: docker-buildx
58+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
59+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
60+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
61+
- $(CONTAINER_TOOL) buildx create --name cert-manager-webhook-huawei-builder
62+
$(CONTAINER_TOOL) buildx use cert-manager-webhook-huawei-builder
63+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
64+
- $(CONTAINER_TOOL) buildx rm cert-manager-webhook-huawei-builder
65+
rm Dockerfile.cross
66+
3467
.PHONY: rendered-manifest.yaml
3568
rendered-manifest.yaml: $(OUT)/rendered-manifest.yaml
3669

@@ -43,3 +76,39 @@ $(OUT)/rendered-manifest.yaml: $(HELM_FILES) | $(OUT)
4376

4477
_test $(OUT) _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH):
4578
mkdir -p $@
79+
80+
##@ release:
81+
82+
$(RELEASE_DIR):
83+
mkdir -p $@
84+
85+
.PHONY: clean-release
86+
clean-release: ## Remove the release folder
87+
rm -rf $(RELEASE_DIR)
88+
89+
.PHONY: check-github-token
90+
check-github-token: ## Check if the github token is set
91+
@if [ -z "${GITHUB_TOKEN}" ]; then echo "GITHUB_TOKEN is not set"; exit 1; fi
92+
93+
.PHONY: check-previous-release-tag
94+
check-previous-release-tag: ## Check if the previous release tag is set
95+
@if [ -z "${PREVIOUS_VERSION}" ]; then echo "PREVIOUS_VERSION is not set"; exit 1; fi
96+
97+
.PHONY: check-release-tag
98+
check-release-tag: ## Check if the release tag is set
99+
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
100+
# @if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
101+
102+
.PHONY: check-release-branch
103+
check-release-branch: ## Check if the release branch is set
104+
@if [ -z "${RELEASE_BRANCH}" ]; then echo "RELEASE_BRANCH is not set"; exit 1; fi
105+
106+
.PHONY: release-changelog
107+
release-changelog: $(RELEASE_NOTES) check-release-tag check-previous-release-tag check-github-token $(RELEASE_DIR)
108+
$(RELEASE_NOTES) --debug --org $(GH_ORG_NAME) --repo $(GH_REPO_NAME) --start-sha $(shell git rev-list -n 1 ${PREVIOUS_VERSION}) --end-sha $(shell git rev-list -n 1 ${RELEASE_TAG}) --output $(RELEASE_DIR)/CHANGELOG.md --go-template go-template:$(REPO_ROOT)/hack/changelog.tpl --dependencies=false --branch=${RELEASE_BRANCH} --required-author=""
109+
110+
.PHONY: release
111+
release: clean-release check-release-tag check-release-branch $(RELEASE_DIR) $(GORELEASER)
112+
git checkout "${RELEASE_TAG}"
113+
$(MAKE) release-changelog
114+
$(GORELEASER) release --config $(GORELEASER_CONFIG) --release-notes $(RELEASE_DIR)/CHANGELOG.md --clean

common.mk

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2025.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include $(ROOT_DIR_RELATIVE)/versions.mk
16+
17+
TOOLS_DIR := $(ROOT_DIR_RELATIVE)/hack/tools
18+
TOOLS_DIR_DEPS := $(TOOLS_DIR)/go.sum $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/Makefile
19+
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
20+
21+
# Use GOPROXY environment variable if set
22+
GOPROXY := $(shell go env GOPROXY)
23+
ifeq ($(GOPROXY),)
24+
GOPROXY := https://proxy.golang.org
25+
endif
26+
export GOPROXY
27+
28+
$(TOOLS_BIN_DIR)/%: $(TOOLS_DIR_DEPS)
29+
make -C $(TOOLS_DIR) $(subst $(TOOLS_DIR)/,,$@)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/cert-manager/cert-manager-webhook-huawei
1+
module github.com/HuaweiCloudDeveloper/cert-manager-webhook-huawei
22

33
go 1.22.0
44

hack/changelog.tpl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Release notes for Cert Manager Webhook Huawei <RELEASE_VERSION>
2+
3+
[Documentation](https://github.com/HuaweiCloudDeveloper/cert-manager-webhook-huawei)
4+
5+
# Changelog since <PREVIOUS_VERSION>
6+
7+
{{with .NotesWithActionRequired -}}
8+
## Urgent Upgrade Notes
9+
10+
### (Important: Please read before upgrading)
11+
12+
{{range .}}{{println "-" .}} {{end}}
13+
{{end}}
14+
15+
{{- if .Notes -}}
16+
## Changes by Kind
17+
{{ range .Notes}}
18+
### {{.Kind | prettyKind}}
19+
20+
{{range $note := .NoteEntries }}{{println "-" $note}}{{end}}
21+
{{- end -}}
22+
{{- end }}
23+
24+
The images for this release are:
25+
<ADD_IMAGE_HERE>
26+
27+
Thanks to all contributors.

hack/tools/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
ROOT_DIR_RELATIVE := ../..
17+
include $(ROOT_DIR_RELATIVE)/common.mk
18+
19+
# Directories.
20+
BIN_DIR := bin
21+
22+
## --------------------------------------
23+
## Tooling Binaries
24+
## --------------------------------------
25+
26+
$(BIN_DIR):
27+
mkdir -p $@
28+
29+
RELEASE_NOTES := $(BIN_DIR)/$(RELEASE_NOTES_BIN)
30+
RELEASE_NOTES_PKG := k8s.io/release/cmd/release-notes
31+
32+
.PHONY: $(RELEASE_NOTES_BIN)
33+
$(RELEASE_NOTES_BIN): $(RELEASE_NOTES)
34+
35+
$(RELEASE_NOTES): ## Build release notes from tools folders.
36+
GOBIN=$(abspath $(BIN_DIR)) go install $(RELEASE_NOTES_PKG)@$(RELEASE_NOTES_VERSION)
37+
38+
GORELEASER_BIN := goreleaser
39+
GORELEASER := $(BIN_DIR)/$(GORELEASER_BIN)
40+
GORELEASER_PKG := github.com/goreleaser/goreleaser
41+
42+
.PHONY: $(GORELEASER_BIN)
43+
$(GORELEASER_BIN): $(GORELEASER)
44+
45+
$(GORELEASER):
46+
GOBIN=$(abspath $(BIN_DIR)) go install $(GORELEASER_PKG)@$(GORELEASER_VERSION)
47+
48+
.PHONY: clean
49+
clean: ## Remove all tools
50+
rm -rf $(BIN_DIR)

0 commit comments

Comments
 (0)