-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (164 loc) · 6.38 KB
/
site-build-deploy.yml
File metadata and controls
191 lines (164 loc) · 6.38 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Site Build and Deploy
on:
pull_request:
push:
branches: [main]
repository_dispatch:
types: [docs-updated]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24
- name: Sync docs
run: npm run sync:docs
env:
REACT_ON_RAILS_REPO_URL: https://github.com/shakacode/react_on_rails.git
REACT_ON_RAILS_REF: main
- name: Prepare docs
run: npm run prepare:docs
- name: Audit docs
id: audit_docs
continue-on-error: true
run: npm run audit:docs -- --output VALIDATION_REPORT_CI.md --fail-on error
- name: Upload docs audit report
if: always()
uses: actions/upload-artifact@v4
with:
name: docs-audit-report
path: VALIDATION_REPORT_CI.md
if-no-files-found: error
- name: Add docs audit summary
if: always()
run: |
{
echo "### Docs Audit"
echo ""
grep -E '^(Pages scanned|Pages with findings|Pages with errors|Pages with warnings|Pages with info|Errors|Warnings|Info):' VALIDATION_REPORT_CI.md || true
echo ""
echo "- Artifact: \`docs-audit-report\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Fail on blocking docs audit findings
if: steps.audit_docs.outcome == 'failure'
run: exit 1
- name: Install site dependencies
run: npm --prefix prototypes/docusaurus install
- name: Build site
run: npm run build
env:
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID }}
ALGOLIA_SEARCH_API_KEY: ${{ vars.ALGOLIA_SEARCH_API_KEY }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
deploy:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
needs: build
runs-on: ubuntu-latest
environment:
name: pages-deploy
url: ${{ steps.deploy.outputs.deployment_url }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24
- name: Sync docs
run: npm run sync:docs
env:
REACT_ON_RAILS_REPO_URL: https://github.com/shakacode/react_on_rails.git
REACT_ON_RAILS_REF: main
- name: Prepare docs
run: npm run prepare:docs
- name: Install site dependencies
run: npm --prefix prototypes/docusaurus install
- name: Build site
run: npm run build
env:
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID }}
ALGOLIA_SEARCH_API_KEY: ${{ vars.ALGOLIA_SEARCH_API_KEY }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
- name: Determine deploy branch
id: deploy_branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "branch=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
else
echo "branch=main" >> "$GITHUB_OUTPUT"
fi
- name: Deploy to Cloudflare Pages
id: deploy
run: |
set -euo pipefail
npx wrangler pages deploy prototypes/docusaurus/build \
--project-name "${CLOUDFLARE_PAGES_PROJECT:-reactonrails-com}" \
--branch "${{ steps.deploy_branch.outputs.branch }}" | tee /tmp/wrangler-pages-deploy.log
DEPLOYMENT_URL="$(grep -Eo 'https://[^ ]+\.pages\.dev' /tmp/wrangler-pages-deploy.log | head -n 1 || true)"
if [ -z "$DEPLOYMENT_URL" ]; then
if [ "${{ steps.deploy_branch.outputs.branch }}" = "main" ]; then
DEPLOYMENT_URL="https://reactonrails.com"
else
SAFE_BRANCH="$(echo "${{ steps.deploy_branch.outputs.branch }}" | sed 's/[^A-Za-z0-9-]/-/g')"
DEPLOYMENT_URL="https://${SAFE_BRANCH}.${CLOUDFLARE_PAGES_PROJECT:-reactonrails-com}.pages.dev"
fi
fi
echo "deployment_url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
{
echo "### Cloudflare Pages Deployment"
echo ""
echo "- Branch: \`${{ steps.deploy_branch.outputs.branch }}\`"
echo "- URL: $DEPLOYMENT_URL"
} >> "$GITHUB_STEP_SUMMARY"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }}
- name: Comment preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment_url }}
DEPLOY_BRANCH: ${{ steps.deploy_branch.outputs.branch }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const marker = "<!-- cf-pages-preview -->";
const body = `${marker}
Cloudflare preview deployed.
- Branch: \`${process.env.DEPLOY_BRANCH}\`
- URL: ${process.env.DEPLOYMENT_URL}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = comments.find((comment) =>
comment.user?.type === "Bot" && comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}