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

Github action asserting license statement in PR description #1892

Merged
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
53 changes: 52 additions & 1 deletion .github/workflows/misc-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Misc tests
name: Miscellaneous test jobs
on:
push:
branches: [ '*' ]
Expand Down Expand Up @@ -26,3 +26,54 @@ jobs:
- name: Test sandbox configuration
run: |
./tests/ci/run_presandbox_tests.sh

assert-license-statement-in-pr-description:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest

steps:
- name: Install jq
run: |
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
sudo apt-get install -y jq

- name: Check PR description
run: |
# License statement we want present.
LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license."

# Fetches the PR description.
PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body)

printf "PR description:\n%s" "${PR_DESCRIPTION}"
echo ""
echo ""
printf "Must contain:\n%s" "${LICENSE_STATEMENT}"
echo ""
echo ""

# Normalize line endings (convert CRLF to LF)
PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d '\r')

# Escape quotes in PR description
PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | sed 's/"/\\"/g; s/'"'"'/\\'"'"'/g')

# Remove all spaces and tabs
PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d ' \t')
LICENSE_STATEMENT=$(echo "${LICENSE_STATEMENT}" | tr -d ' \t')

Comment on lines +56 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what is this needed for? The license statement is a single sentence so there should be no new lines, and a space is a space and should match right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. If I did:

  1. pushing PR with correct statement in the PR description
  2. modified PR statement to incorrect and then re-ran the job.
  3. modified PR statement back to correct and then re-ran the job.

(1) and (2) would return as expected i.e. former succeeded, the latter failed. But (3) would not return as expected, it would fail. Removing spaces etc. seems to have removed something that got encoded unexpected(?)

printf "PR description trimmed:\n%s" "${PR_DESCRIPTION}"
echo ""
echo ""
printf "Must contain trimmed:\n%s" "${LICENSE_STATEMENT}"
echo ""
echo ""

# Assert PR description contains license statement.
if printf "%s\n" "${PR_DESCRIPTION}" | grep -ixq "${LICENSE_STATEMENT}"; then
echo "Success: PR description contains license statement."
else
echo "Error: PR description does not contain the required license statement."
exit 1
fi
Loading