Skip to content

Commit c30c1cf

Browse files
enable license check on the repo with github actions
Signed-off-by: Manikanta Sreeram <[email protected]>
1 parent 35dba53 commit c30c1cf

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: PR License Check
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
run-license-check:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Checkout yocto-scripts repo
17+
uses: actions/checkout@v2
18+
with:
19+
repository: Xilinx/yocto-scripts
20+
path: yocto-scripts
21+
ref: kria-apps
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: '3.9.12'
27+
28+
- name: Install dependencies
29+
run: python3 -m pip install requests
30+
31+
- name: Run standardlicense.py and capture output
32+
id: license_check
33+
env:
34+
PAT_TOKEN: ${{ secrets.GH_PAT }}
35+
PR_NUMBER: ${{ github.event.pull_request.number }}
36+
GH_REPO_NAME: ${{ github.repository }}
37+
run: |
38+
echo "PR_NUMBER: $PR_NUMBER"
39+
echo "GH_REPO_NAME: $GH_REPO_NAME"
40+
cp yocto-scripts/xscc.awk .
41+
output=$(python3 yocto-scripts/standardlicense.py $PR_NUMBER $PAT_TOKEN $GH_REPO_NAME)
42+
echo "$output" > license_result.txt
43+
echo "::set-output name=output::$output"
44+
45+
- name: Check license result
46+
id: check_result
47+
run: |
48+
output=$(cat license_result.txt)
49+
if [[ "$output" == *"License Check is Passed"* ]] || [[ "$output" == *"Skipping License Check for this File"* ]] || [[ "$output" == *"This is the Approved License. Hence, License Check is Passed"* ]]; then
50+
echo "License check passed."
51+
else
52+
echo "License check failed."
53+
exit 1
54+
fi
55+
56+
- name: Post comment on GitHub
57+
if: always()
58+
run: |
59+
COMMENT_BODY=$(cat license_result.txt)
60+
# Replace newline characters with '\n' to properly format the JSON payload
61+
COMMENT_BODY=$(echo "$COMMENT_BODY" | sed 's/$/\\n/g' | tr -d '\n')
62+
echo "Posting comment to PR#${{ github.event.pull_request.number }}:"
63+
echo "Posting comment on this repo#${{ github.repository }}:"
64+
echo "$COMMENT_BODY"
65+
echo "JSON Payload:"
66+
echo "{\"body\": \"$COMMENT_BODY\"}"
67+
curl -X POST \
68+
-H "Accept: application/vnd.github.v3+json" \
69+
-H "Authorization: token ${{ secrets.GH_PAT }}" \
70+
-H "Content-Type: application/json" \
71+
-d "{\"body\": \"$COMMENT_BODY\"}" \
72+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
73+
74+
- name: Post status to GitHub
75+
if: always()
76+
run: |
77+
output=$(cat license_result.txt)
78+
state="failure"
79+
description="License check failed."
80+
if [[ "$output" == *"License Check is Passed"* ]] || [[ "$output" == *"Skipping License Check for this File"* ]] || [[ "$output" == *"This is the Approved License. Hence, License Check is Passed"* ]]; then
81+
state="success"
82+
description="License check passed."
83+
fi
84+
85+
curl -X POST \
86+
-H "Authorization: token ${{ secrets.GH_PAT }}" \
87+
-H "Accept: application/vnd.github.v3+json" \
88+
-d "{\"state\": \"$state\", \"description\": \"$description\", \"context\": \"license-check\"}" \
89+
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}"

0 commit comments

Comments
 (0)