-
Notifications
You must be signed in to change notification settings - Fork 4
add license header check v2 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e8c6772
add license header check v2
YanxuanLiu ea550d7
fix nits
YanxuanLiu b4673ec
fix nits
YanxuanLiu 33d9978
add conditional branch
YanxuanLiu 4fabc7c
fix
YanxuanLiu 218158d
test
YanxuanLiu d8af00b
update desc
YanxuanLiu efaedfa
fix nits
YanxuanLiu 439d63e
optimize
YanxuanLiu b9f8f8d
fix nits
YanxuanLiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright (c) 2024-2025, NVIDIA CORPORATION. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
YanxuanLiu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: 'License Header Check V2' | ||
YanxuanLiu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: 'check license/copyright header v2' | ||
| inputs: | ||
| included_file_patterns: | ||
| description: "included file pattern" | ||
| required: true | ||
| type: string | ||
| excluded_file_patterns: | ||
| description: "excluded file pattern" | ||
| required: false | ||
| type: string | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Get changed files | ||
| shell: bash | ||
| run: | | ||
| set -e | ||
|
|
||
| # Get license pattern with year | ||
| CURRENT_YEAR=$(date +%Y) | ||
| LICENSE_PATTERN="Copyright \(c\) .*?${CURRENT_YEAR},? NVIDIA CORPORATION." | ||
|
|
||
| # Format file patterns | ||
| IFS="," read -r -a INCLUDE_PATTERNS <<< "$(echo "${{ inputs.included_file_patterns }}" | tr -d ' ' | tr -d '\n')" | ||
| IFS="," read -r -a EXCLUDE_PATTERNS <<< "$(echo "${{ inputs.excluded_file_patterns }}" | tr -d ' ' | tr -d '\n')" | ||
| echo "Included file patterns: ${INCLUDE_PATTERNS[@]}" | ||
| echo "Excluded file patterns: ${EXCLUDE_PATTERNS[@]}" | ||
|
|
||
| # Get changed files | ||
| BASE_REF=$(git --no-pager log --oneline -1 | awk '{ print $NF }') | ||
| echo "Base REF: ${BASE_REF}" | ||
| FILES=$(git diff --name-only --diff-filter=AM ${BASE_REF} HEAD) || (echo "Your base commit ID is too old, please try upmerge first." && exit 1) | ||
| RENAME_FILES=$(git diff --name-status ${BASE_REF} HEAD | grep "^R" | grep -v "R100" | awk '{print $3}' || echo "") | ||
| echo "${RENAME_FILES[@]}" | ||
| FILES=($FILES $RENAME_FILES) | ||
| echo "Files to be detected: ${FILES[@]}" | ||
|
|
||
| # Check license header | ||
| NO_LICENSE_FILES="" | ||
| for FILE in "${FILES[@]}"; do | ||
| INCLUDE=false | ||
| for INCLUDE_PATTERN in "${INCLUDE_PATTERNS[@]}"; do | ||
| if [[ $FILE == $INCLUDE_PATTERN ]]; then | ||
| INCLUDE=true | ||
| break | ||
| fi | ||
| done | ||
| EXCLUDE=false | ||
| for EXCLUDE_PATTERN in "${EXCLUDE_PATTERNS[@]}"; do | ||
| if [[ $FILE == $EXCLUDE_PATTERN ]]; then | ||
| EXCLUDE=true | ||
| break | ||
| fi | ||
| done | ||
| if [[ $INCLUDE == true && $EXCLUDE == false ]]; then | ||
| echo "Checking $FILE" | ||
| if !(grep -Eiq "$LICENSE_PATTERN" "$FILE"); then | ||
| NO_LICENSE_FILES+="$FILE " | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| # Output result | ||
| echo "--------- RESULT ---------" | ||
| ERROR_MESSAGE="If the feature branch is not based on the latest target branch, \ | ||
| git diff may include unexpected files marked as modified in the check that are not from the feature branch. \ | ||
| This is because it tries to find a common commit between the two branches \ | ||
| and can get confused if it is too old and there are lots of changes. \ | ||
| If this happens please UPMERGE your PR to the latest development branch." | ||
| if [ ! -z "$NO_LICENSE_FILES" ]; then | ||
| echo "Following files missed copyright/license header or expired:" | ||
| echo $NO_LICENSE_FILES | tr ' ' '\n' | ||
| echo "--------- NOTICE ---------" | ||
| echo "${ERROR_MESSAGE}" | ||
| exit 1 | ||
| else | ||
| echo "All files passed the check" | ||
| exit 0 | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.