-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(deploy): Deploy and analyze performance (#12)
Preview the deployment and Lighthouse will measure performance. Publish when a new version is released.
- Loading branch information
Showing
2 changed files
with
110 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,84 @@ | ||
name: π Preview | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "**.astro" | ||
- "**.ts" | ||
- bun.lockb | ||
- "!**.test.ts" | ||
|
||
jobs: | ||
deploy: | ||
name: π Deploy to the Preview | ||
runs-on: Ubuntu-Latest | ||
outputs: | ||
url: ${{ steps.deploy.outputs.deployment-url }} | ||
|
||
steps: | ||
- name: π Checkout Repository | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: π Setup Bun with Cache | ||
uses: ./.github/actions/setup-bun-with-cache | ||
|
||
- name: πΎ Create a Meta File | ||
run: echo ${{ vars.META_FILE }} >meta.json | ||
|
||
- name: π οΈ Build | ||
run: bun run build | ||
|
||
- name: β οΈ Deploy to the Preview | ||
id: deploy | ||
uses: cloudflare/wrangler-action@05f17c4a695b4d94b57b59997562c6a4624c64e4 # v3.12.1 | ||
with: | ||
command: pages deploy dist --project-name="$GITHUB_REPOSITORY" | ||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
|
||
lighthouse: | ||
name: π¦ Analyze Performance | ||
permissions: | ||
pull-requests: write | ||
needs: deploy | ||
runs-on: Ubuntu-Latest | ||
|
||
steps: | ||
- name: π¦ Analyze Performance with Lighthouse | ||
id: lighthouse | ||
uses: treosh/lighthouse-ci-action@2f8dda6cf4de7d73b29853c3f29e73a01e297bd8 # 12.1.0 | ||
with: | ||
urls: ${{ needs.deploy.outputs.url }} | ||
|
||
- name: π Arrange the Summary | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
id: summary | ||
with: | ||
result-encoding: string | ||
script: | | ||
const manifest = JSON.parse("${{ steps.lighthouse.outputs.manifest }}"); | ||
const gauge = Object.entries(manifest[0].summary).map(([label, percentage]) => { | ||
const score = Math.round(percentage * 100); | ||
const icon = score >= 90 ? "π’" : score >= 50 ? "π§" : "πΊ"; | ||
return { label, score: `${icon} ${score}` }; | ||
}); | ||
const labels = `| ${gauge.map(({ label }) => label).join(" | ")} |`; | ||
const scores = `| ${gauge.map(({ score }) => score).join(" | ")} |`; | ||
return `${labels}\n| ${gauge.map(() => ":-:").join(" | ")} |\n${scores}`; | ||
- name: π¬ Comment the Result | ||
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2 | ||
with: | ||
message: | | ||
## π¦ Lighthouse Result | ||
${{ steps.summary.outputs.result }} | ||
<details><summary>π Score Scale</summary> | ||
| Fail | Average | Pass | | ||
| :-----: | :------: | :-------: | | ||
| πΊ 0-49 | π§ 50-89 | π’ 90-100 | | ||
</details> | ||
message-id: lighthouse |
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