From 734085123b4c9857dc487acd9db58b4f7d7158a3 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:12:41 -0300 Subject: [PATCH] NO-ISSUE - Use yet another alternative to grab PR ID (#569) NOISSUE - Use yet another alternative to grab PR ID Signed-off-by: Ricardo Zanini --- .github/workflows/pr-preview-build.yml | 5 +++++ .github/workflows/pr-preview-publish.yml | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-preview-build.yml b/.github/workflows/pr-preview-build.yml index 3434a3384..1c2a785ae 100644 --- a/.github/workflows/pr-preview-build.yml +++ b/.github/workflows/pr-preview-build.yml @@ -51,6 +51,11 @@ jobs: - name: Install dependencies and build run: npm run local-install-build + - name: Store PR id + if: github.event_name == 'pull_request' + run: | + echo ${{ github.event.number }} > ./build/site/pr-id.txt + - name: Publishing directory for PR preview if: github.event_name == 'pull_request' uses: actions/upload-artifact@v4 diff --git a/.github/workflows/pr-preview-publish.yml b/.github/workflows/pr-preview-publish.yml index d6d7127c2..4598c7139 100644 --- a/.github/workflows/pr-preview-publish.yml +++ b/.github/workflows/pr-preview-publish.yml @@ -31,13 +31,6 @@ jobs: if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - - name: Get PR number - id: get_pr_number - run: | - PR_URL=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.workflow_run.url }}/pull_requests | jq -r '.pull_requests[0].url') - PR_NUMBER=$(basename $PR_URL) - echo "PR number: $PR_NUMBER" - shell: bash - name: Download PR Artifact uses: actions/download-artifact@v4 @@ -47,9 +40,15 @@ jobs: run-id: ${{ github.event.workflow_run.id }} path: ./build/site + - name: Store PR id as variable + id: pr + run: | + echo "id=$(<./build/site/pr-id.txt)" >> $GITHUB_OUTPUT + rm -f pr-id.txt + - name: Publish to Surge for preview id: deploy - run: npx surge ./build/site --domain https://sonataflow-docs-preview-pr-${{ env.PR_NUMBER }}.surge.sh --token ${{ secrets.SURGE_LOCAL_TOKEN }} + run: npx surge ./build/site --domain https://sonataflow-docs-preview-pr-${{ steps.pr.outputs.id }}.surge.sh --token ${{ secrets.SURGE_LOCAL_TOKEN }} - name: Update PR status comment on success if: success() @@ -57,10 +56,10 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} body: | - 🎊 PR Preview ${{ github.sha }} has been successfully built and deployed. See the documentation preview: https://sonataflow-docs-preview-pr-${{ env.PR_NUMBER }}.surge.sh + 🎊 PR Preview ${{ github.sha }} has been successfully built and deployed. See the documentation preview: https://sonataflow-docs-preview-pr-${{ steps.pr.outputs.id }}.surge.sh body-include: "" - number: ${{ env.PR_NUMBER }} + number: ${{ steps.pr.outputs.id }} emojis: "heart" - name: Update PR status comment on failure @@ -73,5 +72,5 @@ jobs: body-include: "" - number: ${{ env.PR_NUMBER }} + number: ${{ steps.pr.outputs.id }} emojis: "confused"