From 0c1cc541e3215b353a6af9c61d364d87325951f5 Mon Sep 17 00:00:00 2001 From: Himani1519 Date: Thu, 5 Oct 2023 14:05:23 +0530 Subject: [PATCH] seperate steps for template comparsion and extract changelog Signed-off-by: Himani1519 --- .github/workflows/build_test.yml | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 312640e..cb0fdf9 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -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: |