Skip to content

Commit

Permalink
Update preview.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
knownotunknown committed Oct 14, 2024
1 parent dfe36c8 commit e5dd670
Showing 1 changed file with 84 additions and 33 deletions.
117 changes: 84 additions & 33 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
})

0 comments on commit e5dd670

Please sign in to comment.