问题
I have GitHub repository with 2 branches: "master" & "develop".
The workflow for us is that any code should be committed to the "develop" branch then pushed to GitHub, then a Pull Request should be created to merge the commits into the "master" branch.
I am trying to write an Action that will create a Pull Request once a developer pushes commits to the branch "develop" and had the following script:
name: Create pull request
on:
push:
branches:
- develop
jobs:
prForMasterBranch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
commit-message: update master branch
title: Update master branch
branch: develop
I can see that this action has executed successfully on "Push" event of the "develop" branch, but I can't see any new Pull Requests!
I checked the logs for the action and found these lines at the end of pull request creation:
Pushing pull request branch to 'origin/develop'
Branch 'develop' no longer differs from base branch 'master'
Closing pull request and deleting branch 'develop'
It seems I am missing something, but couldn't figure it out.
Any help is appreciated.
回答1:
If you look at the documentation of the create-pull-request action, it mentions that
Create Pull Request action will:
- Check for repository changes in the Actions workspace. This includes:
- untracked (new) files
- tracked (modified) files
- commits made during the workflow that have not been pushed
- Commit all changes to a new branch, or update an existing pull request branch.
- Create a pull request to merge the new branch into the base—the branch checked out in the workflow.
It would always need an intermediary branch where it can commit the changes.
So if you modify your workflow config as below, adding the Reset master branch
step to get the latest changes from the remote develop
branch and reset the master
branch, and specify branch: temp
for the action, the workflow would create a temp
branch with the same commits that you have pushed to develop
branch and open a PR from temp
to master
branch. In subsequent commits to develop, it would keep on making the same changes to temp
branch and open a PR similarly or update the existing PR.
name: Create pull request
on:
push:
branches:
- develop
jobs:
prForMasterBranch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Reset master branch
run: |
git fetch origin develop:develop
git reset --hard develop
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
commit-message: update master branch
title: Update master branch
branch: temp
Note that the temp
branch will have the exact commits that are pushed to the develop
branch.
来源:https://stackoverflow.com/questions/62172994/create-pull-request-on-git-push