Skip to content

Commit 5584da2

Browse files
authored
Merge pull request #2791 from Nordix/release-automation
🌱Release automation workflow
2 parents b9fa78b + cacce9e commit 5584da2

File tree

2 files changed

+112
-38
lines changed

2 files changed

+112
-38
lines changed

.github/workflows/release.yaml

Lines changed: 109 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,118 @@
1-
name: release
1+
# This code is borrowed from https://github.com/kubernetes-sigs/cluster-api/blob/main/.github/workflows/release.yaml
2+
name: Create Release
23

34
on:
45
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
6+
branches:
7+
- main
8+
paths:
9+
- 'releasenotes/*.md'
810

9-
permissions:
10-
contents: write # Allow to create a release.
11+
permissions: {}
1112

1213
jobs:
13-
build:
14+
push_release_tags:
15+
permissions:
16+
contents: write # Allow to push tags
17+
runs-on: ubuntu-latest
18+
outputs:
19+
release_tag: ${{ steps.release-version.outputs.release_version }}
20+
if: github.repository == 'kubernetes-sigs/cluster-api-provider-openstack'
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # tag=v5.0.0
24+
with:
25+
fetch-depth: 0
26+
- name: Get changed files
27+
id: changed-files
28+
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
29+
- name: Get release version
30+
id: release-version
31+
run: |
32+
if [[ ${{ steps.changed-files.outputs.all_changed_files_count }} != 1 ]]; then
33+
echo "1 release notes file should be changed to create a release tag, found ${{ steps.changed-files.outputs.all_changed_files_count }}"
34+
exit 1
35+
fi
36+
for changed_file in ${{ steps.changed-files.outputs.all_changed_files }}; do
37+
export RELEASE_VERSION=$(echo "${changed_file}" | grep -oP '(?<=/)[^/]+(?=\.md)')
38+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> ${GITHUB_ENV}
39+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> ${GITHUB_OUTPUT}
40+
if [[ "${RELEASE_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
41+
echo "Valid semver: ${RELEASE_VERSION}"
42+
else
43+
echo "Invalid semver: ${RELEASE_VERSION}"
44+
exit 1
45+
fi
46+
done
47+
- name: Determine the release branch to use
48+
run: |
49+
if [[ ${RELEASE_VERSION} =~ beta ]] || [[ ${RELEASE_VERSION} =~ alpha ]]; then
50+
export RELEASE_BRANCH=main
51+
echo "RELEASE_BRANCH=${RELEASE_BRANCH}" >> ${GITHUB_ENV}
52+
echo "This is a beta or alpha release, will use release branch ${RELEASE_BRANCH}"
53+
else
54+
export RELEASE_BRANCH=release-$(echo ${RELEASE_VERSION} | sed -E 's/^v([0-9]+)\.([0-9]+)\..*$/\1.\2/')
55+
echo "RELEASE_BRANCH=${RELEASE_BRANCH}" >> ${GITHUB_ENV}
56+
echo "This is not a beta or alpha release, will use release branch ${RELEASE_BRANCH}"
57+
fi
58+
- name: Create or checkout release branch
59+
run: |
60+
if git show-ref --verify --quiet "refs/remotes/origin/${RELEASE_BRANCH}"; then
61+
echo "Branch ${RELEASE_BRANCH} already exists"
62+
git checkout "${RELEASE_BRANCH}"
63+
else
64+
git checkout -b "${RELEASE_BRANCH}"
65+
git push origin "${RELEASE_BRANCH}"
66+
echo "Created branch ${RELEASE_BRANCH}"
67+
fi
68+
- name: Validate tag does not already exist
69+
run: |
70+
if [[ -n "$(git tag -l "${RELEASE_VERSION}")" ]]; then
71+
echo "Tag ${RELEASE_VERSION} already exists, exiting"
72+
exit 1
73+
fi
74+
- name: Create Release Tag
75+
run: |
76+
git config user.name "${GITHUB_ACTOR}"
77+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
78+
git tag -a ${RELEASE_VERSION} -m ${RELEASE_VERSION}
79+
git push origin ${RELEASE_VERSION}
80+
echo "Created tags ${RELEASE_VERSION}"
81+
release:
1482
name: create draft release
1583
runs-on: ubuntu-latest
84+
needs: push_release_tags
85+
permissions:
86+
contents: write # Allow to create a release.
1687
steps:
17-
- name: Set env
18-
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
19-
- name: checkout code
20-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # tag=v5.0.0
21-
with:
22-
fetch-depth: 0
23-
- name: Calculate go version
24-
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV
25-
- name: Set up Go
26-
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # tag=v6.0.0
27-
with:
28-
go-version: ${{ env.go_version }}
29-
- name: generate release artifacts
30-
run: |
31-
make release
32-
- name: generate release notes
33-
# Ignore failures for release-notes generation so they could still get
34-
# generated manually before publishing.
35-
run: |
36-
make generate-release-notes || echo "Failed to generate release notes" >> _releasenotes/${{ env.RELEASE_TAG }}.md
37-
env:
38-
GH_TOKEN: ${{ github.token }}
39-
- name: Release
40-
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # tag=v2.4.1
41-
with:
42-
draft: true
43-
files: out/*
44-
body_path: _releasenotes/${{ env.RELEASE_TAG }}.md
88+
- name: Set env
89+
run: echo "RELEASE_TAG=${RELEASE_TAG}" >> ${GITHUB_ENV}
90+
env:
91+
RELEASE_TAG: ${{needs.push_release_tags.outputs.release_tag}}
92+
- name: checkout code
93+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # tag=v5.0.0
94+
with:
95+
fetch-depth: 0
96+
ref: ${{ env.RELEASE_TAG }}
97+
- name: Calculate go version
98+
run: echo "go_version=$(make go-version)" >> ${GITHUB_ENV}
99+
- name: Set up Go
100+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # tag=v6.0.0
101+
with:
102+
go-version: ${{ env.go_version }}
103+
- name: generate release artifacts
104+
run: |
105+
make release
106+
env:
107+
GH_TOKEN: ${{ github.token }}
108+
- name: get release notes
109+
run: |
110+
curl -L "https://raw.githubusercontent.com/${{ github.repository }}/main/releasenotes/${{ env.RELEASE_TAG }}.md" \
111+
-o "${{ env.RELEASE_TAG }}.md"
112+
- name: Release
113+
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # tag=v2.4.1
114+
with:
115+
draft: true
116+
files: out/*
117+
body_path: ${{ env.RELEASE_TAG }}.md
118+
tag_name: ${{ env.RELEASE_TAG }}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,13 @@ staging-manifests:
448448
## --------------------------------------
449449
##@ Release
450450
## --------------------------------------
451-
452451
ifneq (,$(findstring -,$(RELEASE_TAG)))
453452
PRE_RELEASE=true
454453
endif
455454
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)
456455
## set by Prow, ref name of the base branch, e.g., main
457456
RELEASE_DIR := out
458-
RELEASE_NOTES_DIR := _releasenotes
457+
RELEASE_NOTES_DIR := releasenotes
459458

460459
.PHONY: $(RELEASE_DIR)
461460
$(RELEASE_DIR):
@@ -478,14 +477,15 @@ list-image:
478477
gcloud container images list-tags $(STAGING_REGISTRY)/$(IMAGE) --filter="tags=('$(RELEASE_TAG)')" --format=json
479478

480479
.PHONY: release
481-
release: $(RELEASE_NOTES) clean-release $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
480+
release: $(RELEASE_NOTES) $(RELEASE_DIR) ## Builds and push container images using the latest git tag for the commit.
482481
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
483482
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; fi
484483
git checkout "${RELEASE_TAG}"
485484
# Set the manifest image to the production bucket.
486485
$(MAKE) manifest-modification REGISTRY=$(PROD_REGISTRY)
487486
$(MAKE) release-manifests
488487
$(MAKE) release-templates
488+
$(MAKE) generate-release-notes
489489

490490
.PHONY: manifest-modification
491491
manifest-modification: # Set the manifest images to the staging/production bucket.

0 commit comments

Comments
 (0)