-
Notifications
You must be signed in to change notification settings - Fork 543
141 lines (125 loc) · 4.59 KB
/
version.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
name: Bump Version and Generate Docs
on:
pull_request_review:
types: [submitted]
jobs:
changes:
name: Find Updated Chart
runs-on: ubuntu-latest
if: github.event.review.state == 'approved'
outputs:
apps: ${{ steps.apps.outputs.apps }}
steps:
- uses: tj-actions/changed-files@v45
id: changed-files
with:
dir_names: 'true'
dir_names_exclude_current_dir: 'true'
dir_names_max_depth: '2'
matrix: 'true'
files: 'charts/**'
- id: apps
run: |
echo "apps=${{ toJson(steps.changed-files.outputs.all_changed_files) }}" | sed -E 's|charts/||g' >> "$GITHUB_OUTPUT"
docs:
name: Bump Version and Generate Docs
runs-on: ubuntu-latest
needs: changes
permissions:
contents: write
strategy:
max-parallel: 1
fail-fast: false
matrix:
app: ${{ fromJson(needs.changes.outputs.apps ) }}
env:
APP: ${{ matrix.app }}
steps:
- uses: gabe565/setup-helm-docs-action@v1
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: charts
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up chart-testing
uses: helm/chart-testing-action@v2
- name: Check if version bump is needed
id: check_bump
run: |
ct lint --config .github/linters/ct.yaml --source master | grep -q 'chart version not ok. Needs a version bump!'
needsBump=$?
if [ $needsBump -eq 0 ]; then
echo "needsBump=true" >> "$GITHUB_OUTPUT"
else
echo "needsBump=false" >> "$GITHUB_OUTPUT"
fi
- name: Cache binaries
id: cache-bin
if: ${{ steps.check_bump.outputs.needsBump == 'true' }}
uses: actions/cache@v4
env:
cache-name: cache-semver
with:
path: bin
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('bin/semver') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Setup semver
if: ${{ steps.check_bump.outputs.needsBump == 'true' && steps.cache-bin.outputs.cache-hit != 'true' }}
run: |
mkdir -p bin
wget -O bin/semver \
https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.4.0/src/semver
chmod +x bin/semver
- name: Setup PATH
if: ${{ steps.check_bump.outputs.needsBump == 'true' }}
run: |
echo "$GITHUB_WORKSPACE/bin" >> "$GITHUB_PATH"
- name: Compute version
if: ${{ steps.check_bump.outputs.needsBump == 'true' }}
id: get_version
env:
PATCH_LABEL: "${{ contains(github.event.pull_request.labels.*.name, 'chart: patch') }}"
MINOR_LABEL: "${{ contains(github.event.pull_request.labels.*.name, 'chart: minor') }}"
MAJOR_LABEL: "${{ contains(github.event.pull_request.labels.*.name, 'chart: major') }}"
run: |
current_ver=$(cat "charts/${APP}/Chart.yaml" | grep 'version:' | cut -d' ' -f2)
BUMP_TYPE=''
if [[ $MAJOR_LABEL == 'true' ]];
then
BUMP_TYPE='major'
elif [[ $MINOR_LABEL == 'true' ]];
then
BUMP_TYPE='minor'
elif [[ $PATCH_LABEL == 'true' ]];
then
BUMP_TYPE='patch'
else
echo "::error title=Missing Label::Missing the chart versioning label"
exit -1
fi
echo "running ${BUMP_TYPE} version bump"
new_ver=$(semver bump "${BUMP_TYPE}" "$current_ver")
echo "last=${current_ver}" >> "$GITHUB_OUTPUT"
echo "new=${new_ver}" >> "$GITHUB_OUTPUT"
- name: Update Chart Version
if: ${{ steps.check_bump.outputs.needsBump == 'true' }}
shell: bash
run: |
sed -i "s/version: ${{ steps.get_version.outputs.last }}/version: ${{ steps.get_version.outputs.new }}/g" "charts/${APP}/Chart.yaml"
- name: Update Docs
shell: bash
run: |
helm-docs --chart-search-root charts --chart-to-generate charts/${APP}
- name: Commit Changes
env:
message: ${{ steps.check_bump.outputs.needsBump == 'true' && format('to v{0}', steps.get_version.outputs.new) || 'documentation' }}
run: |
git config user.email '<>'
git config user.name github-actions
if ! git diff-index --quiet HEAD; then
git commit -m "chore: update $APP chart $message" --all
git push origin "HEAD:$GITHUB_HEAD_REF"
fi