-
-
Notifications
You must be signed in to change notification settings - Fork 25
66 lines (56 loc) · 2.96 KB
/
check-chart-versions-bump.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
name: Check chart version bump
on:
pull_request:
paths:
- 'charts/**'
jobs:
check_version_bump_on_modified_charts:
runs-on: ubuntu-latest
name: Check version bump on modified charts
steps:
- uses: actions/checkout@v3
- id: list_modified_charts
name: List modified charts
env:
GH_TOKEN: ${{ github.token }}
run: |
# Retrieve the list of modified chart names in the pull request
modifiedCharts=$(gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path' | xargs dirname | grep "^charts/" | cut -d "/" -f 2 | sort --unique | tr '\n' ',')
# Remove last comma
modifiedCharts="${modifiedCharts%,}"
if [ -z "$modifiedCharts" ]; then
echo "= Info: no modified chart found."
else
echo "= modified chart(s): ${modifiedCharts}"
fi
# Store the result
echo "modified_charts=${modifiedCharts}" >> "$GITHUB_OUTPUT"
- id: check_bump
if: steps.list_modified_charts.outputs.modified_charts != ''
name: Check if chart version has been bumped
run: |
git fetch --quiet origin pull/${{ github.event.pull_request.number }}/head:pr-branch
git fetch --quiet origin ${{ github.event.pull_request.base.ref }}:target-branch
# Set IFS to a comma to split the string into an array
IFS=',' read -ra chartNames <<< "${{ steps.list_modified_charts.outputs.modified_charts }}"
notBumped=0
for chartName in "${chartNames[@]}"; do
# Retrieve version from each branch Chart.yaml, or empty if it does not exist
MAIN_CHART_VERSION=$(git show target-branch:charts/$chartName/Chart.yaml 2>/dev/null | grep "^version:" | cut -d " " -f 2)
PR_CHART_VERSION=$(git show pr-branch:charts/$chartName/Chart.yaml 2>/dev/null | grep "^version:" | cut -d " " -f 2)
# If it's a new chart we're just informing the file doesn't exist or a version can't be read from it on the target branch
if [ -z "$MAIN_CHART_VERSION" ]; then
echo "= Info: charts/$chartName/Chart.yaml doesn't exist or a version can't be read from it on the target branch."
fi
# If the version hasn't been bumped between the pull request and the target branch
# or if there is no Chart.yaml in the pull request branch
if [ "$MAIN_CHART_VERSION" == "$PR_CHART_VERSION" ] || [ -z "$PR_CHART_VERSION" ]; then
echo "= ERROR: the version of the '$chartName' chart hasn't been bumped: '$PR_CHART_VERSION'."
((notBumped++))
fi
echo "= Info: the version of the '$chartName' chart has been bumped from '$MAIN_CHART_VERSION' to '$PR_CHART_VERSION'."
done
if [ "$notBumped" -gt 0 ]; then
echo "= ERROR: there is at least a version of a chart that hasn't been bumped."
exit 1
fi