-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
66 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Delete branch after PR merge by bot gen | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed # 监听PR关闭事件(包括合并) | ||
|
||
workflow_dispatch: # 手动触发工作流 | ||
|
||
jobs: | ||
delete_branch: | ||
if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'update-version-') && github.event.pull_request.user.login == 'github-actions[bot]' }} # 条件:PR已合并、分支以 'update-version-' 开头、PR发起者是 github-actions[bot] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Git | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
# Step 1: Delete the branch that was used for the PR | ||
- name: Delete branch | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH_TO_DELETE: ${{ github.event.pull_request.head.ref }} # 使用env变量存储待删除的分支名称 | ||
run: | | ||
if [ "$BRANCH_TO_DELETE" != "main" ]; then | ||
git push origin --delete "$BRANCH_TO_DELETE" | ||
echo "Branch '$BRANCH_TO_DELETE' deleted." | ||
else | ||
echo "Cannot delete 'main' branch." |
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