-
Notifications
You must be signed in to change notification settings - Fork 7
195 lines (166 loc) · 7.13 KB
/
release.yaml
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
name: Release Charts
on:
workflow_dispatch:
inputs:
branch:
description: "Target branch to release"
default: "main"
base-branch:
description: "The base branch to compare the version"
jobs:
tests:
uses: ./.github/workflows/lint-test.yaml
find-charts-to-release:
runs-on: ubuntu-latest
needs: [tests]
outputs:
modified-charts-files: ${{ steps.list-changed-charts.outputs.all_modified_files }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- name: Get list of changed charts
id: list-changed-charts
uses: tj-actions/changed-files@v42
with:
base_sha: ${{ github.event.inputs.base-branch }}
files: charts/*/Chart.yaml
generate-charts-changelog:
needs: find-charts-to-release
if: needs.find-charts-to-release.outputs.modified-charts-files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- uses: Bpazy/setup-git-chglog@v1
with:
git-chglog-version: "0.15.4"
- name: Generate charts changelog files
shell: bash
run: |
set -x
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update && sudo apt install yq -y
for chart_file in ${{ needs.find-charts-to-release.outputs.modified-charts-files }}; do
chart_name=$(grep -Po "(?<=^name: ).+" ${chart_file})
chart_version=$(grep -Po "(?<=^version: ).+" ${chart_file})
chart_tag="${chart_name}@${chart_version}"
chart_path="charts/${chart_name}"
#
# Generate chart CHANGELOG.md file.
git-chglog \
--output "${chart_path}/CHANGELOG.md" \
--tag-filter-pattern "${chart_name}" \
--next-tag "${chart_tag}" \
--path "${chart_path}"
#
# Generate RELEASE-NOTES.md file (used for Github release notes and ArtifactHub "changes" annotation).
git-chglog \
--output "${chart_path}/RELEASE-NOTES.md" \
--tag-filter-pattern "${chart_name}" \
--next-tag "${chart_tag}" \
--path "${chart_path}" "${chart_tag}"
#
# Update ArtifactHub "changes" annotation in the Chart.yaml file.
# https://artifacthub.io/docs/topics/annotations/helm/#supported-annotations
change_types="Added Changed Deprecated Removed Fixed Security"
# TODO: Rethink about this approach of using bash to generate YAML changes for ArtifactHub,
# and find out if there is a better/cleaner way to make it.
echo '|' > "${chart_path}/changes-for-artifacthub.yaml"
for change_type in ${change_types}; do
change_type_section=$(sed -rn "/^\#+\s${change_type}/,/^(#|$)/p" "${chart_path}/RELEASE-NOTES.md")
if [[ -n "${change_type_section}" ]]; then
echo "${change_type_section}" | egrep '^-' | sed 's/^- //g' | while read commit_message; do
echo " - kind: ${change_type,,}"
echo " description: \"${commit_message}\""
done >> "${chart_path}/changes-for-artifacthub.yaml"
fi
done
cat "${chart_path}/changes-for-artifacthub.yaml"
# Merge changes back to the Chart.yaml file.
yq eval-all \
'select(fileIndex==0).annotations."artifacthub.io/changes" = select(fileIndex==1) | select(fileIndex==0)' \
${chart_path}/Chart.yaml ${chart_path}/changes-for-artifacthub.yaml > \
${chart_path}/Chart-with-artifacthub-changes.yaml
mv ${chart_path}/Chart-with-artifacthub-changes.yaml ${chart_path}/Chart.yaml
done
- name: Stash generated charts changelog files
uses: actions/upload-artifact@v4
with:
name: charts-generated-changelog
path: |
charts/*/RELEASE-NOTES.md
charts/*/CHANGELOG.md
charts/*/Chart.yaml
release-charts:
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: write
needs: generate-charts-changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- name: Unstash generated charts changelog files
uses: actions/download-artifact@v4
with:
name: charts-generated-changelog
path: charts
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/[email protected]
- name: Add dependencies
run: |
helm repo add dex https://charts.dexidp.io
helm repo add prometheus https://prometheus-community.github.io/helm-charts
helm repo add jaeger https://jaegertracing.github.io/helm-charts
- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
commit-charts-changelog:
needs:
- find-charts-to-release
- release-charts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- name: Unstash generated charts changelog files
uses: actions/download-artifact@v4
with:
name: charts-generated-changelog
path: charts
- name: Commit charts CHANGELOG.md file
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
released_charts_files="${{ needs.find-charts-to-release.outputs.modified-charts-files }}"
echo "released_charts_files: ${released_charts_files}"
# Commit changes locally.
chart_names=""
for chart_file in ${released_charts_files}; do
chart_name=$(grep -Po "(?<=^name: ).+" ${chart_file})
chart_version=$(grep -Po "(?<=^version: ).+" ${chart_file})
chart_path="charts/${chart_name}"
git add ${chart_path}/CHANGELOG.md
chart_names="${chart_names} ${chart_name}:${chart_version}"
done
git commit -m "Update CHANGELOG for charts ${chart_names}"
# Push changes to the main branch.
git push origin "${GITHUB_REF##*/}":main