Skip to content

Commit a35039d

Browse files
committed
Add pull request trigger to release drafter workflow
1 parent 6db946f commit a35039d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

.github/workflows/release-drafter.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
78
workflow_dispatch:
89

910
jobs:
1011
update_release_draft:
11-
if: ${{ !contains(github.head_ref, 'doc/changelog-update-') && startsWith(github.event.head_commit.message, 'Merge pull request') }}
1212
permissions:
1313
contents: write
1414
pull-requests: write
@@ -23,11 +23,19 @@ jobs:
2323
run: |
2424
# Define a regex pattern to match commit messages for changelog updates
2525
CHANGELOG_UPDATE_PATTERN="^Merge pull request #[0-9]+ from ${{ github.repository_owner }}/doc/changelog-update-.*$"
26-
27-
if [[ "${{ github.event.head_commit.message }}" =~ $CHANGELOG_UPDATE_PATTERN ]]; then
26+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
27+
TARGET_SHA="${{ github.event.pull_request.head.sha }}"
28+
else
29+
TARGET_SHA="${{ github.sha }}"
30+
fi
31+
MESSAGE=$(git log --format=%B -n 1 "$TARGET_SHA")
32+
33+
if [[ "$MESSAGE" =~ $CHANGELOG_UPDATE_PATTERN ]]; then
2834
echo "This commit is not target. Skip the workflow."
2935
echo "SKIP_JOB=true" >> $GITHUB_OUTPUT
3036
else
37+
echo "This commit is target."
38+
echo "$MESSAGE"
3139
echo "SKIP_JOB=false" >> $GITHUB_OUTPUT
3240
fi
3341
- uses: release-drafter/release-drafter@v6
@@ -46,6 +54,9 @@ jobs:
4654
pull-requests: write
4755

4856
steps:
57+
- name: Fetch Sources
58+
uses: actions/checkout@v4
59+
4960
- name: Get latest draft release title
5061
run: |
5162
TITLE=$(gh api repos/${{ github.repository }}/releases \
@@ -68,7 +79,6 @@ jobs:
6879
uses: actions/checkout@v4
6980
with:
7081
fetch-depth: 0
71-
ref: main
7282

7383
- name: Setup Java
7484
uses: actions/setup-java@v4
@@ -103,6 +113,6 @@ jobs:
103113
echo "No changes to commit."
104114
exit 0
105115
fi
106-
git commit -am "Update Version With Release Draft - $REPLACE_VERSION"
107-
git push origin main
108-
116+
git commit -am "Update Version With Release Draft - $RELEASE_VERSION"
117+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
118+
git push origin $BRANCH_NAME

0 commit comments

Comments
 (0)