Skip to content

Commit d5b3972

Browse files
committed
Merge branch 'master' into route-card-redesign
2 parents f84c6bb + f43ced7 commit d5b3972

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

.github/workflows/build.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,3 @@ jobs:
5050
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
5151
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
5252
command: pages deploy dist --project-name=connect --branch=new-connect --commit-dirty=true
53-
54-
preview:
55-
needs: build
56-
if: github.event_name == 'pull_request' && github.repository == 'commaai/new-connect'
57-
uses: commaai/new-connect/.github/workflows/preview.yaml@master
58-
with:
59-
pr_number: ${{ github.event.number }}

.github/workflows/preview.yaml

+39-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: preview
22

33
on:
4-
workflow_call:
5-
inputs:
6-
pr_number:
7-
required: true
8-
type: number
4+
workflow_run:
5+
workflows: ["build"]
6+
types:
7+
- completed
98

109
permissions:
1110
contents: read
1211
pull-requests: write
1312

1413
jobs:
1514
preview:
15+
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
1616
runs-on: ubuntu-latest
1717
timeout-minutes: 1
1818
steps:
@@ -22,16 +22,36 @@ jobs:
2222
- name: Download build artifacts
2323
uses: actions/download-artifact@v4
2424
with:
25-
name: build-artifacts-${{ github.run_id }}
25+
name: build-artifacts-${{ github.event.workflow_run.id }}
2626
path: ./dist
27+
run-id: ${{ github.event.workflow_run.id }}
2728
github-token: ${{ secrets.GITHUB_TOKEN }}
2829

30+
- name: Find PR number
31+
id: pr
32+
uses: actions/github-script@v7
33+
with:
34+
retries: 3
35+
script: |
36+
const response = await github.rest.search.issuesAndPullRequests({
37+
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
38+
per_page: 1,
39+
})
40+
const items = response.data.items
41+
if (items.length < 1) {
42+
console.error('No PRs found')
43+
return
44+
}
45+
const pullRequestNumber = items[0].number
46+
console.info('Pull request number is', pullRequestNumber)
47+
return pullRequestNumber
48+
2949
- name: Deploy to Cloudflare Pages
3050
uses: cloudflare/wrangler-action@v3
3151
with:
3252
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
3353
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }}
34-
command: pages deploy dist --project-name=connect --branch=${{ inputs.pr_number }} --commit-dirty=true
54+
command: pages deploy dist --project-name=connect --branch=${{ steps.pr.outputs.result }} --commit-dirty=true
3555

3656
- name: Checkout ci-artifacts
3757
uses: actions/checkout@v4
@@ -44,25 +64,25 @@ jobs:
4464
- name: take screenshots
4565
run: |
4666
bun install --frozen-lockfile
47-
node src/ci/screenshots.cjs https://${{ inputs.pr_number }}.connect-d5y.pages.dev ${{ github.workspace }}/ci-artifacts
67+
node src/ci/screenshots.cjs https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev ${{ github.workspace }}/ci-artifacts
4868
4969
- name: Push Screenshots
5070
working-directory: ${{ github.workspace }}/ci-artifacts
5171
run: |
52-
git checkout -b new-connect/pr-${{ inputs.pr_number }}
72+
git checkout -b new-connect/pr-${{ steps.pr.outputs.result }}
5373
git config user.name "GitHub Actions Bot"
5474
git config user.email "<>"
5575
git add .
56-
git commit -m "screenshots for PR #${{ inputs.pr_number }}"
57-
git push origin new-connect/pr-${{ inputs.pr_number }} --force
76+
git commit -m "screenshots for PR #${{ steps.pr.outputs.result }}"
77+
git push origin new-connect/pr-${{ steps.pr.outputs.result }} --force
5878
5979
- name: Comment URL on PR
6080
uses: thollander/actions-comment-pull-request@v2
6181
with:
6282
message: |
6383
<!-- _(run_id **${{ github.run_id }}**)_ -->
6484
65-
# deployed preview: https://${{ inputs.pr_number }}.connect-d5y.pages.dev
85+
# deployed preview: https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev
6686
6787
Welcome to new-connect! Make sure to:
6888
* read the [contributing guidelines](https://github.com/commaai/new-connect?tab=readme-ov-file#contributing)
@@ -72,20 +92,20 @@ jobs:
7292
### Mobile
7393
<table>
7494
<tr>
75-
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/Login-mobile.playwright.png"></td>
76-
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/RouteActivity-mobile.playwright.png"></td>
77-
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/RouteList-mobile.playwright.png"></td>
95+
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/Login-mobile.playwright.png"></td>
96+
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/RouteActivity-mobile.playwright.png"></td>
97+
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/RouteList-mobile.playwright.png"></td>
7898
</tr>
7999
</table>
80100
81101
### Desktop
82102
<table>
83103
<tr>
84-
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/Login-desktop.playwright.png">
85-
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/RouteActivity-desktop.playwright.png">
86-
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ inputs.pr_number }}/RouteList-desktop.playwright.png">
104+
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/Login-desktop.playwright.png">
105+
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/RouteActivity-desktop.playwright.png">
106+
<img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ steps.pr.outputs.result }}/RouteList-desktop.playwright.png">
87107
</tr>
88108
</table>
89109
comment_tag: run_id
90-
pr_number: ${{ inputs.pr_number }}
110+
pr_number: ${{ steps.pr.outputs.result }}
91111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)