generated from QubitPi/react-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove GitHub Actions (#47)"
This reverts commit 5c3a628.
- Loading branch information
Showing
10 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"fields": { | ||
"type": "爱" | ||
}, | ||
"id": "n6t9801j5xuxhln9wh3na", | ||
"source": "nojchzzhfk8wqftekbufl", | ||
"target": "nl8uppsqmkg586x5u71q9" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"fields": { | ||
"name": "我", | ||
"type": "entity" | ||
}, | ||
"id": "nojchzzhfk8wqftekbufl" | ||
}, | ||
{ | ||
"fields": { | ||
"name": "中国", | ||
"type": "entity" | ||
}, | ||
"id": "nl8uppsqmkg586x5u71q9" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2024 Jiaqi Liu. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// @ts-check | ||
|
||
/** @typedef {Record<'performance' | 'accessibility' | 'best-practices' | 'seo' | 'pwa', number>} LighthouseSummary */ | ||
|
||
/** @type {Record<keyof LighthouseSummary, string>} */ | ||
const summaryKeys = { | ||
performance: "Performance", | ||
accessibility: "Accessibility", | ||
"best-practices": "Best Practices", | ||
seo: "SEO", | ||
pwa: "PWA", | ||
}; | ||
|
||
/** @param {number} rawScore */ | ||
const scoreEntry = (rawScore) => { | ||
const score = Math.round(rawScore * 100); | ||
// eslint-disable-next-line no-nested-ternary | ||
const scoreIcon = score >= 90 ? "🟢" : score >= 50 ? "🟠" : "🔴"; | ||
return `${scoreIcon} ${score}`; | ||
}; | ||
|
||
/** | ||
* @param {string} url | ||
* @returns {module:url.URL} | ||
*/ | ||
function createURL(url) { | ||
try { | ||
return new URL(url); | ||
} catch (e) { | ||
throw new Error(`Can't create URL for string=${url}`, { cause: e }); | ||
} | ||
} | ||
|
||
/** | ||
* @param {Object} param0 | ||
* @param {string} param0.url | ||
* @param {LighthouseSummary} param0.summary | ||
* @param {string} param0.reportUrl | ||
*/ | ||
const createMarkdownTableRow = ({ url, summary, reportUrl }) => | ||
[ | ||
`| [${createURL(url).pathname}](${url})`, | ||
.../** @type {(keyof LighthouseSummary)[]} */ (Object.keys(summaryKeys)).map((k) => scoreEntry(summary[k])), | ||
`[Report](${reportUrl}) |`, | ||
].join(" | "); | ||
|
||
const createMarkdownTableHeader = () => [ | ||
["| URL", ...Object.values(summaryKeys), "Report |"].join(" | "), | ||
["|---", ...Array(Object.keys(summaryKeys).length).fill("---"), "---|"].join("|"), | ||
]; | ||
|
||
/** | ||
* @param {Object} param0 | ||
* @param {Record<string, string>} param0.links | ||
* @param {{url: string, summary: LighthouseSummary}[]} param0.results | ||
*/ | ||
const createLighthouseReport = ({ results, links }) => { | ||
const tableHeader = createMarkdownTableHeader(); | ||
const tableBody = results.map((result) => { | ||
const testUrl = /** @type {string} */ (Object.keys(links).find((key) => key === result.url)); | ||
const reportPublicUrl = /** @type {string} */ (links[testUrl]); | ||
|
||
return createMarkdownTableRow({ | ||
url: testUrl, | ||
summary: result.summary, | ||
reportUrl: reportPublicUrl, | ||
}); | ||
}); | ||
const comment = ["### ⚡️ Lighthouse report for the deploy preview of this PR", "", ...tableHeader, ...tableBody, ""]; | ||
return comment.join("\n"); | ||
}; | ||
|
||
export default createLighthouseReport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"path": "/*", | ||
"resourceSizes": [ | ||
{ | ||
"resourceType": "document", | ||
"budget": 18 | ||
}, | ||
{ | ||
"resourceType": "total", | ||
"budget": 3000 | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"ci": { | ||
"collect": { | ||
"startServerCommand": "yarn start", | ||
"startServerReadyPattern": "3000", | ||
"startServerReadyTimeout": 10000, | ||
|
||
"numberOfRuns": 1, | ||
|
||
"settings": { | ||
"skipAudits": ["robots-txt", "canonical", "tap-targets", "is-crawlable", "works-offline", "offline-start-url"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "lighthouse-scripts", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -x | ||
set -e | ||
|
||
# Copyright 2024 Jiaqi Liu. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Intentionally left blank |
Oops, something went wrong.