1
1
name : preview
2
2
3
3
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
9
8
10
9
permissions :
11
10
contents : read
12
11
pull-requests : write
13
12
14
13
jobs :
15
14
preview :
15
+ if : ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
16
16
runs-on : ubuntu-latest
17
17
timeout-minutes : 1
18
18
steps :
@@ -22,16 +22,36 @@ jobs:
22
22
- name : Download build artifacts
23
23
uses : actions/download-artifact@v4
24
24
with :
25
- name : build-artifacts-${{ github.run_id }}
25
+ name : build-artifacts-${{ github.event.workflow_run.id }}
26
26
path : ./dist
27
+ run-id : ${{ github.event.workflow_run.id }}
27
28
github-token : ${{ secrets.GITHUB_TOKEN }}
28
29
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
+
29
49
- name : Deploy to Cloudflare Pages
30
50
uses : cloudflare/wrangler-action@v3
31
51
with :
32
52
accountId : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
33
53
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
35
55
36
56
- name : Checkout ci-artifacts
37
57
uses : actions/checkout@v4
@@ -44,25 +64,25 @@ jobs:
44
64
- name : take screenshots
45
65
run : |
46
66
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
48
68
49
69
- name : Push Screenshots
50
70
working-directory : ${{ github.workspace }}/ci-artifacts
51
71
run : |
52
- git checkout -b new-connect/pr-${{ inputs.pr_number }}
72
+ git checkout -b new-connect/pr-${{ steps.pr.outputs.result }}
53
73
git config user.name "GitHub Actions Bot"
54
74
git config user.email "<>"
55
75
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
58
78
59
79
- name : Comment URL on PR
60
80
uses : thollander/actions-comment-pull-request@v2
61
81
with :
62
82
message : |
63
83
<!-- _(run_id **${{ github.run_id }}**)_ -->
64
84
65
- # deployed preview: https://${{ inputs.pr_number }}.connect-d5y.pages.dev
85
+ # deployed preview: https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev
66
86
67
87
Welcome to new-connect! Make sure to:
68
88
* read the [contributing guidelines](https://github.com/commaai/new-connect?tab=readme-ov-file#contributing)
@@ -72,20 +92,20 @@ jobs:
72
92
### Mobile
73
93
<table>
74
94
<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>
78
98
</tr>
79
99
</table>
80
100
81
101
### Desktop
82
102
<table>
83
103
<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">
87
107
</tr>
88
108
</table>
89
109
comment_tag : run_id
90
- pr_number : ${{ inputs.pr_number }}
110
+ pr_number : ${{ steps.pr.outputs.result }}
91
111
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments