-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (65 loc) · 2.41 KB
/
Copy pathpreview.yml
File metadata and controls
76 lines (65 loc) · 2.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
# Preview deploys on every pull request.
#
# This workflow uses the bundled local control plane (no external tokens): it
# starts `deploy server` on the runner, deploys the PR branch to a
# `preview-<branch>` alias, and comments the URL on the PR.
#
# To deploy previews to Netlify/Vercel instead, add secrets (NETLIFY_AUTH_TOKEN
# or VERCEL_TOKEN) and replace the deploy step with:
# deploy login --provider netlify --token ${{ secrets.NETLIFY_AUTH_TOKEN }}
# deploy preview --provider netlify --no-build
name: Preview deploy
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: npm ci
- name: Start local control plane
run: node cli.js server --port 8787 --storage .deploy-storage --token dev-token &
- name: Wait for server
run: |
for i in $(seq 1 15); do
if curl -sf --max-time 2 http://localhost:8787/ > /dev/null 2>&1; then
echo "Server ready"
exit 0
fi
sleep 1
done
echo "::error::Local control plane failed to start"
exit 1
- name: Login
run: DEPLOY_CONFIG_DIR=$RUNNER_TEMP/dc node cli.js login --server http://localhost:8787
- name: Preview deploy
id: deploy
run: |
cd examples/sample-site
DEPLOY_CONFIG_DIR=$RUNNER_TEMP/dc node ../../cli.js preview --json 2>&1 | tee deploy.log
sed -n '/^{/,$p' deploy.log > preview.json
echo "Preview deploy output:"
cat deploy.log
echo "Parsed JSON:"
cat preview.json
URL=$(node -p "JSON.parse(require('fs').readFileSync('preview.json','utf8')).url || ''")
echo "url=$URL" >> "$GITHUB_OUTPUT"
- name: Comment URL on the PR
if: steps.deploy.outputs.url != ''
uses: actions/github-script@v7
with:
script: |
const url = '${{ steps.deploy.outputs.url }}';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 **Preview deploy ready:** ${url}\n\n_Deployed by deploy-cli on PR #${context.issue.number}._`,
});