From e60935b676efc1f16c36966546e2adc433f5b325 Mon Sep 17 00:00:00 2001 From: signed-long <38993953+signed-long@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:47:54 -0600 Subject: [PATCH] CI: Call preview from build workflow (#83) --- .github/workflows/build.yaml | 7 ++++ .github/workflows/preview.yaml | 58 +++++++++++----------------------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1d4744bb..17162a4c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -50,3 +50,10 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} command: pages deploy dist --project-name=connect --branch=new-connect --commit-dirty=true + + preview: + needs: build + if: github.event_name == 'pull_request' && github.repository == 'commaai/new-connect' + uses: commaai/new-connect/.github/workflows/preview.yaml@master + with: + pr_number: ${{ github.event.number }} diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 979d7f63..ef04b7fe 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -1,10 +1,11 @@ name: preview on: - workflow_run: - workflows: ["build"] - types: - - completed + workflow_call: + inputs: + pr_number: + required: true + type: number permissions: contents: read @@ -12,7 +13,6 @@ permissions: jobs: preview: - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} runs-on: ubuntu-latest timeout-minutes: 1 steps: @@ -22,36 +22,16 @@ jobs: - name: Download build artifacts uses: actions/download-artifact@v4 with: - name: build-artifacts-${{ github.event.workflow_run.id }} + name: build-artifacts-${{ github.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: - retries: 3 - 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 - - name: Deploy to Cloudflare Pages uses: cloudflare/wrangler-action@v3 with: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} - command: pages deploy dist --project-name=connect --branch=${{ steps.pr.outputs.result }} --commit-dirty=true + command: pages deploy dist --project-name=connect --branch=${{ inputs.pr_number }} --commit-dirty=true - name: Checkout ci-artifacts uses: actions/checkout@v4 @@ -64,17 +44,17 @@ jobs: - name: take screenshots run: | bun install --frozen-lockfile - node src/ci/screenshots.cjs https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev ${{ github.workspace }}/ci-artifacts + node src/ci/screenshots.cjs https://${{ inputs.pr_number }}.connect-d5y.pages.dev ${{ github.workspace }}/ci-artifacts - name: Push Screenshots working-directory: ${{ github.workspace }}/ci-artifacts run: | - git checkout -b new-connect/pr-${{ steps.pr.outputs.result }} + git checkout -b new-connect/pr-${{ inputs.pr_number }} git config user.name "GitHub Actions Bot" git config user.email "<>" git add . - git commit -m "screenshots for PR #${{ steps.pr.outputs.result }}" - git push origin new-connect/pr-${{ steps.pr.outputs.result }} --force + git commit -m "screenshots for PR #${{ inputs.pr_number }}" + git push origin new-connect/pr-${{ inputs.pr_number }} --force - name: Comment URL on PR uses: thollander/actions-comment-pull-request@v2 @@ -82,7 +62,7 @@ jobs: message: | - # deployed preview: https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev + # deployed preview: https://${{ inputs.pr_number }}.connect-d5y.pages.dev Welcome to new-connect! Make sure to: * read the [contributing guidelines](https://github.com/commaai/new-connect?tab=readme-ov-file#contributing) @@ -92,20 +72,20 @@ jobs: ### Mobile - - - + + +
### Desktop - - - + + +
comment_tag: run_id - pr_number: ${{ steps.pr.outputs.result }} + pr_number: ${{ inputs.pr_number }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}