Skip to content
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

added a yaml script that invokes github actions when a pr is triggered #44

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/pr-license-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: PR License Check

on:
pull_request:
branches:
- '**'

jobs:
run-license-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Checkout license-repo
uses: actions/checkout@v2
with:
repository: suchetla/license-repo
path: license-repo

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9.12'

- name: Install dependencies
run: python3 -m pip install requests

- name: Run license.py and capture output
id: license_check
env:
PAT_TOKEN: ${{ secrets.GH_PAT }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_REPO_NAME: ${{ github.repository }}
run: |
cp license-repo/xscc.awk .
output=$(python3 license-repo/standardlicense.py $PR_NUMBER $PAT_TOKEN $GH_REPO_NAME)
echo "$output" > license_result.txt
echo "::set-output name=output::$output"

- name: Check license result
id: check_result
run: |
output=$(cat license_result.txt)
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
echo "License check passed."
else
echo "License check failed."
exit 1
fi

- name: Post comment on GitHub
if: always()
run: |
COMMENT_BODY=$(cat license_result.txt)
# Replace newline characters with '\n' to properly format the JSON payload
COMMENT_BODY=$(echo "$COMMENT_BODY" | sed 's/$/\\n/g' | tr -d '\n')
echo "Posting comment to PR#${{ github.event.pull_request.number }}:"
echo "Posting comment on this repo#${{ github.repository }}:"
echo "$COMMENT_BODY"
echo "JSON Payload:"
echo "{\"body\": \"$COMMENT_BODY\"}"
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Content-Type: application/json" \
-d "{\"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"

- name: Post status to GitHub
if: always()
run: |
output=$(cat license_result.txt)
state="failure"
description="License check failed."
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
state="success"
description="License check passed."
fi

curl -X POST \
-H "Authorization: token ${{ secrets.GH_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"state\": \"$state\", \"description\": \"$description\", \"context\": \"license-check\"}" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}"
Loading