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

reject PR if identical to pull_request_template.md #281

Open
wants to merge 11 commits into
base: v2.x/staging
Choose a base branch
from
75 changes: 48 additions & 27 deletions .github/workflows/build-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,48 @@ jobs:
id: extract-changelog
run: |
PR_DESCRIPTION="${{ github.event.pull_request.body }}"
# Check if "changelog:" exists in PR description
if echo "$PR_DESCRIPTION" | grep -q "VERSION:" && echo "$PR_DESCRIPTION" | grep -q "CHANGELOG:"; then
# Extract text after "changelog:"
CHANGELOG_TEXT=$(echo $PR_DESCRIPTION | sed -n 's/.*CHANGELOG: \(.*\)/\1/p')
# Extract VERSION: from PR description
VERSION=$(echo "$PR_DESCRIPTION" | grep -oP 'VERSION:\s*\Kv\d+\.\d+\.\d+')
echo "Extracted changelog: $CHANGELOG_TEXT"
echo "::set-output name=changelog::$CHANGELOG_TEXT"
echo "::set-output name=version::$VERSION"
echo "$PR_DESCRIPTION" > /tmp/pr_description.txt
echo "PR DESCRIPTION saved to /tmp/pr_description.txt."
cat /tmp/pr_description.txt

# Save the template content to a file
TEMPLATE_CONTENT=$(sed 's/"//g' .github/pull_request_template.md)
echo "$TEMPLATE_CONTENT" > /tmp/template_content.txt
echo "Template content saved to /tmp/template_content.txt."
cat /tmp/template_content.txt

# Use diff to compare the two files
if diff -wB /tmp/pr_description.txt /tmp/template_content.txt > /dev/null; then
Copy link
Member

Choose a reason for hiding this comment

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

just diff .github/pull_request_template.md directly.

echo "ERROR: PR description is identical to the template."
exit 1
else
echo -e "No changelog and version information found in PR description please add them.\n Expected Format:\n VERSION:vX.XX.X\n CHANGELOG:This is changelog note.\n
To re-run the action, just make a push or commit after updating the PR description or updating the changelog via a manual file changing commit."
exit 1
echo "PR description and template are different."
fi
# Check if "changelog:" exists in PR description
if echo "$PR_DESCRIPTION" | grep -q "VERSION:" && echo "$PR_DESCRIPTION" | grep -q "CHANGELOG:"; then
# Extract content after "changelog:"
CHANGELOG_TEXT=$(echo $PR_DESCRIPTION | sed -n 's/.*CHANGELOG: \(.*\)/\1/p')
# Check if extracted CHANGELOG_TEXT is empty or identical to the template content
if [ -z "$CHANGELOG_TEXT" ] || [ diff -wB /tmp/pr_description.txt /tmp/template_content.txt ]; then
echo "The changelog information after 'CHANGELOG:' cannot be empty or identical to pull_request_template.md."
exit 1
fi
# Extract VERSION: from PR description
VERSION=$(echo "$PR_DESCRIPTION" | grep -oP 'VERSION:\s*\Kv\d+\.\d+\.\d+')
echo "Extracted changelog: $CHANGELOG_TEXT"
echo "::set-output name=changelog::$CHANGELOG_TEXT"
echo "::set-output name=version::$VERSION"
else
echo -e "No changelog and version information found in PR description please add them.\nExpected Format:\nVERSION:vX.XX.X\nCHANGELOG:This is changelog note.\nTo re-run the action, just make a push or commit after updating the PR description or updating the changelog via a manual file changing commit."
exit 1
fi
- name: Check PR body against changelog
if: steps.check-changelog.outputs.check_commit == 'false'
run: |
ESCAPED_CHANGELOG="${{ steps.extract-changelog.outputs.changelog }}"
ESCAPED_CHANGELOG=$(echo "$ESCAPED_CHANGELOG" | sed "s/'/\\\\'/g")
VERSION="${{ steps.extract-changelog.outputs.version }}"

if ! grep -Fq "$ESCAPED_CHANGELOG" CHANGELOG.md; then
# Check if version exists in CHANGELOG.md
if grep -q "^## $VERSION" CHANGELOG.md; then
Expand Down Expand Up @@ -121,21 +142,21 @@ jobs:
fi

check_changelog:
if: github.event_name == 'pull_request'
needs: update-changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
if: github.event_name == 'pull_request'
needs: update-changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Verify Changelog update
run: |
if [ "${{ needs.update-changelog.outputs.was_updated }}" != "true" ]; then
echo "CHANGELOG.md not updated, please update CHANGELOG.md with the changes made in the pull request"
exit 1
else
echo "changelog was updated successfully."
fi
- name: Verify Changelog update
run: |
if [ "${{ needs.update-changelog.outputs.was_updated }}" != "true" ]; then
echo "CHANGELOG.md not updated, please update CHANGELOG.md with the changes made in the pull request"
exit 1
else
echo "changelog was updated successfully."
fi

build:
runs-on: ubuntu-latest
Expand Down
Loading