Skip to content

Commit ea7b8a8

Browse files
authored
Optimize failure notice of copyright header check (#23)
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 <[email protected]>
1 parent 2296899 commit ea7b8a8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

license-header-check/action.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024, NVIDIA CORPORATION.
1+
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -43,8 +43,10 @@ runs:
4343
echo "Excluded file patterns: ${EXCLUDE_PATTERNS[@]}"
4444
4545
# Get changed files
46-
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)
47-
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 "")
46+
BASE_REF=$(git --no-pager log --oneline -1 | awk '{ print $NF }')
47+
echo "Base REF: ${BASE_REF}"
48+
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)
49+
RENAME_FILES=$(git diff --name-status ${BASE_REF} HEAD | grep "^R" | grep -v "R100" | awk '{print $3}' || echo "")
4850
echo "${RENAME_FILES[@]}"
4951
FILES=($FILES $RENAME_FILES)
5052
echo "Files to be detected: ${FILES[@]}"
@@ -76,10 +78,16 @@ runs:
7678
7779
# Output result
7880
echo "--------- RESULT ---------"
81+
ERROR_MESSAGE="If the feature branch is not based on the latest target branch, \
82+
git diff may include unexpected files marked as modified in the check that are not from the feature branch. \
83+
This is because it tries to find a common commit between the two branches \
84+
and can get confused if it is too old and there are lots of changes. \
85+
If this happens please UPMERGE your PR to the latest development branch."
7986
if [ ! -z "$NO_LICENSE_FILES" ]; then
8087
echo "Following files missed copyright/license header or expired:"
8188
echo $NO_LICENSE_FILES | tr ' ' '\n'
82-
echo "If there are files that are not modified by your PR, please try upmerge first."
89+
echo "--------- NOTICE ---------"
90+
echo "${ERROR_MESSAGE}"
8391
exit 1
8492
else
8593
echo "All files passed the check"

0 commit comments

Comments
 (0)