Added: Changelog Feature #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull Request Workflow | |
permissions: | |
contents: write | |
pull-requests: write | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize] | |
jobs: | |
validate-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Check PR Title Format | |
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: pull branch updates | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git config pull.rebase true | |
git pull origin ${{ github.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}**\n$(jq -r ".pull_request.title" "$GITHUB_EVENT_PATH" | sed 's/^[^:]*: //' | sed 's/^/* /')" | |
# Update changelog file | |
sed -i "1s/^/${CHANGELOG_ENTRY}\n\n/" Changelog.md | |
- name: Commit and Push Changelog Update | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add Changelog.md | |
git commit -m "Update Changelog with changes from pull request #${{ github.event.number }}" | |
git push origin HEAD:${{ github.head_ref }} |