Skip to content

Commit

Permalink
improve .sh file and expand ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Frosty2500 committed Nov 27, 2024
1 parent 6643281 commit 38b89bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,17 @@ jobs:
- name: Create source and wheel dist
run: |
python -m build
sdk-check-copyright:
# This job checks that the copyright year in the header of all files is up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install required dependencies
run: |
sudo apt-get update
sudo apt-get install -y bash git
- name: Run copyright check
run: |
chmod +x ./etc/scripts/set_copyright_year.sh
CHECK_MODE=true ./etc/scripts/set_copyright_year.sh
14 changes: 13 additions & 1 deletion etc/scripts/set_copyright_year.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@
# notice (in case the first line is a shebang).

while read -rd $'\0' year file; do
sed -i "1,2s/^\(# Copyright (c) \)[[:digit:]]\{4,\}/\1$year/" "$file"
# Extract the first year from the copyright notice
current_year=$(sed -n '1,2s/^\(# Copyright (c) \)[^0-9]*\([0-9]\{4\}\)\([^\n]*\)/\2/p' "$file")

if $CHECK_MODE && [[ "$current_year" != "$year" ]]; then
echo "Error: Copyright year mismatch in file $file. Expected $year, found $current_year."
exit 1
fi

if ! $CHECK_MODE && [[ "$current_year" != "$year" ]]; then
sed -i "1,2s/^\(# Copyright (c) \)[[:digit:]]\{4,\}/\1$year/" "$file"
echo "Updated copyright year in $file"
fi
done < <(git ls-files -z "$@" | xargs -0I{} git log -1 -z --format="%ad {}" --date="format:%Y" "{}")

0 comments on commit 38b89bf

Please sign in to comment.