Skip to content

Commit b17fa0a

Browse files
authored
Automate release (#461)
1 parent 5058ba4 commit b17fa0a

File tree

5 files changed

+154
-17
lines changed

5 files changed

+154
-17
lines changed

.github/workflows/branch-build.yaml

+1-14
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ on:
1717
- "!**.md"
1818
branches:
1919
- "main"
20-
- "release-0.2"
21-
- "release-0.3"
22-
- "release-0.4"
20+
- "release-*"
2321

2422
jobs:
2523
entry-tests:
2624
name: Lint and test code
2725
runs-on: ubuntu-latest
2826
permissions:
2927
contents: read
30-
3128
steps:
3229
- name: Checkout code
3330
uses: actions/checkout@v2
@@ -56,7 +53,6 @@ jobs:
5653
matrix-infra: ${{ steps.set-matrix-infra.outputs.matrix }}
5754
permissions:
5855
contents: read
59-
6056
steps:
6157
- name: Checkout code
6258
uses: actions/checkout@v2
@@ -80,7 +76,6 @@ jobs:
8076
permissions:
8177
contents: read
8278
packages: write
83-
8479
steps:
8580
- name: Checkout code
8681
uses: actions/checkout@v2
@@ -101,7 +96,6 @@ jobs:
10196
permissions:
10297
contents: read
10398
packages: write
104-
10599
steps:
106100
- name: Checkout code
107101
uses: actions/checkout@v2
@@ -123,7 +117,6 @@ jobs:
123117
permissions:
124118
contents: read
125119
packages: write
126-
127120
steps:
128121
- name: Checkout code
129122
uses: actions/checkout@v2
@@ -141,7 +134,6 @@ jobs:
141134
if: github.ref == 'refs/heads/main'
142135
permissions:
143136
contents: read
144-
145137
steps:
146138
- name: Checkout code
147139
uses: actions/checkout@v2
@@ -164,7 +156,6 @@ jobs:
164156
permissions:
165157
contents: read
166158
packages: write
167-
168159
steps:
169160
- name: Checkout
170161
uses: actions/checkout@v2
@@ -207,7 +198,6 @@ jobs:
207198
needs: [ entry-tests, build-app, build-tests ]
208199
permissions:
209200
contents: read
210-
211201
steps:
212202
- name: Checkout code
213203
uses: actions/checkout@v2
@@ -248,7 +238,6 @@ jobs:
248238
if: github.ref == 'refs/heads/main'
249239
permissions:
250240
contents: read
251-
252241
env:
253242
CAPACT_CREDENTIALS_STORE_FILE_PASSPHRASE: "no-pass"
254243
CAPACT_CREDENTIALS_STORE_BACKEND: "file"
@@ -287,13 +276,11 @@ jobs:
287276
--namespace 'capact-system' \
288277
--phase 'SUCCEEDED'
289278
290-
291279
slackNotification:
292280
name: Slack Notification
293281
runs-on: ubuntu-latest
294282
needs: [ update-cluster ]
295283
if: always()
296-
297284
steps:
298285
- name: Slack Notification
299286
if: ${{ always() && needs.update-cluster.result != 'success' }}

.github/workflows/make-release.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Make release
2+
3+
# Required secrets:
4+
# GCS_CREDS - Credentials to Google Cloud Storage for binary and chart releases
5+
# GH_PAT - GitHub username with personal access token with permissions to make commits to repository, must be in format "<username>:<PAT>"
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: Version in SemVer (e.g. '0.5.0')
12+
required: true
13+
14+
jobs:
15+
make-release:
16+
name: Make release
17+
runs-on: ubuntu-latest
18+
environment: Release
19+
permissions:
20+
contents: write
21+
packages: write
22+
pull-requests: read
23+
issues: read
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
with:
28+
persist-credentials: false
29+
- name: Setup Git credentials
30+
# Replacing the GH Action token with PAT is required to trigger the branch-build workflow on a commit:
31+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
32+
run: |
33+
git remote remove origin
34+
git remote add origin https://${{secrets.GH_PAT}}@github.com/${{github.repository}}.git
35+
git config --global user.email "[email protected]"
36+
git config --global user.name "Capact Bot"
37+
- name: Setup environment
38+
run: |
39+
. ./hack/ci/setup-env.sh
40+
- name: Set up Go
41+
uses: actions/setup-go@v2
42+
with:
43+
go-version: ${{env.GO_VERSION}}
44+
- name: Set up GoReleaser
45+
run: go install github.com/goreleaser/[email protected]
46+
- name: Set up GCS
47+
uses: google-github-actions/setup-gcloud@master
48+
with:
49+
service_account_key: ${{ secrets.GCS_CREDS }}
50+
export_default_credentials: true
51+
- name: Log into registry
52+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
53+
- name: Push release commits and tag
54+
env:
55+
RELEASE_VERSION: "${{ github.event.inputs.version }}"
56+
run: ./hack/make-release.sh
57+
- name: Run GoReleaser
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
run: make release-binaries
61+
- name: Generate release notes
62+
run: |
63+
npm install -g github-release-notes
64+
gren release -d -T "${{ secrets.GITHUB_TOKEN }}" --tags "v${{ github.event.inputs.version }}" --override
65+
- name: Release Helm charts
66+
run: make release-charts

.goreleaser.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ builds:
1919
- linux
2020
- windows
2121
- darwin
22+
goarch: &build-arch
23+
- "386"
24+
- amd64
25+
- arm64
2226
hooks: &build-hooks
2327
# Install upx first, https://github.com/upx/upx/releases
2428
post: upx -9 "{{ .Path }}"
@@ -32,6 +36,7 @@ builds:
3236
- id: populator
3337
env: *build-env
3438
goos: *build-goos
39+
goarch: *build-arch
3540
hooks: *build-hooks
3641
main: ./cmd/populator
3742
binary: 'populator-{{ .Os }}-{{ .Arch }}'
@@ -73,6 +78,6 @@ blobs:
7378
folder: '{{ .Tag }}'
7479

7580
release:
76-
# You can disable this pipe in order to not upload any artifacts.
77-
# Defaults to false.
78-
disable: true
81+
github:
82+
owner: capactio
83+
name: capact

.grenrc.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dataSource: prs
2+
groupBy:
3+
"🚨 Breaking": [breaking]
4+
"🔧 Bug Fixes": [bug]
5+
"🚀 Enhancements": [enhancement]
6+
template:
7+
issue: "- {{name}} [{{text}}]({{url}}) ([@{{user_login}}]({{user_url}}))"
8+
group: "\n### {{heading}}\n"

hack/make-release.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
6+
REPO_ROOT_DIR=$(cd "${CURRENT_DIR}/.." && pwd)
7+
readonly CURRENT_DIR
8+
readonly REPO_ROOT_DIR
9+
10+
11+
release::update_helm_charts_version() {
12+
local -r release_version="$1"
13+
local -r deploy_dir="${REPO_ROOT_DIR}/deploy/kubernetes/charts"
14+
15+
for d in "${deploy_dir}"/*/ ; do
16+
sed -i.bak "s/^version: .*/version: ${release_version}/g" "${d}/Chart.yaml"
17+
done
18+
}
19+
20+
release::make_prepare_release_commit() {
21+
local -r version="$1"
22+
local -r branch="$2"
23+
24+
git add .
25+
git commit -m "Prepare ${version} release"
26+
git push origin "${branch}"
27+
}
28+
29+
release::set_capact_images_in_charts() {
30+
local -r image_tag="$1"
31+
sed -E -i.bak "s/overrideTag: \".+\"/overrideTag: \"${image_tag}\"/g" "${REPO_ROOT_DIR}/deploy/kubernetes/charts/capact/values.yaml"
32+
}
33+
34+
release::set_hub_manifest_source_branch() {
35+
local -r branch="$1"
36+
sed -E -i.bak "s/branch: .+/branch: ${branch}/g" "${REPO_ROOT_DIR}/deploy/kubernetes/charts/capact/charts/hub-public/values.yaml"
37+
}
38+
39+
release::make_release_commit() {
40+
local -r version="$1"
41+
local -r release_branch="$2"
42+
local -r tag="v${version}"
43+
44+
git add .
45+
git commit -m "Set fixed Capact image tag and Populator source branch"
46+
git tag "${tag}"
47+
git push origin "${release_branch}"
48+
git push origin "${tag}"
49+
}
50+
51+
# required inputs:
52+
# RELEASE_VERSION - new version in SemVer format: x.y.z
53+
[ -z "${RELEASE_VERSION}" ] && echo "Need to set RELEASE_VERSION" && exit 1;
54+
55+
SOURCE_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
56+
RELEASE_VERSION_MAJOR_MINOR="$(echo "${RELEASE_VERSION}" | sed -E 's/([0-9]+\.[0-9])\.[0-9]/\1/g')"
57+
RELEASE_BRANCH="release-${RELEASE_VERSION_MAJOR_MINOR}"
58+
59+
main() {
60+
release::update_helm_charts_version "${RELEASE_VERSION}"
61+
release::make_prepare_release_commit "${RELEASE_VERSION}" "${SOURCE_BRANCH}"
62+
63+
local -r capact_image_tag=$(git rev-parse --short HEAD | sed 's/.$//')
64+
git checkout -B "${RELEASE_BRANCH}"
65+
66+
release::set_capact_images_in_charts "${capact_image_tag}"
67+
release::set_hub_manifest_source_branch "${RELEASE_BRANCH}"
68+
release::make_release_commit "${RELEASE_VERSION}" "${RELEASE_BRANCH}"
69+
}
70+
71+
main

0 commit comments

Comments
 (0)