feat: update #377
Workflow file for this run
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
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
ci: | |
name: CI | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Check for 'skip ci' in commit messages | |
run: | | |
if [[ "${{ github.event.head_commit.message }}" == *"[skip-ci]"* && "${{ github.actor }}" == "tszhong0411" ]]; then | |
echo "CI checks are skipped as requested." | |
exit 0 | |
fi | |
- uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: latest | |
- name: Install dependencies | |
run: bun install | |
- name: Get preview environment variables | |
run: bunx vercel env pull .env --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Lint | |
run: bun run lint | |
- name: Typecheck | |
run: bun run type-check | |
- name: Unit test | |
run: bun run test:unit --coverage | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
- name: Build app | |
run: bun run build | |
- name: Install playwright | |
run: bun run playwright install --with-deps | |
- name: E2E test | |
run: bun run test:e2e | |
- name: Upload Playwright report | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: playwright-report | |
path: playwright-report/ | |
retention-days: 30 | |
- name: Add comment to PR | |
id: loading_comment_to_pr | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.issue.number }} | |
header: lighthouse | |
message: | | |
Running Lighthouse audit... | |
- name: Audit website with Lighthouse | |
id: lighthouse_audit | |
uses: treosh/lighthouse-ci-action@v10 | |
with: | |
uploadArtifacts: true | |
temporaryPublicStorage: true | |
configPath: '.github/lighthouse.yml' | |
- name: Format lighthouse score | |
id: format_lighthouse_score | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[2].summary // The 3th run is the latest | |
const links = ${{ steps.lighthouse_audit.outputs.links }} | |
const formatResult = (res) => Math.round((res * 100)) | |
Object.keys(result).forEach(key => result[key] = formatResult(result[key])) | |
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴' | |
const comment = [ | |
`⚡️ [Lighthouse report](${Object.values(links)[0]}):`, | |
'| Category | Score |', | |
'| --- | --- |', | |
`| ${score(result.performance)} Performance | ${result.performance} |`, | |
`| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`, | |
`| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`, | |
`| ${score(result.seo)} SEO | ${result.seo} |`, | |
' ' | |
].join('\n') | |
core.setOutput("comment", comment); | |
- name: Add comment to PR | |
id: comment_to_pr | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
number: ${{ github.event.issue.number }} | |
header: lighthouse | |
message: | | |
${{ steps.format_lighthouse_score.outputs.comment }} |