Skip to content

Commit

Permalink
Optimize failure notice of copyright header check (#23)
Browse files Browse the repository at this point in the history
fix #20

If the feature branch is not based on the latest target branch, git diff
may include unexpected files marked as modified in the check that are
not from the feature branch. This is because it tries to find a common
commit between the two branches and can get confused if it is too old
and there are lots of changes. If this happens please upmerge your PR to
the latest development branch.

now the check is based on merged commit vs base ref, it should not detect untouched files
---------

Signed-off-by: Yanxuan Liu <yanxuanl@nvidia.com>
  • Loading branch information
YanxuanLiu authored Jan 23, 2025
1 parent 2296899 commit ea7b8a8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions license-header-check/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,8 +43,10 @@ runs:
echo "Excluded file patterns: ${EXCLUDE_PATTERNS[@]}"
# Get changed files
FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) || (echo "Your base commit ID is too old, please try upmerge first." && exit 1)
RENAME_FILES=$(git diff --name-status ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep "^R" | grep -v "R100" | awk '{print $3}' || echo "")
BASE_REF=$(git --no-pager log --oneline -1 | awk '{ print $NF }')
echo "Base REF: ${BASE_REF}"
FILES=$(git diff --name-only --diff-filter=AM ${BASE_REF} HEAD) || (echo "Your base commit ID is too old, please try upmerge first." && exit 1)
RENAME_FILES=$(git diff --name-status ${BASE_REF} HEAD | grep "^R" | grep -v "R100" | awk '{print $3}' || echo "")
echo "${RENAME_FILES[@]}"
FILES=($FILES $RENAME_FILES)
echo "Files to be detected: ${FILES[@]}"
Expand Down Expand Up @@ -76,10 +78,16 @@ runs:
# Output result
echo "--------- RESULT ---------"
ERROR_MESSAGE="If the feature branch is not based on the latest target branch, \
git diff may include unexpected files marked as modified in the check that are not from the feature branch. \
This is because it tries to find a common commit between the two branches \
and can get confused if it is too old and there are lots of changes. \
If this happens please UPMERGE your PR to the latest development branch."
if [ ! -z "$NO_LICENSE_FILES" ]; then
echo "Following files missed copyright/license header or expired:"
echo $NO_LICENSE_FILES | tr ' ' '\n'
echo "If there are files that are not modified by your PR, please try upmerge first."
echo "--------- NOTICE ---------"
echo "${ERROR_MESSAGE}"
exit 1
else
echo "All files passed the check"
Expand Down

0 comments on commit ea7b8a8

Please sign in to comment.