-
Notifications
You must be signed in to change notification settings - Fork 30
236 lines (218 loc) · 8.17 KB
/
release-chart.yml
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: Manually Release Chart
env:
MERGE_BRANCH: gh-pages
PR_LABEL: pr/release/robot_update_githubpage
PR_REVIWER: weizhoublue
DAOCLOUD_HARBOR_URL: https://release.daocloud.io
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
inputs:
project:
description: 'project name.[ leave empty for all projects]'
required: false
ref:
description: 'branch name, tag or sha'
required: true
default: main
daocloud:
description: 'enable push to daocloud repo'
required: true
type: boolean
default: true
workflow_call:
inputs:
project:
required: true
type: string
ref:
required: true
type: string
justpush:
required: true
type: string
permissions: write-all
jobs:
package:
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.get_ref.outputs.ref }}
steps:
- name: Get Ref
id: get_ref
run: |
if ${{ inputs.project != '' }} ; then
echo "trigger by workflow_call"
echo ::set-output name=project::${{ inputs.project }}
echo ::set-output name=release::true
echo ::set-output name=ref::${{ inputs.ref }}
echo ::set-output name=publishversion::true
elif ${{ github.event_name == 'workflow_dispatch' }} ; then
echo "call by self workflow_dispatch"
if ${{ github.event.inputs.project == '' }} ; then
echo ::set-output name=project::all
else
echo ::set-output name=project::${{ github.event.inputs.project }}
fi
# release to github pages
echo ::set-output name=release::${{ github.event.inputs.daocloud }}
echo ::set-output name=ref::${{ github.event.inputs.ref }}
echo ::set-output name=publishversion::false
elif ${{ github.event_name == 'push' }} ; then
echo "call by tag push"
echo ::set-output name=project::all
echo ::set-output name=release::true
# release to github pages
echo ::set-output name=ref::${GITHUB_REF##*/}
echo ::set-output name=publishversion::true
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
# some event, the tag is not sha, so checkout it and get sha
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ steps.get_ref.outputs.ref }}
- name: Result Ref
id: result
run: |
ref=$( git show -s --format='format:%H')
echo ::set-output name=ref::${ref}
- name: Set up Helm
uses: azure/[email protected]
- name: package chart
id: package
run: |
ROOT_DIR=`pwd`
project_list="${{ steps.get_ref.outputs.project }}"
if [ "$project_list" == "all" ] || [ -z "$project_list" ] ; then
project_list=""
TMP=`ls charts`
for ITEM in $TMP ; do
if [ -d "${ROOT_DIR}/charts/${ITEM}/${ITEM}" ] ; then
project_list+=" $ITEM "
fi
done
fi
mkdir _upload
cd _upload
for ITEM in $project_list ; do
[ ! -d "${ROOT_DIR}/charts/${ITEM}/${ITEM}" ] && echo "error, failed to find project $ITEM in /charts" && exit 1
helm package ${ROOT_DIR}/charts/${ITEM}/${ITEM}
echo "package ${ITEM}"
done
echo "---------finish--------"
ls
echo ::set-output name=project_list::${project_list}
- name: Upload chart artifact
uses: actions/[email protected]
with:
name: charts
path: _upload
retention-days: 1
- name: Install helm-push
if: ${{ steps.get_ref.outputs.release == 'true' }}
run: |
helm plugin install https://github.com/chartmuseum/helm-push
- name: push to daocloud
if: ${{ steps.get_ref.outputs.release == 'true' }}
run: |
ROOT_DIR=`pwd`
cd _upload
set -x
RETRY_NUMBER=100
FAILED_CHART=""
SUCCEED_CHART=""
for ITEM in ${{ steps.package.outputs.project_list }} ; do
DAO_PROJECT=` grep "DAOCLOUD_REPO_PROJECT" ${ROOT_DIR}/charts/${ITEM}/config | awk -F= '{print $2}' | tr -d ' ' `
[ -z "$DAO_PROJECT" ] && echo "error, failed to find DAOCLOUD_REPO_PROJECT config in charts/${ITEM}/config " && exit 1
CHART_FILE=` ls | grep -o -E "^${ITEM}-[v0-9]+.[0-9]+.[0-9]+.*.tgz" `
[ ! -f "${CHART_FILE}" ] && echo "error, failed to find chart.tgz for $ITEM " && ls && exit 2
DAO_ADDRESS=${{ env.DAOCLOUD_HARBOR_URL }}/chartrepo/${DAO_PROJECT}
echo "push $CHART_FILE to $DAO_ADDRESS "
BAD=true
for ((N=0;N<RETRY_NUMBER;N++)); do
helm repo add daocloud-${DAO_PROJECT} ${DAO_ADDRESS} --username=${{ secrets.DAOCLOUD_HARBOR_USER }} --password=${{ secrets.DAOCLOUD_HARBOR_PASSWORD }} || { sleep 2 ; continue ; }
BAD="" && break
done
if [ "$BAD" != "true" ] ; then
BAD=true
for ((N=0;N<RETRY_NUMBER;N++)); do
helm cm-push ${CHART_FILE} daocloud-${DAO_PROJECT} --username=${{ secrets.DAOCLOUD_HARBOR_USER }} --password=${{ secrets.DAOCLOUD_HARBOR_PASSWORD }} || { sleep 2 ; continue ; }
BAD="" && break
done
fi
if [ "$BAD" == "true" ] ; then
echo "error, failed to helm push ${CHART_FILE} "
FAILED_CHART+=" ${CHART_FILE} "
else
echo "succeeded to helm push ${CHART_FILE} "
SUCCEED_CHART+=" ${CHART_FILE} "
fi
done
echo "============== result =========="
echo "SUCCEED_CHART: ${SUCCEED_CHART}"
echo ""
echo "FAILED_CHART: ${FAILED_CHART}"
if [ -n "$FAILED_CHART" ]; then
exit 1
fi
exit 0
#- name: Create Release
# id: create_release
# if: ${{ steps.get_ref.outputs.publishversion == 'true' }}
# uses: ncipollo/[email protected]
# with:
# artifacts: "_upload/*"
# allowUpdates: true
# removeArtifacts: true
# replacesArtifacts: true
# artifactErrorsFailBuild: true
# token: ${{ secrets.GITHUB_TOKEN }}
# tag: ${{ steps.get_ref.outputs.ref }}
# name: "Release ${{ steps.get_ref.outputs.ref }}"
# update /index.yaml in the target branch
update_githubpage:
runs-on: ubuntu-latest
needs: [package]
if: ${{ inputs.justpush != 'true' }}
steps:
- name: Get Base Chart URL
id: get_base_url
run: |
name=${{ github.repository }}
proj=${name#*/}
url=https://${{ github.repository_owner }}.github.io/${proj}
echo "::set-output name=url::${url}"
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ env.MERGE_BRANCH }}
persist-credentials: "true"
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: charts
path: ./
- name: Update Chart Yaml
run: |
ls
helm repo index ./ --url ${{ steps.get_base_url.outputs.url }}
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
title: "robot Update chart to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot Update chart from ${{ needs.package.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_chart
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.WELAN_PAT }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}