Skip to content

Commit

Permalink
Backport update to changelog.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Aug 28, 2024
1 parent 1c5a0f8 commit cd1b283
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cd1b283

Please sign in to comment.