Skip to content

Commit

Permalink
🌱 Add GitHub Action to automate creating a release
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed Sep 2, 2021
1 parent 02e6cd2 commit 46e1377
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: release

jobs:
build:
name: tag release
runs-on: ubuntu-latest
steps:
- name: Set env
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- name: generate release artifacts
run: |
make release
- name: generate release notes
run: |
make release-notes
- name: Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: out/*
body_path: _releasenotes/${{ env.RELEASE_TAG }}.md
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
cmd/clusterctl/clusterctl
bin
hack/tools/bin
out

# Test binary, build with `go test -c`
*.test
Expand Down Expand Up @@ -67,3 +66,7 @@ clusterctl-settings.json

# test results
_artifacts

#release artifacts
out
_releasenotes
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,20 @@ set-manifest-image:
## --------------------------------------

## latest git tag for the commit, e.g., v0.3.10
RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
# the previous release tag, e.g., v0.3.9, excluding pre-release tags
PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | sort -V | grep -B1 $(RELEASE_TAG) | head -n 1 2>/dev/null)
## set by Prow, ref name of the base branch, e.g., master
RELEASE_ALIAS_TAG := $(PULL_BASE_REF)
RELEASE_DIR := out
RELEASE_NOTES_DIR := _releasenotes

$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/

$(RELEASE_NOTES_DIR):
mkdir -p $(RELEASE_NOTES_DIR)/

.PHONY: release
release: clean-release ## Builds and push container images using the latest git tag for the commit.
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
Expand Down Expand Up @@ -587,6 +593,10 @@ release-alias-tag: ## Adds the tag to the last build tag.
gcloud container images add-tag $(KUBEADM_BOOTSTRAP_CONTROLLER_IMG):$(TAG) $(KUBEADM_BOOTSTRAP_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
gcloud container images add-tag $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG):$(TAG) $(KUBEADM_CONTROL_PLANE_CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)

.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)
go run ./hack/tools/release/notes.go --from=$(PREVIOUS_TAG) > $(RELEASE_NOTES_DIR)/$(RELEASE_TAG).md

## --------------------------------------
## Cleanup / Verification
## --------------------------------------
Expand Down
9 changes: 3 additions & 6 deletions docs/developer/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,17 @@ For version v0.x.y:
> NOTE: To use your GPG signature when pushing the tag, use `git tag -s [...]` instead)
- `git tag -a v0.x.y -m v0.x.y`
- `git tag test/v0.x.y` (:warning: MUST NOT be an annotated tag)
1. Push the tag to the GitHub repository
1. Push the tag to the GitHub repository. This will automatically trigger a [Github Action](https://github.com/kubernetes-sigs/cluster-api/actions) to create a draft release.
> NOTE: `origin` should be the name of the remote pointing to `github.com/kubernetes-sigs/cluster-api`
- `git push origin v0.x.y`
- `git push origin test/v0.x.y`
1. Run `make release` to build artifacts (the image is automatically built by CI)
1. Follow the [Image Promotion process](https://git.k8s.io/k8s.io/k8s.gcr.io#image-promoter) to promote the image from the staging repo to `k8s.gcr.io/cluster-api`
1. Create a release in GitHub based on the tag created above
1. Release notes can be created by running `go run ./hack/tools/release/notes.go --from=<PREV_VERSION>`, which will generate an output that can be copied to the drafted release in GitHub.
Pay close attention to the `## :question: Sort these by hand` section, as it contains items that need to be manually sorted.
1. Review the draft release on GitHub. Pay close attention to the `## :question: Sort these by hand` section, as it contains items that need to be manually sorted.
1. Publish the release

### Permissions

Releasing requires a particular set of permissions.

* Push access to the staging gcr bucket
* Tag push access to the GitHub repository
* GitHub Release creation access
2 changes: 1 addition & 1 deletion test/infrastructure/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ set-manifest-pull-policy:
## Release
## --------------------------------------

RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
RELEASE_DIR := out

Expand Down

0 comments on commit 46e1377

Please sign in to comment.