-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create restore_check_license_and_history.yml
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,90 @@ | ||
name: Check License and History | ||
|
||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
push: | ||
pull_request_target: | ||
|
||
|
||
jobs: | ||
changedfiles: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
output1: ${{ steps.changes.outputs.diff_list }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: Get changed files | ||
id: changes | ||
run: | | ||
echo "files added or changed in a PR: " | ||
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' | ||
echo "added or changed files: " | ||
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' | ||
echo "diff_list<<EOF" >> $GITHUB_OUTPUT | ||
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT | ||
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: list new files | ||
run: | | ||
echo "New files in this PR ${{ steps.changes.outputs.diff_list }}" | ||
lint: | ||
runs-on: ubuntu-latest | ||
needs: changedfiles | ||
env: | ||
OUTPUT1: ${{needs.changedfiles.outputs.output1}} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: Check License | ||
run: | | ||
exit_code=0 | ||
for file in $(echo $OUTPUT1) | ||
do | ||
if ! grep -qE "Copyright \(C\) 20[0-9]{2} Speedb Ltd\. All rights reserved\." "$file"; then | ||
echo $file does not have the Apache 2.0 license header && exit_code=222 | ||
fi | ||
done | ||
exit $exit_code | ||
- name: Check HISTORY PR | ||
run: | | ||
set +e | ||
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}|grep -v "\.github" |grep -q [a-z,A-Z] | ||
if [ $? -eq "0" ]; then | ||
history_not_in=1 | ||
git diff --name-only --diff-filter=M ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}|grep -v "\.github" |grep -q "HISTORY.md" | ||
if [ $? -ne "0" ]; then | ||
echo "New files were added in this PR but the HISTORY.md file was not updated" | ||
else | ||
history_not_in=0 | ||
fi | ||
exit $history_not_in | ||
fi | ||
echo "No files were added" | ||
exit 0 | ||
- name: Check HISTORY WD | ||
run: | | ||
set +e | ||
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' ':!*.md' |grep -q [a-z,A-Z] | ||
if [ $? -eq "0" ]; then | ||
history_not_in=1 | ||
git diff --name-only --diff-filter=ACMRT remotes/origin/main HEAD -- . ':!.github' |grep -q "HISTORY.md" | ||
if [ $? -ne "0" ]; then | ||
echo "New files were added in this PR but the HISTORY.md file was not updated" | ||
else | ||
history_not_in=0 | ||
fi | ||
exit $history_not_in | ||
fi | ||
echo "No files were added" | ||
exit 0 |