forked from Uniswap/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (122 loc) Β· 5.13 KB
/
check-and-deploy.yml
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
name: Check Benchmarks & Deploy
env:
VERCEL_TEAM_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
jobs:
check-uniswap-benchmarks:
name: Check uniswap Benchmarks
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.20.4
cache: 'yarn'
cache-dependency-path: yarn.lock
- name: Install Dependencies
run: yarn install
- name: Check Licensure
id: check_licensure
run: yarn run check-licensure
- name: Run Linter
run: yarn lint
- name: Check Type Correctness
run: yarn run tsc --noEmit
- name: Check Formatting
run: yarn prettier --check .
audit_with_lighthouse:
name: Audit with Lighthouse
runs-on: ubuntu-latest
if: github.ref != 'refs/head/main' && github.ref != 'refs/heads/prod'
permissions:
contents: write
pull-requests: write
defaults:
run:
working-directory: ./
steps:
# Step 1: Retrieve the Vercel Preview URL
- name: vercel-preview-url
uses: zentered/[email protected]
id: vercel_preview_url
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel_team_id: ${{ secrets.VERCEL_ORG_ID }}
# Step 2: Wait for the Vercel deployment to be ready
- uses: UnlyEd/github-action-await-vercel@v1
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: ${{ steps.vercel_preview_url.outputs.preview_url }}
timeout: 420
poll-interval: 15
- uses: actions/checkout@v3
- name: Audit preview URL with Lighthouse (mobile)
id: lighthouse_audit_mobile
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ steps.vercel_preview_url.outputs.preview_url }}
uploadArtifacts: true
temporaryPublicStorage: true
- name: Audit preview URL with Lighthouse (desktop)
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ steps.vercel_preview_url.outputs.preview_url }}
uploadArtifacts: true
temporaryPublicStorage: true
configPath: .github/lighthouse/lighthouse-config.json
- name: Format Lighthouse score
id: format_lighthouse_score
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const mobileLinks = ${{ steps.lighthouse_audit_mobile.outputs.links }};
const mobileResult = ${{ steps.lighthouse_audit_mobile.outputs.manifest }}[0].summary;
const desktopLinks = ${{ steps.lighthouse_audit.outputs.links }};
const desktopResult = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary;
const previewUrl = "${{ steps.vercel_preview_url.outputs.preview_url }}";
const formatResult = (res) => Math.round((res * 100));
const score = res => res >= 90 ? 'π’' : res >= 50 ? 'π ' : 'π΄';
Object.keys(mobileResult).forEach(key => mobileResult[key] = formatResult(mobileResult[key]));
Object.keys(desktopResult).forEach(key => desktopResult[key] = formatResult(desktopResult[key]));
const comment = [
`## β‘οΈ Lighthouse Report`,
`### Mobile ([view report](${Object.values(mobileLinks)[0]}))`,
'| Category | Score |',
'| --- | --- |',
`| ${score(mobileResult.performance)} Performance | ${mobileResult.performance} |`,
`| ${score(mobileResult.accessibility)} Accessibility | ${mobileResult.accessibility} |`,
`| ${score(mobileResult['best-practices'])} Best practices | ${mobileResult['best-practices']} |`,
`| ${score(mobileResult.seo)} SEO | ${mobileResult.seo} |`,
` `,
`### Desktop ([view report](${Object.values(desktopLinks)[0]}))`,
'| Category | Score |',
'| --- | --- |',
`| ${score(desktopResult.performance)} Performance | ${desktopResult.performance} |`,
`| ${score(desktopResult.accessibility)} Accessibility | ${desktopResult.accessibility} |`,
`| ${score(desktopResult['best-practices'])} Best practices | ${desktopResult['best-practices']} |`,
`| ${score(desktopResult.seo)} SEO | ${desktopResult.seo} |`,
` `,
`*Lighthouse ran on [${previewUrl}](${previewUrl})*`
].join('\n');
core.setOutput("comment", comment);
- name: Add comment to PR
uses: mshick/add-pr-comment@v1
with:
message: |
${{ steps.format_lighthouse_score.outputs.comment }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub tokens
allow-repeats: false # This is the default