From d094a70d3a33b58c743dbb42647f077538c3fbdf Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 22 Oct 2021 16:32:39 +0100 Subject: [PATCH] netlify.yaml: increased magic --- .github/workflows/netlify.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/netlify.yaml b/.github/workflows/netlify.yaml index b3b4d73e..8473eee3 100644 --- a/.github/workflows/netlify.yaml +++ b/.github/workflows/netlify.yaml @@ -23,8 +23,16 @@ jobs: - name: "🔍 Read PR number" id: readctx + # we need to find the PR number that corresponds to the branch, which we do by + # searching the GH API run: | - echo "::set-output name=prnumber::${{ github.event.workflow_run.pull_requests[0].number }}" + head_branch='${{github.event.workflow_run.head_repository.owner.login}}:${{github.event.workflow_run.head_branch}}' + echo "head branch: $head_branch" + pr_number=$(curl -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + 'https://api.github.com/repos/${{ github.repository }}/pulls?head=$head_branch' | + jq -r '.[] | .number') + echo "PR number: $pr_number" + echo "::set-output name=prnumber::$pr_number" - name: '📥 Download artifact' uses: dawidd6/action-download-artifact@af92a8455a59214b7b932932f2662fdefbd78126 # v2.15.0 @@ -45,7 +53,7 @@ jobs: deploy-message: "Deploy from GitHub Actions" enable-pull-request-comment: false enable-commit-comment: false - alias: pr${{ github.event.workflow_run.pull_requests[0].number }} + alias: pr${{ github.steps.readctx.outputs.prnumber }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} @@ -57,6 +65,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - pull-request-number: ${{ github.event.workflow_run.pull_requests[0].number }} + pull-request-number: ${{ github.steps.readctx.outputs.prnumber }} description-message: | Preview: ${{ steps.netlify.outputs.deploy-url }}