-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (132 loc) · 5.07 KB
/
site-build-deploy.yml
File metadata and controls
155 lines (132 loc) · 5.07 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
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: 20
- name: Sync docs
run: npm run sync:docs
env:
SHAKAPACKER_REPO_URL: https://github.com/shakacode/shakapacker.git
SHAKAPACKER_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:site
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: 20
- name: Sync docs
run: npm run sync:docs
env:
SHAKAPACKER_REPO_URL: https://github.com/shakacode/shakapacker.git
SHAKAPACKER_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:site
- 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:-shakapacker-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://shakapacker.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:-shakapacker-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,
});
}