Skip to content

Commit

Permalink
use merge-base for copyright year check (#4907)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etan-status authored May 9, 2023
1 parent 8f9bb39 commit 3a1c468
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,29 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
# Fails on nimyaml tests:
# with:
# submodules: true
with:
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base
# submodules: true # Fails on nimyaml tests

- name: Check copyright year (Linux)
if: github.event_name == 'pull_request' && runner.os == 'Linux'
run: |
excluded_extensions="ans|json|md|png|txt"
base_branch=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")
git fetch origin "$base_branch" 2>/dev/null
modified_files=$(git diff --name-only --diff-filter=d --ignore-submodules "origin/$base_branch" HEAD | grep -vE '\.('$excluded_extensions')$' || true)
current_year=$(date +"%Y")
outdated_files=()
for file in $modified_files; do
while read -r file; do
if ! grep -qE 'Copyright \(c\) .*'$current_year' Status Research & Development GmbH' "$file"; then
outdated_files+=("$file")
fi
done
done < <(git diff --name-only --diff-filter=AM --ignore-submodules HEAD^ HEAD | grep -vE '\.('$excluded_extensions')$' || true)
if (( ${#outdated_files[@]} )); then
echo "The following files do not have an up-to-date copyright year:"
for file in "${outdated_files[@]}"; do
echo "- $file"
done
exit 1
exit 2
fi
- name: MSYS2 (Windows amd64)
Expand Down

0 comments on commit 3a1c468

Please sign in to comment.