-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (121 loc) · 4.82 KB
/
check_license_and_history.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Git log
run: |
git log --graph --decorate --oneline --all
- name: ls -l
run: |
ls -l
- name: Get changed files
id: changes
run: |
echo "github.event.pull_request.head.sha"
echo ${{ github.event.pull_request.head.sha }}
echo "github.event.pull_request.base.sha"
echo ${{ github.event.pull_request.base.sha }}
echo ${{github.event.pull_request.head.repo.full_name}}
echo echo running on branch ${GITHUB_REF##*/}
if [ "${{ github.event.pull_request.head.repo.full_name }}" == "maxb-io/shred" ]; then
echo "files added or changed in a PR that came from the speedb repo: "
git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- . ':!.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
else
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 remotes/origin/main HEAD -- . ':!.github' ':!*.md' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- 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
- name: Check License
run: |
exit_code=0
for file in $(echo $OUTPUT1)
do
if ! grep -qE "Copyright \(C\) 20[0-9]{2} Shred 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
if: github.event.pull_request.head.repo.full_name == 'maxb-io/shred'
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