Skip to content

Bump mirrorbits-parent subchart versions #1392

Bump mirrorbits-parent subchart versions

Bump mirrorbits-parent subchart versions #1392

name: Check chart version bump
on:
pull_request:
jobs:
check_version_bump_on_modified_charts:
runs-on: ubuntu-latest
name: Check version bump on modified charts
steps:
- uses: actions/checkout@v4
- 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