From 0812cef0737ea801143df920c1df6c8e6aa67aa4 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 6 Jun 2024 13:41:11 -0700 Subject: [PATCH] more preview fixes, workflow_run is way too hard to use --- .github/workflows/build.yaml | 2 +- .github/workflows/preview.yaml | 30 ++++++++++++++++++++++++++---- abc | 0 3 files changed, 27 insertions(+), 5 deletions(-) delete mode 100644 abc diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 577174392..cbce6709d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,4 +23,4 @@ jobs: path: ./dist overwrite: true retention-days: 1 - name: build-artifacts-${{ github.event.number }} + name: build-artifacts-${{ github.run_id }} diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index c8052dc96..1d211fc02 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -4,6 +4,7 @@ on: workflow_run: workflows: ["build"] types: + - requested - completed permissions: @@ -12,24 +13,43 @@ permissions: jobs: preview: - #if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Download build artifacts uses: actions/download-artifact@v4 with: - name: build-artifacts-${{ github.event.number }} + name: build-artifacts-${{ github.event.workflow_run.id }} path: ./dist run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Find PR number + id: pr + uses: actions/github-script@v7 + with: + script: | + const response = await github.rest.search.issuesAndPullRequests({ + q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', + per_page: 1, + }) + const items = response.data.items + if (items.length < 1) { + console.error('No PRs found') + return + } + const pullRequestNumber = items[0].number + console.info("Pull request number is", pullRequestNumber) + return pullRequestNumber + # deploy - name: Deploy to Cloudflare Pages id: cloudflare-publish uses: cloudflare/pages-action@v1.5.0 with: - branch: ${{ github.event.number }} + branch: ${{ steps.pr.outputs.result }} projectName: connect accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} @@ -45,5 +65,7 @@ jobs: * mark your PR as a draft until it's ready to review * post the preview on [Discord](https://discord.comma.ai); feedback from users will speedup the PR review - deployed preview: https://${{ github.event.number }}.connect-d5y.pages.dev + deployed preview: https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev comment_tag: run_id + pr_number: ${{ steps.pr.outputs.result }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/abc b/abc deleted file mode 100644 index e69de29bb..000000000