-
Notifications
You must be signed in to change notification settings - Fork 423
143 lines (121 loc) · 4.25 KB
/
preview.yaml
File metadata and controls
143 lines (121 loc) · 4.25 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Deploy PR Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node
uses: actions/[email protected]
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Generate llms.txt
run: yarn generate:llms
- name: Build static site
env:
BASE: /docs-preview/pr-${{ github.event.number }}/
NEXT_PUBLIC_BASE_PATH: /docs-preview/pr-${{ github.event.number }}
run: yarn build
- name: Checkout docs-preview repository
uses: actions/[email protected]
with:
repository: celestiaorg/docs-preview
token: ${{ secrets.PR_PREVIEW_DEPLOY }}
path: docs-preview
- name: Deploy to docs-preview
run: |
# Create target directory
TARGET_DIR="docs-preview/pr-${{ github.event.number }}"
mkdir -p "$TARGET_DIR"
# Remove existing content in target directory to ensure clean deploy
rm -rrf "$TARGET_DIR"/*
# Copy built files
cp -r out/* "$TARGET_DIR"/
# Ensure .nojekyll exists in root
touch docs-preview/.nojekyll
# Commit and Push
cd docs-preview
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to deploy"
else
git commit -m "Deploy preview for PR #${{ github.event.number }} from ${{ github.sha }}"
git push
fi
- name: Post Preview Link
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://celestiaorg.github.io/docs-preview/pr-${prNumber}/`;
const body = `🚀 **Preview Deployment**\n\nYour preview is ready: [${previewUrl}](${previewUrl})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.body.includes('🚀 **Preview Deployment**') &&
comment.user.type === 'Bot'
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout docs-preview repository
uses: actions/[email protected]
with:
repository: celestiaorg/docs-preview
token: ${{ secrets.PR_PREVIEW_DEPLOY }}
path: docs-preview
- name: Remove preview
run: |
TARGET_DIR="docs-preview/pr-${{ github.event.number }}"
if [ -d "$TARGET_DIR" ]; then
rm -rf "$TARGET_DIR"
cd docs-preview
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Remove preview for PR #${{ github.event.number }}"
git push
else
echo "Preview directory $TARGET_DIR does not exist, skipping cleanup."
fi