Skip to content

Commit

Permalink
seperate steps for template comparsion and extract changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Himani1519 <[email protected]>
  • Loading branch information
Himani1519 committed Oct 5, 2023
1 parent 1b96d26 commit 0c1cc54
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,56 @@ jobs:
echo "ERROR: CHANGELOG.md has not been updated."
echo "::set-output name=check_commit::false"
fi
- name: Compare PR description with template
if: steps.check-changelog.outputs.check_commit == 'false'
run: |
PR_DESCRIPTION="${{ github.event.pull_request.body }}"
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
echo "ERROR: PR description is identical to the template."
exit 1
else
echo "PR description and template are different."
fi
- name: Extract changelog info
if: steps.check-changelog.outputs.check_commit == 'false'
id: extract-changelog
run: |
PR_DESCRIPTION="${{ github.event.pull_request.body }}"
PR_DESCRIPTION=$(cat /tmp/pr_description.txt)
# 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:"
# 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
TEMPLATE_CONTENT=$(cat /tmp/template_content.txt)
if [ -z "$CHANGELOG_TEXT" ] || [ "$CHANGELOG_TEXT" == "$TEMPLATE_CONTENT" ]; 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*\K\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.\n Expected Format:\n VERSION:X.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."
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: |
Expand Down

0 comments on commit 0c1cc54

Please sign in to comment.