Skip to content

Commit

Permalink
add workflow job for the diff againts script
Browse files Browse the repository at this point in the history
  • Loading branch information
havan committed Sep 19, 2024
1 parent 874749d commit 70fee0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ jobs:
# Run buf format
buf format proto --diff --exit-code
# diff check against c4t branch to catch breaking changes
diff-c4t:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Run diff against branch
run: scripts/diff_against_branch.sh

# Push the draft branch to buf.build
bsr-push-draft:
runs-on: ubuntu-latest
Expand Down
16 changes: 12 additions & 4 deletions scripts/diff_against_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ function check_added_file {
# Skip it as it's newly introduced
return
fi


OTHER_FILE=$(echo $FILE | sed -e "s#/v$FILE_VERSION/#/v$(( FILE_VERSION - 1))/#")

echo
echo "#############################################################################"
echo "## Detected newly added file: $FILE"
echo "## Version: $FILE_VERSION"
Expand All @@ -51,6 +51,7 @@ function check_modified_file {
FILE=$1
OTHER_FILE=$FILE

echo
echo "#############################################################################"
echo "## Detected modified file: $FILE"
echo "## Comparing against $ORIGIN/$OTHER_FILE"
Expand All @@ -67,10 +68,12 @@ function check_modified_file {
# against the c4t branch
diff -w -B - <(git show origin/$ORIGIN:$OTHER_FILE | sed -e "s#//.*##g") < <(cat $FILE | sed -e "s#//.*##g") > /dev/null
if [[ "$?" != "0" ]] ; then
echo "## ERROR: Structural change detected in already existing file: $FILE"
echo
echo "## ❌ [FAIL] ERROR: Structural change detected in already existing file: $FILE"
ERROR_FILES+=("$FILE")
else
echo "## INFO: No structural change detected. The changes should only be in the comments."
echo
echo "## ✅ [PASS] INFO: No structural change detected. The changes should only be in the comments."
fi
}

Expand All @@ -86,11 +89,16 @@ done < <(git diff --name-status origin/$ORIGIN | grep -P "^M.*" | grep -oP "prot
if [ ${#ERROR_FILES[@]} -gt 0 ] ; then
echo
echo "#############################################################################"
echo "## Found ${#ERROR_FILES[@]} errors while doing the diff"
echo "## Found ${#ERROR_FILES[@]} errors while doing the diff"
echo "## Please check the following files: "
for file in ${ERROR_FILES[@]} ; do
echo "## -> $file"
done
echo "#############################################################################"
exit 1
fi

echo
echo "##########################"
echo "## ✅ No issues found! ##"
echo "##########################"

0 comments on commit 70fee0b

Please sign in to comment.