-
Notifications
You must be signed in to change notification settings - Fork 0
217 lines (188 loc) · 6.82 KB
/
Copy pathrelease.yml
File metadata and controls
217 lines (188 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Create release
run-name: ${{ inputs.releaseversion }}
on:
workflow_dispatch:
inputs:
releaseversion:
description: 'Release version'
required: true
type: string
default: 'X.Y.Z'
jobs:
release:
name: Release
runs-on: ubuntu-latest
env:
DOCKERFILE: ./Dockerfile
DOCKER_IMAGE_NAME: cloudtooling/wordpress
permissions:
contents: write
packages: write
attestations: write
id-token: write
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
app-id: ${{ vars.CI_APP_ID }}
private-key: ${{ secrets.CI_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.head_ref }}
- name: Write version vars
run: |
BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
BRANCH=${GITHUB_REF_NAME#v}
APP_VERSION=${{ github.event.inputs.releaseversion }}
echo Version: $APP_VERSION
echo "VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
- name: Install Helm
uses: azure/setup-helm@v5
- name: Install Python
uses: actions/setup-python@v7
with:
python-version: '3.14'
check-latest: true
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.8.0
with:
version: v3.14.0
yamale_version: '6.0.0'
- name: Set up helm-docs
uses: gabe565/setup-helm-docs-action@v1
- name: Run chart-testing (lint)
run: ct lint --config .ct.yaml
- name: Helm Package
run: |
# Increment a version string using Semantic Versioning (SemVer) terminology.
# Parse command line options.
# Source: https://github.com/fmahnke/shell-semver
#
# usage: increment_version.sh [-Mmp] major.minor.patch
increment_version() {
while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
* ) patch=true;;
esac
done
# shellcheck disable=SC2004,SC2206
shift $(($OPTIND - 1))
version=$1
# Build array from version string.
# shellcheck disable=SC2206
a=( ${version//./ } )
# If version string is missing or has the wrong number of members, show usage message.
if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi
# Increment version numbers as requested.
if [ -n "$major" ]
then
((a[0]++))
a[1]=0
a[2]=0
fi
if [ -n "$minor" ]
then
((a[1]++))
a[2]=0
fi
if [ -n "$patch" ]
then
((a[2]++))
fi
echo "${a[0]}.${a[1]}.${a[2]}"
}
export HELM_CHART_DIR=charts/wordpress
chartVersion=$(cat $HELM_CHART_DIR/Chart.yaml | grep "version: " | sed -E -n "s/^version: \s*(.*)$/\1/p")
appVersion=$(cat $HELM_CHART_DIR/Chart.yaml | grep "appVersion: " | sed -E -n "s/^appVersion: \s*(.*)$/\1/p")
newVersion=$(increment_version -p $chartVersion)
sed -i 's/version: '"$chartVersion"'/version: '"$newVersion"'/g' $HELM_CHART_DIR/Chart.yaml
sed -i 's/appVersion: '"$appVersion"'/appVersion: '"${{ github.event.inputs.releaseversion }}"'/g' $HELM_CHART_DIR/Chart.yaml
helm-docs
helm package $HELM_CHART_DIR
git add .
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure Git author
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build & Push Container Image
id: build-and-push-image
uses: docker/build-push-action@v7
with:
context: .
file: ${{env.DOCKERFILE}}
push: true
tags: |
${{env.DOCKER_IMAGE_NAME}}:latest
${{env.DOCKER_IMAGE_NAME}}:${{ github.run_id }}
${{env.DOCKER_IMAGE_NAME}}:${{ env.APP_VERSION }}
build-args: |
BUILD_DATE=${{env.BUILD_DATE}}
APP_VERSION=${{env.APP_VERSION}}
platforms: linux/amd64,linux/arm64
- name: Login to GitHub Container Registry
run: |
echo ${{ secrets.CT_OCI_GITHUB_TOKEN }} | helm registry login ghcr.io -u $ --password-stdin
- name: Push Charts to GHCR
run: |
shopt -s nullglob
for pkg in *.tgz; do
if [ -z "${pkg:-}" ]; then
break
fi
helm push "${pkg}" oci://ghcr.io/cloudtooling/helm-charts
done
rm *.tgz
- name: Generate Changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --tag v${{ inputs.releaseversion }} --prepend CHANGELOG.md --unreleased
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Add Changelog
run: |
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "chore(release): update changelog for v${{ inputs.releaseversion }}"
- name: Trigger changes
run: |
RELEASE_VERSION="${{ github.event.inputs.releaseversion }}"
echo "{\"version\":\"${RELEASE_VERSION}\"}" | jq > config.json
git add .
git commit -m "Release ${RELEASE_VERSION}"
git tag v${{ github.event.inputs.releaseversion }}
git push --tags
git push
- name: Create GH release
uses: softprops/action-gh-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ github.event.inputs.releaseversion }}
tag_name: v${{ github.event.inputs.releaseversion }}
draft: true