Skip to content

Enhance CI Workflow: Check for Version Bump and appVersion Changes #1

Enhance CI Workflow: Check for Version Bump and appVersion Changes

Enhance CI Workflow: Check for Version Bump and appVersion Changes #1

name: Check for Version Bump and appVersion in Chart.yaml
on:
pull_request:
types: [opened, synchronize, labeled]
jobs:
check_version_bump:
name: Version Bump Check
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract Chart Version
id: chart_version
run: |
version=$(yq e '.version' ./deployments/chart/Chart.yaml)
echo "version=$version" >> $GITHUB_ENV
- name: Get latest Git tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --abbrev=0 || echo "No tags found")
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
# Compare versions and fail if there is a version bump
- name: Compare versions and fail if there is a version bump
if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') }}
run: |
if [ "v${{ env.version }}" != "${{ env.latest_tag }}" ]; then
echo "Version bump detected. Failing the job."
exit 1
else
echo "No version bump detected."
fi
# Check for changes in the appVersion between PR and main
- name: Check for appVersion changes
if: ${{ !contains(github.event.pull_request.labels.*.name, 'release') }}
run: |
if git diff main -- deployments/chart/Chart.yaml | grep -qe "^[+-]appVersion: "; then
echo "appVersion has changed. Failing the job."
exit 1
else
echo "No appVersion changes detected."
fi
# Post warning comment if there is a failure
- name: Post warning comment
if: ${{ failure() && !contains(github.event.pull_request.labels.*.name, 'release') }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: "Warning: This PR will result in a new release because the version in Chart.yaml (`${{ env.version }}`) or the appVersion has changed. Please confirm before merging."