Skip to content

Commit

Permalink
Reenables copyright hook, updates GitHub Action to only run pre-commi…
Browse files Browse the repository at this point in the history
…t on modified/added files
  • Loading branch information
pranavm-nvidia committed Oct 14, 2024
1 parent ac4da83 commit abfbfc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -34,6 +34,10 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Get modified files
id: modified-files
run: echo "modified_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]

with:
extra_args: --files ${{ steps.modified-files.outputs.modified_files }}
19 changes: 9 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace

# FIXME: Only run on changed files when triggered by GitHub Actions
#- repo: local
# hooks:
# - id: add-license
# name: Add License
# entry: python tools/add_copyright.py
# language: python
# stages: [pre-commit]
# verbose: true
# require_serial: true
- repo: local
hooks:
- id: add-license
name: Add License
entry: python tools/add_copyright.py
language: python
stages: [pre-commit]
verbose: true
require_serial: true
2 changes: 2 additions & 0 deletions tools/add_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def add_copyrights(paths):

# Don't automatically 'git add' changes for now, make it more clear which
# files were changed and have ability to see 'git diff' on them.
# Note that this means the hook will modify files and then cancel the commit, which you will then
# have to manually make again.
# subprocess.run(["git", "add"] + paths)

print(f"Processed copyright headers for {len(paths)} file(s).")
Expand Down

0 comments on commit abfbfc4

Please sign in to comment.