This repository was archived by the owner on May 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (87 loc) · 3.44 KB
/
update-app-version.yml
File metadata and controls
98 lines (87 loc) · 3.44 KB
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
name: Update chart appVersion
on:
workflow_dispatch:
inputs:
chart:
description: "name fo chart"
required: true
version:
description: "new appVersion"
required: true
repository_dispatch:
types: [update_chart_version]
jobs:
check_vars:
runs-on: ubuntu-latest
outputs:
chart: ${{ steps.eval.outputs.chart }}
appVersion: ${{ steps.eval.outputs.appVersion }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: check workflow_dispatch or repository_dispatch
id: eval
shell: bash
run: |
if [ "${{ github.event.inputs.chart }}" != "" ]; then
echo "::set-output name=chart::${{ github.event.inputs.chart }}"
echo "::set-output name=appVersion::${{ github.event.inputs.version }}"
else
echo "::set-output name=chart::${{ github.event.client_payload.chart }}"
echo "::set-output name=appVersion::${{ github.event.client_payload.version }}"
fi
- name: check chart
shell: bash
env:
valid: '0-9a-zA-Z\-\_'
run: |
if [ ! -d "charts/${{ steps.eval.outputs.chart }}" ]; then
echo "Chart ${{ steps.eval.outputs.chart }} does not exist. Canceling update..."
exit 1
else
if [[ ! "${{ steps.eval.outputs.appVersion }}" =~ [^$valid] ]]; then
echo "appVersion does not match regex ${{ steps.eval.outputs.appVersion }}, canceling update..."
exit 1
else
echo "Chart ${{ steps.eval.outputs.chart }} found. Update appVersion to ${{ steps.eval.outputs.appVersion }}"
exit 0
fi
fi
update_appVersion:
runs-on: ubuntu-latest
needs: [check_vars]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install helm-docs @latest
env:
DOCS_VERSION: 1.11.0
run: |
wget https://github.com/norwoodj/helm-docs/releases/download/v${DOCS_VERSION}/helm-docs_${DOCS_VERSION}_Linux_x86_64.tar.gz -O helm-docs.tar.gz
tar -xzf helm-docs.tar.gz
- name: Set appVersion and push
shell: bash
env:
CHART_YAML: charts/${{ needs.check_vars.outputs.chart }}/Chart.yaml
run: |
sed -i "s/appVersion: .*/appVersion: ${{ needs.check_vars.outputs.appVersion }}/g" $CHART_YAML
# Get version
export chart_version=$(grep 'version:' $CHART_YAML | awk '{ print $2}')
### Increments the part of the string
## $1: version itself
## $2: number of part: 0 – major, 1 – minor, 2 – patch
increment_version() {
local delimiter=.
local array=($(echo "$1" | tr $delimiter '\n'))
array[$2]=$((array[$2]+1))
echo $(local IFS=$delimiter ; echo "${array[*]}")
}
export new_version=$(increment_version $chart_version 2)
sed -i "s/version: .*/version: $new_version/g" $CHART_YAML
cat $CHART_YAML
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
./helm-docs -t templates/README.md.gotmpl
git status
git commit charts/${{ needs.check_vars.outputs.chart }} -m "update chart ${{ needs.check_vars.outputs.chart }} to appVersion ${{ needs.check_vars.outputs.appVersion }}"
git push