Skip to content

Commit

Permalink
ci(deploy): Deploy and analyze performance (#12)
Browse files Browse the repository at this point in the history
Preview the deployment and Lighthouse will measure performance.
Publish when a new version is released.
  • Loading branch information
5ouma authored Nov 9, 2024
1 parent 9e214b2 commit e476218
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/preview.yml
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
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,29 @@ jobs:
config: .github/tagpr.ini
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy:
name: πŸš€ Deploy to the Production
needs: tagpr
if: ${{ needs.tagpr.outputs.tag != '' }}
runs-on: Ubuntu-Latest

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 Production
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 }}

0 comments on commit e476218

Please sign in to comment.