From e5dd6705ac21baf9adb7747e39c9b65a0ff85e2f Mon Sep 17 00:00:00 2001 From: Som Gupta <78577376+knownotunknown@users.noreply.github.com> Date: Mon, 14 Oct 2024 18:39:01 -0500 Subject: [PATCH] Update preview.yaml --- .github/workflows/preview.yaml | 117 +++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 33 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 7735bb62..03442f3e 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -1,10 +1,10 @@ -name: preview +name: Build and Preview on: - workflow_run: - workflows: ["build"] - types: - - completed + push: + branches: + - master + pull_request: workflow_dispatch: permissions: @@ -13,8 +13,75 @@ permissions: checks: write jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 1 + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + + - run: bun install --frozen-lockfile + - run: timeout 12s bun pre-commit + - run: bun run test + - run: ./check-lines.sh + + - name: Bundle size breakdown + run: | + bun run build --sourcemap true + node src/ci/dependency_report.cjs dist/ | column -t -s ":" + - run: ./check-bundle-size.sh + + - name: Build for Lighthouse + run: bun run build + + - name: Run Lighthouse CI + uses: treosh/lighthouse-ci-action@v10 + id: lighthouse + with: + configPath: './lighthouserc.json' + uploadArtifacts: true + temporaryPublicStorage: true + + - name: Upload Lighthouse reports + uses: actions/upload-artifact@v4 + with: + name: lighthouse-reports + path: ${{ steps.lighthouse.outputs.resultsPath }} + + - name: Check Lighthouse CI status + if: steps.lighthouse.outputs.assertionResults != '[]' + run: | + echo "Lighthouse CI assertions failed. Check the report for details." + exit 1 + + build: + runs-on: ubuntu-latest + timeout-minutes: 1 + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + - run: bun install --frozen-lockfile + - run: bun run build + + - name: Upload built project + uses: actions/upload-artifact@v4 + with: + path: ./dist + overwrite: true + retention-days: 1 + name: build-artifacts-${{ github.run_id }} + + - name: Deploy to Cloudflare Pages + if: github.ref == 'refs/heads/master' && github.repository == 'commaai/new-connect' + uses: cloudflare/wrangler-action@v3 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} + command: pages deploy dist --project-name=connect --branch=new-connect --commit-dirty=true + preview: - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} + needs: build + if: github.event_name == 'pull_request' runs-on: ubuntu-latest timeout-minutes: 1 outputs: @@ -28,14 +95,14 @@ jobs: script: | const response = await github.rest.checks.create({ name: 'preview', - head_sha: '${{ github.event.workflow_run.head_sha }}', + head_sha: '${{ github.event.pull_request.head.sha }}', status: 'in_progress', output: { title: 'Preview deployment', summary: 'In Progress', }, - owner: 'commaai', - repo: '${{ github.event.repository.name }}', + owner: context.repo.owner, + repo: context.repo.repo, }) return response.data.id @@ -45,28 +112,12 @@ 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 }}', - }) - 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 + run: echo "result=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - name: Deploy to Cloudflare Pages uses: cloudflare/wrangler-action@v3 @@ -137,8 +188,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} update_pr_check: - needs: preview - if: always() && github.event.workflow_run.event == 'pull_request' + needs: [build, preview] + if: always() && github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Update PR check @@ -148,13 +199,13 @@ jobs: github.rest.checks.update({ check_run_id: ${{ needs.preview.outputs.check_id }}, name: 'preview', - head_sha: '${{ github.event.workflow_run.head_sha }}', + head_sha: '${{ github.event.pull_request.head.sha }}', status: 'completed', conclusion: '${{ needs.preview.result }}', output: { title: 'Preview deployment', summary: 'Result: ${{ needs.preview.result }}', }, - owner: 'commaai', - repo: '${{ github.event.repository.name }}', - }) + owner: context.repo.owner, + repo: context.repo.repo, + }) \ No newline at end of file