Skip to content

Commit

Permalink
feat(ci): check version for bump in PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorJPDJ committed Apr 12, 2024
1 parent d2bac1e commit 1f154e3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/chart-oci-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
for d in * ; do
# check if directory changed and skip if not
[ $GIT_DIFF_ENABLED = 1 ] && \
git diff -s --exit-code "${GIT_DIFF_BASE}..${GIT_DIFF_HEAD}" "$d" && \
git diff -s --exit-code "${GIT_DIFF_BASE}..${GIT_DIFF_HEAD}" -- "$d" && \
continue
if [ -f "$d/Chart.yaml" ] ; then
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/version-changed-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check for version bumps in PR

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check_changes_and_versions:
name: Check for changes and version bumps
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.MATRIX }}
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: '0'

- name: Verify changes and versions
run: |
GIT_DIFF_BASE='${{ github.event.pull_request.base.sha }}'
GIT_DIFF_HEAD='${{ github.event.pull_request.head.sha }}'
./scripts/ci_version_changed_check.sh "$GIT_DIFF_BASE" "$GIT_DIFF_HEAD"
38 changes: 38 additions & 0 deletions scripts/ci_version_changed_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
GIT_DIFF_BASE="$1"
GIT_DIFF_HEAD="$2"
EXIT_CODE=0
CHANGED=0

[ -z "$GIT_DIFF_BASE" -o -z "$GIT_DIFF_HEAD" ] &&
echo "GIT_DIFF_BASE or GIT_DIFF_HEAD not provided. Exiting." &&
exit 1

cd charts

for d in * ; do
# check if directory changed and skip if not
git diff -s --exit-code "${GIT_DIFF_BASE}..${GIT_DIFF_HEAD}" -- "$d" && \
continue
CHANGED=1
echo "[Chart $d]: files changed, checking versions"

chart_yaml="./$d/Chart.yaml"
if [ -f "$chart_yaml" ] ; then
base_ver="$(git show "$GIT_DIFF_BASE:$chart_yaml" | grep "^version:" | awk '{print $2}')"
echo "[Chart $d]: base version: $base_ver"
head_ver="$(git show "$GIT_DIFF_HEAD:$chart_yaml" | grep "^version:" | awk '{print $2}')"
echo "[Chart $d]: head version: $head_ver"

if [ "$base_ver" == "$head_ver" ] ; then
echo -e "[Chart $d]: \e[31mversion not changed, this should be fixed!\e[0m"
EXIT_CODE=2
else
echo -e "[Chart $d]: \e[32mversion changed, everything is ok!\e[0m"
fi
fi
done

[ "$CHANGED" == "0" ] && \
echo -e "\e[32mNo chart changes detected, everything is ok!\e[0m"
exit $EXIT_CODE

0 comments on commit 1f154e3

Please sign in to comment.