Merge pull request #8 from Flowm/claude/epic-wilson-991a95 #74
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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - run: npm run lint | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - run: npm test | |
| preview: | |
| needs: [lint, test] | |
| # PRs targeting main, excluding forks (which can't access the deploy secrets). | |
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - run: npm run build | |
| env: | |
| VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }} | |
| VITE_POSTHOG_API_HOST: ${{ secrets.VITE_POSTHOG_API_HOST }} | |
| # First 8 chars of the PR head commit form the preview alias, so the URL is | |
| # reproducible from a commit (and matches `npm run deploy:preview` locally). | |
| # Cloudflare requires the alias to start with a lowercase letter (a bare SHA | |
| # beginning with a hex digit is rejected — API code 10021), so prefix `preview-`. | |
| - id: meta | |
| env: | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: | | |
| echo "sha=${HEAD_SHA:0:8}" >> "$GITHUB_OUTPUT" | |
| echo "alias=preview-${HEAD_SHA:0:8}" >> "$GITHUB_OUTPUT" | |
| # Upload a new Worker version without promoting it to production. The | |
| # --preview-alias mints a stable URL (<sha>-meteocompare.<subdomain>.workers.dev). | |
| - id: preview | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| command: versions upload --preview-alias ${{ steps.meta.outputs.alias }} | |
| - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | |
| env: | |
| PREVIEW_URL: ${{ steps.preview.outputs.deployment-url }} | |
| ALIAS: ${{ steps.meta.outputs.alias }} | |
| SHA: ${{ steps.meta.outputs.sha }} | |
| with: | |
| script: | | |
| const marker = '<!-- meteocompare-preview -->'; | |
| // wrangler-action returns the per-version URL (https://<8-hex>-<worker>.<sub>.workers.dev); | |
| // swap the version prefix for our commit alias to get the URL deploy:preview reproduces. | |
| const versionUrl = process.env.PREVIEW_URL; | |
| const alias = process.env.ALIAS; | |
| const sha = process.env.SHA; | |
| const aliasUrl = versionUrl && alias | |
| ? versionUrl.replace(/^https:\/\/[0-9a-f]{8}-/, `https://${alias}-`) | |
| : ''; | |
| const body = [ | |
| marker, | |
| '### ⛅ Preview deployment', | |
| '', | |
| aliasUrl ? `This PR is live at ${aliasUrl}` : 'Preview upload finished but no URL was reported.', | |
| '', | |
| `_Commit \`${sha}\` — reproduce locally with \`npm run deploy:preview\`._`, | |
| ].join('\n'); | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find((c) => c.body?.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); | |
| } | |
| deploy: | |
| needs: [lint, test] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - run: npm ci | |
| - run: npm run build | |
| env: | |
| VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }} | |
| VITE_POSTHOG_API_HOST: ${{ secrets.VITE_POSTHOG_API_HOST }} | |
| - uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |