-
Notifications
You must be signed in to change notification settings - Fork 25
127 lines (110 loc) · 3.53 KB
/
publish-docs.yml
File metadata and controls
127 lines (110 loc) · 3.53 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Publish Docs
on:
push:
branches: [master]
pull_request:
types: [opened, reopened, synchronize, closed]
workflow_dispatch:
inputs:
pr_number:
description: 'PR Number'
required: true
run_id:
description: 'Run ID of the build artifact'
required: true
permissions:
contents: write
pull-requests: write
actions: read
concurrency: ci-${{ github.ref }}
jobs:
# 1. Build Preview Artifact (Runs on PR)
build-preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Calculate BASE_URL
run: |
echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV
- name: Install and Build
run: npm ci && npm run build
env:
BASE_URL: ${{ env.BASE_URL }}
- name: Upload Preview Artifact
uses: actions/upload-artifact@v4
with:
name: preview-build
path: build/
- name: Comment Build Info
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-build-info
message: |
### ✅ Build Successful
To deploy this preview, a maintainer must run the **Deploy Preview** workflow.
**Run ID**: `${{ github.run_id }}`
**PR Number**: `${{ github.event.pull_request.number }}`
# 2. Deploy Preview (Manual Trigger)
deploy-preview:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: preview-build
run-id: ${{ inputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: site
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: site
target-folder: pr-preview/pr-${{ inputs.pr_number }}
- name: Comment Preview Link
uses: actions/github-script@v6
with:
script: |
const prNumber = ${{ inputs.pr_number }};
const owner = context.repo.owner;
const repo = context.repo.repo;
const url = `https://${owner}.github.io/${repo}/pr-preview/pr-${prNumber}/`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: `🚀 **Preview Deployed!**\n\n[View Preview](${url})`
});
# 3. Production Build & Deploy (Runs on Master Push)
build-production:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
with: { name: site, path: build/ }
deploy-production:
needs: build-production
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with: { name: site, path: site }
- uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: site
clean-exclude: pr-preview