Grabbing PR number from a push event?

Viewed 603

I have two GitHub actions workflow set up right now. One to publish an image to a jfrog registry, and another to promote the image with a new tag to the jfrog artifactory.

I am trying to use the github.event.number in the push workflow but for some reason you can't get the PR number if it isn't a pull_request being made... hence I get the error:

"Error response from daemon: manifest for (company jfrog artifactory url) - not found: manifest unknown: The named manifest is not known to the registry.

Anyone know any work arounds to this?

1 Answers

I successfully got the PR number from a PUSH event by using this implementation:

name: Get PR Number on PUSH event

on: [push, pull_request]

jobs:
  push:
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'push' }}
    steps:
      - uses: actions/checkout@v2.3.4
        with:
          fetch-depth: 0
      - name: Get Pull Request Number
        id: pr
        run: echo "::set-output name=pull_request_number::$(gh pr view --json number -q .number || echo "")"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - run: echo ${{ steps.pr.outputs.pull_request_number }}

  pull-request:
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'pull_request' }}
    steps:
      - run: echo ${{ github.event.number }}

I also let the pull_request job to show how to get it from this event as well (if you want to compare when you realize a push to an already opened PR).

Part of the solution was shared here but you also needed to add the actions/checkout to the job steps otherwise the gh cli didn't recognised the repo.

You can check the 2 workflow runs here:

Related