Skip to content

Commit b16f705

Browse files
Replace test workflow with build & deploy workflow for Netlify
Build and deploy via GH Actions using netlify-cli instead of consuming Netlify build minutes. Includes PR deploy previews with comment links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 00a89e7 commit b16f705

2 files changed

Lines changed: 49 additions & 41 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build & Deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 22
18+
cache: npm
19+
20+
- run: npm ci
21+
22+
- run: npm test
23+
24+
- name: Build & deploy to Netlify
25+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
26+
run: npx netlify-cli deploy --build --prod --site=${{ secrets.NETLIFY_SITE_ID }} --auth=${{ secrets.NETLIFY_AUTH_TOKEN }}
27+
28+
- name: Deploy preview (PRs)
29+
if: github.event_name == 'pull_request'
30+
id: preview
31+
run: |
32+
output=$(npx netlify-cli deploy --build --site=${{ secrets.NETLIFY_SITE_ID }} --auth=${{ secrets.NETLIFY_AUTH_TOKEN }})
33+
echo "$output"
34+
url=$(echo "$output" | grep -oP 'Website draft URL: \K\S+')
35+
echo "url=$url" >> "$GITHUB_OUTPUT"
36+
37+
- name: Comment preview URL
38+
if: github.event_name == 'pull_request' && steps.preview.outputs.url
39+
uses: actions/github-script@v7
40+
with:
41+
script: |
42+
github.rest.issues.createComment({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
issue_number: context.issue.number,
46+
body: `Deploy preview: ${process.env.URL}`
47+
})
48+
env:
49+
URL: ${{ steps.preview.outputs.url }}

.github/workflows/test.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)