4

In a GitHub action, I create a file with a script. Then I can use git create a branch, add the file, commit the file and push the branch to the repo. All using git.

I then want to create a PR from within my action so I'm using GH CLI. In my steps this is the PR relate part:

echo "GH CLI Auth"
gh auth login --with-token < ${{ secrets.GITHUB_TOKEN }}
echo "Create PR"
gh pr create --reviewer myhandle --title "Show Notes ${{ env.NEWFILE_PATH }}" --body "Show Notes ${{ env.NEWFILE_PATH }}"

But I'm getting an error.

GH CLI Auth
/home/runner/work/_temp/<GUID_CENSORED>.sh: line 13: ***: No such file or directory
Error: Process completed with exit code 1.

I am giving the GitHub Token write access to the code and pull-requests.

permissions:
  contents: write
  pull-requests: write

I'm stumped. Thanks for the help!

Patrick
  • 2,044
  • 1
  • 25
  • 44

1 Answers1

5

You can use environment variable for that. Either GH_TOKEN or GITHUB_TOKEN, check docs for details.

Here is an example:

name: Create PR workflow example
on: push
jobs:
  create_pr:
    runs-on: ubuntu-latest
    steps:
      - run: gh pr create --title "The fix" --body "This fixes the issue"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
frennky
  • 12,581
  • 10
  • 47
  • 63
  • I see now, I was doing that on the step before the one I was actually using `gh cli` in. Once I moved that, as you pointed out it worked. Thanks! – Patrick Dec 16 '21 at 18:34