This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (130 loc) · 4.82 KB
/
pull-request.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: pull-request
on:
pull_request:
types: [opened, reopened]
permissions:
pull-requests: write
contents: read
checks: write
id-token: write
pages: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- run: |
pnpm install
pnpm build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_VIRTUAL_NATSUMATSURI }}
channelId: live
projectId: virtual-natsumatsuri
lighthouse:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lighthouse CI
uses: treosh/lighthouse-ci-action@v10
id: lighthouse
with:
uploadArtifacts: true
temporaryPublicStorage: true
urls: https://virtual-natsumatsuri.web.app/
- name: Get Comment Body
uses: actions/github-script@v5
id: get-comment-body
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const results = ${{ steps.lighthouse.outputs.manifest }}
const links = ${{ steps.lighthouse.outputs.links }}
const mark = (value) => {
if (value >= 0.9) {
return '🟢';
} else if (value >= 0.5) {
return '🟡';
} else {
return '🔴';
}
};
const body = `
# Lighthouse Report
| URL | Performance | Accessibility | Best Practices | SEO | PWA | Details |
| --- | ----------- | ------------- | -------------- | --- | --- | ------- |
${results.map((result) => `| ${result.url} | ${mark(result.summary.performance)}${Math.trunc(result.summary.performance * 100)} | ${mark(result.summary.accessibility)}${Math.trunc(result.summary.accessibility * 100)} | ${mark(result.summary['best-practices'])}${Math.trunc(result.summary['best-practices'] * 100)} | ${mark(result.summary.seo)}${Math.trunc(result.summary.seo * 100)} | ${mark(result.summary.pwa)}${Math.trunc(result.summary.pwa * 100)} | :pencil: [result](${links[result.url]}) |`).join('\n')}
`;
core.setOutput("body", body)
- name: Find Comment
uses: peter-evans/find-comment@v2
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
includes-comment: "# Lighthouse Report"
- name: Create Comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id == '0'
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}
- name: Update Comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id != '0'
with:
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: ${{ steps.get-comment-body.outputs.body }}
edit-mode: replace
visualizer:
needs: lighthouse
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install and Build
uses: pnpm/action-setup@v4
with:
version: 9
- run: |
pnpm install
pnpm build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./dist/visualizer/
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
id: deployment
with:
branch: ${{ github.head_ref }}
- name: Find existing comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: '# Visualizer Report'
- name: Create comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id == '0'
with:
issue-number: ${{ github.event.number }}
body: |
# Visualizer Report
You can view the results [here](${{ steps.deployment.outputs.page_url }}).
- name: Update comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id != '0'
with:
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
# Visualizer Report
You can view the results [here](${{ steps.deployment.outputs.page_url }}).
edit-mode: replace