From 1f154e3265c9d836634ff7d2c21365f48396d212 Mon Sep 17 00:00:00 2001 From: JuniorJPDJ Date: Fri, 12 Apr 2024 16:26:48 +0200 Subject: [PATCH] feat(ci): check version for bump in PRs --- .github/workflows/chart-oci-publish.yml | 2 +- .github/workflows/version-changed-check.yml | 23 +++++++++++++ scripts/ci_version_changed_check.sh | 38 +++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/version-changed-check.yml create mode 100755 scripts/ci_version_changed_check.sh diff --git a/.github/workflows/chart-oci-publish.yml b/.github/workflows/chart-oci-publish.yml index 16ddffb..596352a 100644 --- a/.github/workflows/chart-oci-publish.yml +++ b/.github/workflows/chart-oci-publish.yml @@ -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 diff --git a/.github/workflows/version-changed-check.yml b/.github/workflows/version-changed-check.yml new file mode 100644 index 0000000..6da6365 --- /dev/null +++ b/.github/workflows/version-changed-check.yml @@ -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" diff --git a/scripts/ci_version_changed_check.sh b/scripts/ci_version_changed_check.sh new file mode 100755 index 0000000..8f1b81d --- /dev/null +++ b/scripts/ci_version_changed_check.sh @@ -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