Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): check version for bump in PRs #63

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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