From cd1b2838019cf9fc3608c12e9bfb34a72f2a3669 Mon Sep 17 00:00:00 2001 From: Alex Velez Date: Wed, 28 Aug 2024 13:02:33 -0500 Subject: [PATCH] Backport update to changelog.yml workflow --- .github/workflows/changelog.yml | 59 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 01e6449a2..37f85a82d 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -1,34 +1,31 @@ -name: Check Changelog.md +name: Check PR for Changelog + on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, edited, reopened] + jobs: - check-changelog: - runs-on: ubuntu-latest - permissions: write-all - steps: - - uses: actions/checkout@v4 - - name: Fetch changed files - id: fetch-changed-files - run: | - response=$(gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - repos/${owner}/${REPO}/pulls/${PULL_NUMBER}/files) - echo "$response" | jq '.' > response.json - - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - owner: ${{ github.repository_owner }} - REPO: ${{ github.event.repository.name }} - PULL_NUMBER: ${{ github.event.pull_request.number }} - - name: Check if Changelog.md is changed - run: | - if [[ $(jq '.[].filename' response.json) == *"CHANGELOG.md"* ]]; then - echo "Changelog.md is changed" - exit 0 - else - echo "Changelog.md is not changed" - exit 1 - fi + check-description: + runs-on: ubuntu-latest + steps: + + - name: Check PR Description + id: check_description + run: | + description=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH" | awk '/## Changelog/{flag=1; next} /##/{flag=0} flag' | grep -oP '(?<=- \*\*Description:\*\* ).*' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + echo "$description" + default_description="Summary of change(s)" + if [ -n "$description" ] && [ "$description" != "$default_description" ]; then + echo "containsChangelog=true" >> $GITHUB_OUTPUT + else + echo "containsChangelog=false" >> $GITHUB_OUTPUT + fi + - name: Results + run: | + if [[ "${{ steps.check_description.outputs.containsChangelog }}" == "true" || "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]]; then + echo "PR contains Changelog section/ PR made by Dependabot" + exit 0 + else + echo "Changelog section is missing or does not contain the required details" + exit 1 + fi \ No newline at end of file