-
Notifications
You must be signed in to change notification settings - Fork 76
172 lines (155 loc) · 5.95 KB
/
auto-version-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
name: Auto Version Release
# it is trigger by tag event:
# 1 build the release image, push images to ghcr.io, and build image like: ghcr.io/weizhoublue/github-action-test/controllerimage:v1.0.0
# 2 package the chart package, update index.yaml and commit to '/charts' of branch 'github_pages' ( PR with label pr/release/robot_update_githubpage )
# 3 create changelog file, commit to '/changelogs' of branch 'github_pages' for githubPage ( PR with label pr/release/robot_update_githubpage )
# 4 commit '/docs' to '/docs' of branch 'github_pages'
# 5 create a release , attached with the chart and changelog
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: true
default: v1.0.0
permissions: write-all
jobs:
get-tag:
runs-on: ubuntu-latest
outputs:
tag: ${{ env.RUN_TAG }}
steps:
- name: Get Ref
id: get_ref
run: |
if ${{ github.event_name == 'workflow_dispatch' }} ; then
echo "call by self workflow_dispatch"
echo "RUN_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
YBranchName=` grep -Eo "v[0-9]+\.[0-9]+" <<< "${{ github.event.inputs.tag }}" `
elif ${{ github.event_name == 'push' }} ; then
echo "call by push tag"
echo "RUN_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
YBranchName=` grep -Eo "v[0-9]+\.[0-9]+" <<< "${GITHUB_REF##*/}" `
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
echo "YBranchName=${YBranchName}"
if [ -n "$YBranchName" ] ; then
echo "RUN_YBranchName=${YBranchName}" >> $GITHUB_ENV
else
echo "error, failed to find y branch"
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.RUN_TAG }}
- name: Check Version
run: |
TagVersion="${{ env.RUN_TAG }}"
RecordVersion=` cat VERSION | tr -d ' ' | tr -d '\n' `
if [ "$RecordVersion" != "$TagVersion" ] ; then
echo "error, version $RecordVersion of '/VERSION' is different with Tag $TagVersion "
exit 1
fi
#no need to check chart version, which will auto update to /VERSION by CI
# if branch exists, the action will no fail, and it output created=false
- name: release Y branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: 'release-${{ env.RUN_YBranchName }}'
sha: '${{ github.sha }}'
# for auto-cherrypick.yaml, create a label
- name: Create cherry-pick label
continue-on-error: true
run: |
echo ${{ secrets.WELAN_PAT }} | gh auth login --with-token
branchLabelName="${{ env.LABEL_PREFIX_CHERRYPICK }}release-${{ env.RUN_YBranchName }}"
mainLabelName="${{ env.LABEL_PREFIX_CHERRYPICK }}main"
echo "try to create label "
gh label create ${branchLabelName} --force
(( $? !=0 )) && echo "error, failed to create label ${branchLabelName}"
gh label create ${mainLabelName} --force
(( $? !=0 )) && echo "error, failed to create label ${mainLabelName}"
build-release-image:
needs: get-tag
uses: ./.github/workflows/call-release-image.yaml
with:
ref: ${{ needs.get-tag.outputs.tag }}
secrets: inherit
release-chart:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-chart.yaml
with:
ref: ${{ needs.get-tag.outputs.tag }}
submit: true
secrets: inherit
release-doc:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-doc.yaml
with:
ref: ${{ needs.get-tag.outputs.tag }}
secrets: inherit
release-changelog:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-changelog.yaml
with:
dest_tag: ${{ needs.get-tag.outputs.tag }}
secrets: inherit
create-release:
needs: [release-chart, release-changelog, get-tag]
name: create release
runs-on: ubuntu-latest
steps:
- name: Download Chart Artifact
uses: actions/download-artifact@v3
with:
name: ${{ needs.release-chart.outputs.artifact }}
path: chart-package/
- name: Download Changelog Artifact
uses: actions/download-artifact@v3
with:
name: ${{ needs.release-changelog.outputs.artifact }}
path: changelog-result/
- name: Get Downloaded Files
id: download_file
run: |
# ========= chart
if ! ls chart-package/*.tgz &>/dev/null ; then
echo "error, failed to find any chart "
exit 1
fi
chart_path=$( ls chart-package/*.tgz )
echo "chart_path=${chart_path}" >> $GITHUB_ENV
# ========== changelog
if ! ls changelog-result/*.md &>/dev/null ; then
echo "error, failed to find changelog "
exit 2
fi
ls changelog-result/
cat changelog-result/*.md
changelog_file=$( ls changelog-result/ )
changelog_path=./changelog-result/${changelog_file}
echo "changelog_path=${changelog_path}" >> $GITHUB_ENV
cp ./changelog-result/${changelog_file} ./changelog-result/changelog.md
- name: Create Release
id: create_release
continue-on-error: false
uses: ncipollo/[email protected]
with:
artifacts: "chart-package/*"
allowUpdates: true
removeArtifacts: true
replacesArtifacts: true
artifactErrorsFailBuild: true
bodyFile: "./changelog-result/changelog.md"
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.get-tag.outputs.tag }}
name: "Release ${{ needs.get-tag.outputs.tag }}"