-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (59 loc) · 2.06 KB
/
preview.yml
File metadata and controls
63 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '20'
jobs:
deploy-preview:
if: github.actor != 'dependabot[bot]'
name: Deploy Preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build docs site
run: npm run docs:build
- name: Verify Netlify credentials
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: |
code=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
"https://api.netlify.com/api/v1/sites/$NETLIFY_SITE_ID")
echo "Netlify API status: $code"
test "$code" = "200"
- name: Deploy to Netlify (Preview)
id: deploy
uses: nwtgck/actions-netlify@v3.0
with:
publish-dir: './docs-dist'
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "PR #${{ github.event.pull_request.number }}"
alias: pr-${{ github.event.pull_request.number }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Comment PR
uses: actions/github-script@v8
with:
script: |
const url = '${{ steps.deploy.outputs.deploy-url }}';
const body = `## Preview Deployment\n\nYour preview is ready.\n\n**URL:** ${url}\n\n---\n<sub>Deployed from commit ${{ github.sha }}</sub>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});