ci: use npm script for notifications #18
This file contains hidden or 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: Check | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| # Fast checks - always run | |
| format: | |
| name: Formatting | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npx prettier --check . | |
| lint: | |
| name: Linting | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npm run lint | |
| typecheck: | |
| name: Types | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npm run typecheck | |
| test: | |
| name: Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npm run test:ci | |
| # Slow checks - only run on main or when PR is not draft | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: [format, lint, typecheck, test] | |
| if: | | |
| github.ref == 'refs/heads/main' || | |
| (github.event_name == 'pull_request' && github.event.pull_request.draft == false) | |
| env: | |
| NOTION_ACCESS_TOKEN: ${{ secrets.NOTION_ACCESS_TOKEN }} | |
| NOTION_DATA_SOURCE_ID_BOOKS: ${{ secrets.NOTION_DATA_SOURCE_ID_BOOKS }} | |
| NOTION_DATA_SOURCE_ID_ALBUMS: ${{ secrets.NOTION_DATA_SOURCE_ID_ALBUMS }} | |
| NOTION_DATA_SOURCE_ID_PODCASTS: ${{ secrets.NOTION_DATA_SOURCE_ID_PODCASTS }} | |
| NOTION_DATA_SOURCE_ID_WRITING: ${{ secrets.NOTION_DATA_SOURCE_ID_WRITING }} | |
| TMDB_READ_ACCESS_TOKEN: ${{ secrets.TMDB_READ_ACCESS_TOKEN }} | |
| TMDB_TV_LIST_ID: ${{ secrets.TMDB_TV_LIST_ID }} | |
| TMDB_MOVIE_LIST_ID: ${{ secrets.TMDB_MOVIE_LIST_ID }} | |
| CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }} | |
| CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }} | |
| CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }} | |
| PUSHOVER_API_TOKEN: ${{ secrets.PUSHOVER_API_TOKEN }} | |
| PUSHOVER_USER_KEY: ${{ secrets.PUSHOVER_USER_KEY }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - name: Build | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: npm run build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-output | |
| path: out/ | |
| metadata: | |
| name: Metadata | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: | | |
| github.ref == 'refs/heads/main' || | |
| (github.event_name == 'pull_request' && github.event.pull_request.draft == false) | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: build-output | |
| path: out/ | |
| - run: npm run test:metadata | |
| lighthouse: | |
| name: Lighthouse | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: | | |
| github.ref == 'refs/heads/main' || | |
| (github.event_name == 'pull_request' && github.event.pull_request.draft == false) | |
| env: | |
| LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/puppeteer | |
| key: lighthouse-chrome-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: build-output | |
| path: out/ | |
| - run: npm run lighthouse | |
| # Deploy - only on main, only if all checks pass | |
| deploy: | |
| name: Deploy | |
| runs-on: ubuntu-latest | |
| needs: [metadata, lighthouse] | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: build-output | |
| path: out/ | |
| - name: Deploy to Cloudflare Pages | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy out --project-name=michaeluloth --branch=main | |
| # Notify - always runs on main, reports success or which check failed | |
| notify: | |
| name: Notify | |
| runs-on: ubuntu-latest | |
| needs: [format, lint, typecheck, test, build, metadata, lighthouse, deploy] | |
| if: always() && github.ref == 'refs/heads/main' | |
| env: | |
| PUSHOVER_API_TOKEN: ${{ secrets.PUSHOVER_API_TOKEN }} | |
| PUSHOVER_USER_KEY: ${{ secrets.PUSHOVER_USER_KEY }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - run: npm ci | |
| - name: Send Pushover notification | |
| run: | | |
| npm run notify:ci -- \ | |
| --deploy=${{ needs.deploy.result }} \ | |
| --lighthouse=${{ needs.lighthouse.result }} \ | |
| --metadata=${{ needs.metadata.result }} \ | |
| --build=${{ needs.build.result }} \ | |
| --test=${{ needs.test.result }} \ | |
| --typecheck=${{ needs.typecheck.result }} \ | |
| --lint=${{ needs.lint.result }} \ | |
| --format=${{ needs.format.result }} \ | |
| --workflow-url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |