Skip to content

Commit

Permalink
merge: dev to main
Browse files Browse the repository at this point in the history
merge: dev to main
  • Loading branch information
CycleBai committed Jul 29, 2024
2 parents ee99f1b + b657352 commit 2f01b94
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 64 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/auto_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Auto PR

on:
push:
branches:
- dev

jobs:
handle_pr:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install GitHub CLI
run: sudo apt-get install gh

- name: Get committer username and email
run: |
committer_username=$(git log -1 --pretty=format:'%an')
committer_email=$(git log -1 --pretty=format:'%ae')
echo "committer_username=$committer_username" >> $GITHUB_ENV
echo "committer_email=$committer_email" >> $GITHUB_ENV
- name: Hash committer username
run: |
branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }')
echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV
echo "Branch name: ${{ env.branch_name }}"
- name: Configure git
run: |
git config --global user.name "${{ env.committer_username }}"
git config --global user.email "${{ env.committer_email }}"
- name: Check if PR branch exists
id: check_branch
run: |
git fetch origin
if git show-ref --verify --quiet refs/remotes/origin/${{ env.branch_name }}; then
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Create and push new branch based on dev
if: env.branch_exists == 'false'
run: |
git fetch origin
git checkout dev
git pull origin dev
git checkout -b ${{ env.branch_name }}
git push origin ${{ env.branch_name }}
- name: Fetch, rebase and push to existing branch
if: env.branch_exists == 'true'
run: |
git fetch origin
git checkout ${{ env.branch_name }}
git pull origin ${{ env.branch_name }} --rebase
git push origin ${{ env.branch_name }}
- name: Create Pull Request
if: env.branch_exists == 'false'
id: create_pr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.branch_name }}
base: main
title: "Auto PR from ${{ env.branch_name }}"
body: "This is an automated PR created from ${{ env.branch_name }}"
draft: false

- name: Wait for PR creation
if: env.branch_exists == 'false'
run: sleep 20 # 等待 20 秒,确保 PR 被创建

- name: Get PR number
if: env.branch_exists == 'false'
id: get_pr_number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number')
echo "pr_number=$pr_number" >> $GITHUB_ENV
echo "PR number: $pr_number"
- name: Append commit to existing PR
if: env.branch_exists == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number=$(gh pr list --state open --head ${{ env.branch_name }} --json number -q '.[0].number')
echo "pr_number=$pr_number" >> $GITHUB_ENV
echo "Appending commit to PR #${{ env.pr_number }}"
gh pr comment ${{ env.pr_number }} --body "New commits have been added to the PR."
64 changes: 0 additions & 64 deletions .github/workflows/sync-commit.yml

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Tips: 文档将很快迁移到单独仓库/网站。

您可以在遵循许可证的情况下自由分发/使用此项目。

## 贡献提示

如果您对此存储库具有写权限,请仅推送到 dev 分支,CI 系统会自动创建一个 Pull Request

## 贡献者

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
Expand Down

0 comments on commit 2f01b94

Please sign in to comment.