Skip to content

Commit

Permalink
feat: use action internally
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyt61 authored Apr 17, 2023
1 parent a44a755 commit 372efca
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Check Pull Request Commits Authors

on:
workflow_call:
inputs:
EMAIL_DOMAIN:
required: true
type: string
GITHUB_TOKEN:
required: true
type: string

jobs:
check-pr-commits-authors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: octokit/[email protected]
id: get-commits
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
with:
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits
accept-header: application/vnd.github+json
- name: "Checking commits authors email domain"
env:
COMMITS: ${{ steps.get-commits.outputs.data }}
run: |
required_email_domain=${{ inputs.EMAIL_DOMAIN }}
invalid_commits=0
for COMMIT in $(echo $COMMITS | jq -r '.[] | @base64'); do
_jq() {
echo ${COMMIT} | base64 --decode | jq -r ${1}
}
COMMIT_HASH=$(_jq '.sha')
COMMIT_MESSAGE=$(_jq '.commit.message')
COMMIT_AUTHOR=$(_jq '.commit.author.email')
echo "Cheking commit: $COMMIT_HASH"
echo " Commit message: \"$COMMIT_MESSAGE\""
author_email_domain=${COMMIT_AUTHOR#*@}
if [ $author_email_domain != $required_email_domain ]; then
echo " ❌ Invalid Author Email: $COMMIT_AUTHOR. Use a \`$required_email_domain\` domain email."
echo " See the commit here: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}/commits/$COMMIT_HASH"
invalid_commits=$((invalid_commits+1))
else
echo " ✅ Valid Author Email: $COMMIT_AUTHOR"
fi
done
if [ $invalid_commits -gt 0 ]; then
exit 1
fi

0 comments on commit 372efca

Please sign in to comment.