Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Himani1519 <[email protected]>
  • Loading branch information
Himani1519 committed Oct 12, 2023
1 parent a7b571e commit 969c6c4
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions .github/workflows/build-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,57 +69,65 @@ jobs:
fi
- name: Compare PR description with template
if: steps.check-changelog.outputs.check_commit == 'false'
id: compare-with-template
env:
PR_DESCRIPTION: ${{ github.event.pull_request.body }}
run: |
PR_DESCRIPTION="${{ github.event.pull_request.body }}"
# Safely print the PR description using Node.js
node -e 'const prDesc = process.env.PR_DESCRIPTION; console.log("----- PR Description Start -----\n" + prDesc + "\n----- PR Description End -----");'
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
# Save the template content to a file without modifying it
cat .github/pull_request_template.md > /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
- name: Extract changelog info using Node.js
if: steps.check-changelog.outputs.check_commit == 'false'
id: extract-changelog
run: |
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 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 content after "changelog:" using Node.js
CHANGELOG_TEXT=$(node -e "const lines = process.env.PR_DESCRIPTION.split('\n'); \
for (const line of lines) { \
if (line.startsWith('CHANGELOG: ')) { \
console.log(line.substring('CHANGELOG: '.length)); \
break; \
} \
}")
# 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=changelog::$(echo "$CHANGELOG_TEXT" | base64)"
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
env:
PR_DESCRIPTION: ${{ env.PR_DESCRIPTION }}

- 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 "${{ steps.extract-changelog.outputs.changelog }}" | base64 -d)
echo "$ESCAPED_CHANGELOG"
ESCAPED_CHANGELOG=$(echo "$ESCAPED_CHANGELOG" | sed "s/'/\\\\'/g")
VERSION="${{ steps.extract-changelog.outputs.version }}"
if ! grep -Fq "$ESCAPED_CHANGELOG" CHANGELOG.md; then
Expand All @@ -139,6 +147,7 @@ jobs:
git commit -s -m "Update changelog with PR #${{ github.event.pull_request.number }} description"
git push
fi
- name: check for changes
id: check-change
run: |
Expand All @@ -147,7 +156,7 @@ jobs:
echo "::set-output name=change_detected::false"
else
echo "::set-output name=change_detected::true"
fi
fi
check_changelog:
if: github.event_name == 'pull_request'
needs: update-changelog
Expand Down

0 comments on commit 969c6c4

Please sign in to comment.