forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (132 loc) · 6.55 KB
/
Copy pathwebsite-deploy.yml
File metadata and controls
154 lines (132 loc) · 6.55 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
name: Deploy website
on:
push:
branches: [develop]
paths:
- 'packages/website/**'
- 'packages/muyajs/**'
- 'pnpm-lock.yaml'
- '.github/workflows/website-deploy.yml'
pull_request:
paths:
- 'packages/website/**'
- 'packages/muyajs/**'
- 'pnpm-lock.yaml'
- '.github/workflows/website-deploy.yml'
concurrency:
group: website-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22.21.1'
cache: 'pnpm'
# The root postinstall script rebuilds the desktop app's Electron-native
# modules (native-keymap, keytar, ced). They need these system libraries
# on Linux even though the website itself does not.
- name: Install desktop-rebuild system libs
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libx11-dev libxkbfile-dev libsecret-1-dev
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm --filter marktext-website run lint
- name: Type-check
run: pnpm --filter marktext-website run type-check
- name: Next build
run: pnpm --filter marktext-website run build
- name: OpenNext Cloudflare build
run: pnpm --filter marktext-website run cf:build
# ---- Production deploy: develop push ----
- name: Deploy (production)
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
run: pnpm --filter marktext-website exec wrangler deploy
# ---- Preview deploy: pull_request ----
#
# Uploads a Worker version tagged + aliased with the PR number. With
# Preview URLs enabled on the Worker (Cloudflare dashboard → Workers &
# Pages → marktext-website → Settings → Preview URLs), wrangler emits a
# URL like https://pr-NNNN-marktext-website.<subdomain>.workers.dev that
# stays stable for the life of the PR. If the URL is not present in the
# output, the Preview URLs feature is off and we report that via a
# notice on the PR rather than failing the build.
- name: Deploy preview
id: preview
if: github.event_name == 'pull_request'
working-directory: packages/website
run: |
set +e
ALIAS="pr-${{ github.event.pull_request.number }}"
pnpm exec wrangler versions upload \
--message "PR #${{ github.event.pull_request.number }} @ ${{ github.event.pull_request.head.sha }}" \
--tag "$ALIAS" \
--preview-alias "$ALIAS" \
> upload.log 2>&1
upload_status=$?
cat upload.log
if [ $upload_status -ne 0 ] && grep -q "Could not route to" upload.log; then
echo "result=not-bootstrapped" >> "$GITHUB_OUTPUT"
echo "::warning::Worker 'marktext-website' is not bootstrapped yet. Merge this PR to develop to create it; subsequent PRs will get real preview URLs."
exit 0
fi
if [ $upload_status -ne 0 ]; then
exit $upload_status
fi
# wrangler 4.x prints two preview lines: "Version Preview URL:"
# (versioned, per-deploy) and "Version Preview Alias URL:" (stable
# per --preview-alias, e.g. pr-NNNN). Prefer the alias because it's
# the URL we want to comment back on the PR.
PREVIEW_URL=$(grep -E '^Version Preview Alias URL:' upload.log | grep -Eo 'https://[^[:space:]]+' | head -n1 || true)
if [ -z "$PREVIEW_URL" ]; then
PREVIEW_URL=$(grep -E '^Version Preview URL:' upload.log | grep -Eo 'https://[^[:space:]]+' | head -n1 || true)
fi
VERSION_ID=$(grep -Eo 'Worker Version ID:[[:space:]]*[a-f0-9-]+' upload.log | awk '{print $NF}' || true)
if [ -n "$PREVIEW_URL" ]; then
echo "result=ok" >> "$GITHUB_OUTPUT"
echo "url=$PREVIEW_URL" >> "$GITHUB_OUTPUT"
echo "version=$VERSION_ID" >> "$GITHUB_OUTPUT"
elif [ -n "$VERSION_ID" ]; then
echo "result=preview-disabled" >> "$GITHUB_OUTPUT"
echo "version=$VERSION_ID" >> "$GITHUB_OUTPUT"
echo "::warning::Worker version $VERSION_ID uploaded but no preview URL was emitted. Enable Preview URLs on the marktext-website Worker in the Cloudflare dashboard to get clickable PR previews."
else
echo "Could not parse a preview URL or version ID from wrangler output" >&2
exit 1
fi
- name: Comment preview URL on PR
if: github.event_name == 'pull_request' && steps.preview.outputs.result == 'ok'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: website-preview
message: |
**Website preview ready:** ${{ steps.preview.outputs.url }}
Built from `${{ github.event.pull_request.head.sha }}` · Worker: `marktext-website` · Version: `${{ steps.preview.outputs.version }}` · Alias: `pr-${{ github.event.pull_request.number }}`
- name: Comment preview-disabled notice on PR
if: github.event_name == 'pull_request' && steps.preview.outputs.result == 'preview-disabled'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: website-preview
message: |
**Website preview not generated** — Preview URLs are disabled on the `marktext-website` Worker.
The version `${{ steps.preview.outputs.version }}` was uploaded successfully. To enable clickable PR previews, in the Cloudflare dashboard go to **Workers & Pages → marktext-website → Settings → Preview URLs** and turn the feature on. Subsequent PR runs will then post a real preview URL here.
- name: Comment bootstrap notice on PR
if: github.event_name == 'pull_request' && steps.preview.outputs.result == 'not-bootstrapped'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: website-preview
message: |
**Website preview not generated** — the `marktext-website` Worker does not exist on Cloudflare yet.
The build itself succeeded. Merge this PR to `develop` to create the Worker; subsequent PRs will get a real preview URL automatically.