Skip to content

Commit

Permalink
Add header workflow integration 2 (#5109)
Browse files Browse the repository at this point in the history
* Add a header check to the CI Fix #4980

The `add_header` script needs to be run after an edit to determine the status of
the header and, if necessary, change the header.

This commit adds the check for the header to the CI/CD. This enforces the usage
of the `add_header` script and ensures a healthy code base.

* Change the output of the `add_header` script Fix #4980

The `add_header` sript prints the correct header for a file if the `--in-place`
argument is not provided. This is a good way to see changes, however due to this
the output of the CI/CD is too verbose.

This commit disables the output of the output of the correct header, if the
`--check` option is provided. It also displays the number of files checked.
  • Loading branch information
jdierkes authored and bari12 committed Jan 20, 2022
1 parent 1ae3abf commit a776021
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/autotest.yml
Expand Up @@ -5,6 +5,25 @@ on:
- push

jobs:
header-lint:
if: 'github.event_name == ''pull_request'''
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check headers
shell: bash
run: |
git pull origin master
echo "Current git rev $(git rev-parse HEAD)"
echo "Common ancestor git rev $(git merge-base HEAD remotes/origin/master)"
echo "If a file header needs to be changed run 'tools/add_header -i FILE' from the rucio project directory."
FILES=$(git diff --name-status HEAD $(git merge-base HEAD remotes/origin/master) | grep -v '^A' | cut -f 2 | grep -E '\.py$|^bin/') || echo "No Files found"
if [[ -n $FILES ]]; then
echo "Files to check: $FILES"
tools/add_header --disable-add-me -cd $FILES
fi
setup:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion tools/add_header
Expand Up @@ -95,6 +95,7 @@ def main(arguments):
email = '<%s>' % email
exit_code = 0

print("Checking %i files" % (len(arguments.MyFiles)))
for MyFile in arguments.MyFiles:
# Query log history
cmd = '''git log --reverse --date=short --format='%s' %s ''' % ('%aN,<%aE>,%ad', MyFile)
Expand Down Expand Up @@ -244,7 +245,7 @@ def main(arguments):
if count == 0 or not_comment_line:
modified.write(line)

else:
elif not arguments.check:
print(header)
exit(exit_code)

Expand Down

0 comments on commit a776021

Please sign in to comment.