Reputation: 35805
What would be a good way to do the following in github actions:
Should I use raw git commands? Or the github cli? Or other actions?
What would you suggest?
Upvotes: 2
Views: 7094
Reputation: 1701
I was looking for a solution that didn't require using actions from a third-party and figured out that Github actions now support Github command line natively, if you use Github hosted runners. See: Using Github CLI in Workflows
This makes it super easy to create a pull request using the gh pr create command.
Something like this:
steps:
- name: create pull request
run: gh pr create -B base_branch -H branch_to_merge --title 'Merge branch_to_merge into base_branch' --body 'Created by Github action'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Upvotes: 12
Reputation: 1127
I've used Create Pull Request GHA (https://github.com/peter-evans/create-pull-request) and it is quite easy to use. Within the action itself you can even specify the branch name. In the next step, you can also run shell commands. Example as below:
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
Upvotes: 0