forked from protoLabsAI/protoMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (84 loc) · 2.98 KB
/
deploy-docs.yml
File metadata and controls
94 lines (84 loc) · 2.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Deploy docs site to Cloudflare Pages via Wrangler CLI.
#
# Triggers on docs/** changes pushed to dev, staging, or main.
# PR pushes get a preview deployment with URL posted as a comment.
# Production branch = staging (matches current user-facing surface).
#
# Required secrets: CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID
name: Deploy Docs
on:
push:
branches: [dev, staging, main]
paths:
- 'docs/**'
- 'package.json'
- 'package-lock.json'
pull_request:
paths:
- 'docs/**'
workflow_dispatch:
permissions:
contents: read
deployments: write
pull-requests: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository == 'protoLabsAI/protoMaker'
timeout-minutes: 10
concurrency:
group: docs-deploy-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Build docs
run: |
npm install vitepress@1.6.4
npx vitepress build docs
- name: Deploy to Cloudflare Pages
id: deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
npx wrangler pages deploy docs/.vitepress/dist \
--project-name=protolabs-docs \
--branch="$BRANCH" \
--commit-hash="${GITHUB_SHA}" \
--commit-message="${{ github.event.head_commit.message || 'Deploy' }}"
- name: Comment PR preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const branch = context.payload.pull_request.head.ref;
const slug = branch.replace(/[^a-z0-9-]/gi, '-').substring(0, 28);
const url = `https://${slug}.protolabs-docs.pages.dev`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Docs preview: ${url}`
});
- name: Notify Discord
if: always() && github.event_name == 'push'
run: |
STATUS="${{ job.status }}"
COMMIT="${GITHUB_SHA:0:8}"
BRANCH="${GITHUB_REF_NAME}"
if [ "$STATUS" = "success" ]; then
MSG="Docs deployed (${BRANCH}): \`${COMMIT}\` — https://docs.protolabs.studio"
else
MSG="Docs deploy FAILED (${BRANCH}): \`${COMMIT}\` — ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
fi
if [ -n "${DISCORD_DEPLOY_WEBHOOK:-}" ]; then
curl -sf -H "Content-Type: application/json" \
-d "{\"content\": \"${MSG}\"}" \
"$DISCORD_DEPLOY_WEBHOOK" || true
fi
env:
DISCORD_DEPLOY_WEBHOOK: ${{ secrets.DISCORD_DEPLOY_WEBHOOK }}