-
Notifications
You must be signed in to change notification settings - Fork 16
170 lines (153 loc) · 5.67 KB
/
auto-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
name: Auto Release Version
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
#- name: release Z branch
# uses: peterjgrainger/action-create-branch@v2.4.0
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# branch: 'release-${{ env.RUN_TAG }}'
# sha: '${{ github.sha }}'
# if branch exists, the action will no fail, and it output created=false
- name: release Y branch
uses: peterjgrainger/action-create-branch@v2.4.0
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 ; if [ $? -ne 0 ]; then echo -e "\e[31merror, failed to create label ${branchLabelName}\e[0m"; fi
gh label create ${mainLabelName} --force ; if [ $? -ne 0 ]; then echo -e "\e[31merror, failed to create label ${mainLabelName}\e[0m"; fi
build-release-image:
needs: get-tag
uses: ./.github/workflows/build-image-release.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
release-pages:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-pages.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 }}
secrets: inherit
create-release:
needs: [release-changelog, get-tag, release-chart]
name: create release
runs-on: ubuntu-latest
steps:
- name: Download Chart Artifact
uses: actions/download-artifact@v3.0.2
with:
name: ${{ needs.release-chart.outputs.artifact }}
path: chart-package/
- name: Download Changelog Artifact
uses: actions/download-artifact@v3.0.2
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 "RUN_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 "RUN_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/release-action@v1.13.0
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 }}"