Skip to content

Added: Pull-Request title check and Changelog feature #8

Added: Pull-Request title check and Changelog feature

Added: Pull-Request title check and Changelog feature #8

Workflow file for this run

name: Pull Request Title Check
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
validate-pull-request-title:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Validate Pull Request Title
run: |
PR_TITLE=$(jq -r ".pull_request.title" "$GITHUB_EVENT_PATH")
# Check if the pull request title matches the required format
if ! echo "$PR_TITLE" | grep -qE '^(Added|Changed|Deprecated|Removed|Fixed|Security): .+$'; then
echo "Pull request title '$PR_TITLE' does not match the required format."
echo "::error::Pull request title does not match the required format."
exit 1
fi
- name: Checkout PR Branch
run: git checkout ${{ github.event.pull_request.head.ref }}
- name: Update Changelog
if: success()
run: |
# Extract version and date from previous changelog entry
PREVIOUS_VERSION=$(grep -oP '(?<=## \[)[^\]]+' Changelog.md | head -n 1)
DATE=$(date +'%Y-%m-%d')
CHANGELOG_ENTRY="## [${PREVIOUS_VERSION}] - ${DATE}
$(git log --format='- %s' origin/${PR_BRANCH}^1..HEAD | sed 's/^\([A-Z][a-zA-Z]*\): /\n### \1\n- /g' | sed ':a;N;$!ba;s/\n\n/\n/g')"
# Update changelog file
sed -i "/## \[${PREVIOUS_VERSION}\]/a ${CHANGELOG_ENTRY}" Changelog.md
# Commit and push changelog update
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add Changelog.md
git commit -m "Update Changelog for ${PREVIOUS_VERSION} with changes from pull request #$PR_NUMBER"
git push origin $PR_BRANCH