-
Notifications
You must be signed in to change notification settings - Fork 40
166 lines (149 loc) · 6.74 KB
/
preview.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: preview
on:
workflow_run:
workflows: ["build"]
types:
- completed
permissions:
contents: read
pull-requests: write
checks: write
jobs:
pr:
name: Find PR number
runs-on: ubuntu-latest
outputs:
number: ${{ steps.pr.outputs.number }}
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
steps:
# use `gr pr view` to get the PR number
# https://github.com/orgs/community/discussions/25220#discussioncomment-11285971
- name: Find PR number
id: pr
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' \
--jq '"number=\(.number)"' \
>> $GITHUB_OUTPUT
- run: |
echo "PR number: ${{ steps.pr.outputs.number }}"
preview:
if: github.repository == 'commaai/new-connect' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
needs: pr
timeout-minutes: 2
outputs:
check_id: ${{ steps.check.outputs.result }}
steps:
- name: Create PR check
uses: actions/github-script@v7
id: check
with:
script: |
const response = await github.rest.checks.create({
name: 'preview',
head_sha: '${{ github.event.workflow_run.head_sha }}',
status: 'in_progress',
output: {
title: 'Preview deployment',
summary: 'In Progress',
},
owner: 'commaai',
repo: '${{ github.event.repository.name }}',
})
return response.data.id
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts-${{ github.event.workflow_run.id }}
path: ./dist
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- 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=${{ needs.pr.outputs.number }} --commit-dirty=true
- name: Checkout ci-artifacts
uses: actions/checkout@v4
with:
repository: commaai/ci-artifacts
ssh-key: ${{ secrets.CI_ARTIFACTS_DEPLOY_KEY }}
path: ${{ github.workspace }}/ci-artifacts
ref: master
- name: take screenshots
run: bun src/ci/screenshots.ts https://${{ needs.pr.outputs.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-${{ needs.pr.outputs.number }}
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add .
git commit -m "screenshots for PR #${{ needs.pr.outputs.number }}"
git push origin new-connect/pr-${{ needs.pr.outputs.number }} --force
- name: Comment URL on PR
uses: thollander/actions-comment-pull-request@v3
with:
message: |
<!-- _(run_id **${{ github.run_id }}**)_ -->
# deployed preview: https://${{ needs.pr.outputs.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)
* mark your PR as a draft until it's ready to review
* post the preview on [Discord](https://discord.comma.ai); feedback from users will speedup the PR review
### Mobile
<table>
<tr>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/Login-mobile.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/RouteActivity-mobile.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/RouteList-mobile.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/SettingsActivity-mobile.playwright.png"></td>
</tr>
</table>
### Desktop
<table>
<tr>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/Login-desktop.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/RouteActivity-desktop.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/RouteList-desktop.playwright.png"></td>
<td><img src="https://raw.githubusercontent.com/commaai/ci-artifacts/new-connect/pr-${{ needs.pr.outputs.number }}/SettingsActivity-desktop.playwright.png"></td>
</tr>
</table>
comment-tag: run_id
pr-number: ${{ needs.pr.outputs.number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
update_pr_check:
needs: preview
if: always() && github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Update PR check
uses: actions/github-script@v7
with:
script: |
github.rest.checks.update({
check_run_id: ${{ needs.preview.outputs.check_id }},
name: 'preview',
head_sha: '${{ github.event.workflow_run.head_sha }}',
status: 'completed',
conclusion: '${{ needs.preview.result }}',
output: {
title: 'Preview deployment',
summary: 'Result: ${{ needs.preview.result }}',
},
owner: 'commaai',
repo: '${{ github.event.repository.name }}',
})