forked from sunggun-yu/meowhq-helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (152 loc) · 5.67 KB
/
release-please.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
name: release-please
on:
push:
branches:
- main
paths:
- "charts/**"
jobs:
release-please:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
releases_created: ${{ steps.release.outputs.releases_created }}
steps:
# PR should not be triggered by repository's token to trigger GHA for auto approval
# so, use github apps token instead of repository token
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
# - id: app-token
# uses: actions/create-github-app-token@v1
# with:
# app-id: ${{ secrets.APP_ID }}
# private-key: ${{ secrets.PRIVATE_KEY }}
- id: release
uses: google-github-actions/release-please-action@v4
with:
token: ${{ secrets.PAT_TOKEN }}
get-bumped-charts:
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.releases_created }}
name: 'Get modified charts'
permissions:
contents: read
outputs:
charts: ${{ steps.get-bumped-charts.outputs.charts }}
result: ${{ steps.get-bumped-charts.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # to be able to obtain files changed in the latest commit
- id: get-bumped-charts
name: 'Get modified charts'
run: |
# get the changed files
files_changed="$(git show --pretty="" --name-only)"
echo "files_changed=$files_changed"
# get the directories that includes Chart.yaml file changes to get the charts that changed version
chart_file_changed="$(echo $files_changed | grep -E 'Chart\.ya?ml' | xargs dirname | grep -o "charts/[^/]*" | sort | uniq || true)"
# Initialize an empty array for version-changed charts
version_changed_charts=()
for chart in $chart_file_changed; do
# Check if there's a version change in the Chart.yaml file
if git show "$chart" | grep -q "+version"; then
version_changed_charts+=("$chart")
fi
done
# make the outputs
if [ ${#version_changed_charts[@]} -gt 0 ]; then
echo "charts=${version_changed_charts[@]}" >>$GITHUB_OUTPUT
echo "result=ok" >>$GITHUB_OUTPUT
else
echo "error=No version changed charts found" >>$GITHUB_OUTPUT
echo "result=fail" >>$GITHUB_OUTPUT
fi
# print the outputs
cat $GITHUB_OUTPUT
- id: show-warning
name: 'Show Warning'
if: ${{ steps.get-bumped-charts.outputs.result == 'fail' }}
run: |
echo "${{ steps.get-bumped-charts.outputs.error }}"
echo "publish jobs/steps will be interrupted"
# uses: actions/github-script@v6
# with:
# script: |
# core.setFailed('${{ steps.get-bumped-charts.outputs.error }}')
publish-charts:
runs-on: self-hosted
needs: get-bumped-charts
if: ${{ needs.get-bumped-charts.outputs.result == 'ok' }}
name: Publish Charts to registry
permissions:
contents: read
env:
PUBLISH_DIR: ".target"
steps:
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.13.0
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build the package of updated Charts
id: package-charts
run: |
rm -rf $PUBLISH_DIR && mkdir -p $PUBLISH_DIR
version_changed_charts="${{needs.get-bumped-charts.outputs.charts}}"
for dir in ${version_changed_charts}; do
helm package $dir --dependency-update --destination $PUBLISH_DIR
done
- name: Publish Charts to repository
id: push-charts-repository
run: |
# install helm plugin helm-push to publish chart to "repository"
helm plugin install https://github.com/chartmuseum/helm-push
# Use a for loop to packaged each .tgz file in the $PUBLISH_DIR directory
for file in "$PUBLISH_DIR"/*.tgz; do
if [ -f "$file" ]; then
echo "Publishing $file to Helm Repository"
helm cm-push \
--username ${{ secrets.HELM_REPO_USERNAME }} \
--password ${{ secrets.HELM_REPO_PASSWORD }} \
$file \
https://chartmuseum.lab.meowhq.dev
fi
done
- name: Publish Charts to OCI Registry
id: push-charts-oci
run: |
# login to oci registry
echo '${{ secrets.HARBOR_CICD_PASSWORD }}' | \
helm registry login --username '${{ secrets.HARBOR_CICD_USERNAME }}' \
--password-stdin \
harbor.lab.meowhq.dev
# Use a for loop to packaged each .tgz file in the $PUBLISH_DIR directory
for file in "$PUBLISH_DIR"/*.tgz; do
if [ -f "$file" ]; then
echo "Publishing $file to OCI Registry"
helm push $file oci://harbor.lab.meowhq.dev/charts
fi
done
# this is currently in test
publish-charts-github-release:
runs-on: ubuntu-latest
needs: get-bumped-charts
if: ${{ needs.get-bumped-charts.outputs.result == 'ok' }}
name: Publish Charts to Github
permissions:
contents: write
packages: write
pages: write
steps:
- uses: actions/checkout@v4
name: Checkout Repository
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
env:
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}