Skip to content

Commit 3a1c468

Browse files
authored
use merge-base for copyright year check (#4907)
Instead of comparing against current base branch head, use the common ancestor of the PR and the base branch to avoid false positives when a year was bumped in the base branch but not yet merged into the PR.
1 parent 8f9bb39 commit 3a1c468

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,29 @@ jobs:
5757
steps:
5858
- name: Checkout
5959
uses: actions/checkout@v3
60-
# Fails on nimyaml tests:
61-
# with:
62-
# submodules: true
60+
with:
61+
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base
62+
# submodules: true # Fails on nimyaml tests
6363

6464
- name: Check copyright year (Linux)
6565
if: github.event_name == 'pull_request' && runner.os == 'Linux'
6666
run: |
6767
excluded_extensions="ans|json|md|png|txt"
6868
69-
base_branch=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")
70-
git fetch origin "$base_branch" 2>/dev/null
71-
modified_files=$(git diff --name-only --diff-filter=d --ignore-submodules "origin/$base_branch" HEAD | grep -vE '\.('$excluded_extensions')$' || true)
72-
7369
current_year=$(date +"%Y")
7470
outdated_files=()
75-
for file in $modified_files; do
71+
while read -r file; do
7672
if ! grep -qE 'Copyright \(c\) .*'$current_year' Status Research & Development GmbH' "$file"; then
7773
outdated_files+=("$file")
7874
fi
79-
done
75+
done < <(git diff --name-only --diff-filter=AM --ignore-submodules HEAD^ HEAD | grep -vE '\.('$excluded_extensions')$' || true)
8076
8177
if (( ${#outdated_files[@]} )); then
8278
echo "The following files do not have an up-to-date copyright year:"
8379
for file in "${outdated_files[@]}"; do
8480
echo "- $file"
8581
done
86-
exit 1
82+
exit 2
8783
fi
8884
8985
- name: MSYS2 (Windows amd64)

0 commit comments

Comments
 (0)