5

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?

ProjectLuo
  • 93
  • 5
  • Hi ProjectLuo, I think your issue might be related to this one: https://stackoverflow.com/questions/68462262/for-what-reasons-could-a-pr-number-not-be-present-in-a-pr-event and the solution could be to use this action: https://github.com/marketplace/actions/find-current-pull-request – GuiFalourd Nov 24 '21 at 19:35
  • Hi GuiFalourd, thanks for the reply. Tried adding the solution you have linked and i'm still getting the respective error. I think the PR number gets completely lost or something when I do a push.... hmmm – ProjectLuo Nov 24 '21 at 20:07
  • In that case, [as referred here](https://github.community/t/github-actions-no-way-to-get-pr-number-on-push-event/16052/2), what you could do is to get the pull request information using the endpoint https://developer.github.com/v3/repos/commits/#list-pull-requests-associated-with-commit using the `SHA` (as you can get the GITHUB_SHA from the env variables). – GuiFalourd Nov 24 '21 at 20:25
  • There are also good insights here: https://stackoverflow.com/questions/59077079/how-to-get-pull-request-number-within-github-actions-workflow (in particular the most recent answer). – GuiFalourd Nov 24 '21 at 20:29

1 Answers1

5

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:

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71