Repository navigation
148 lines (127 loc) · 4.58 KB
/
Copy pathwebsite.yml
File metadata and controls
148 lines (127 loc) · 4.58 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
name: Website
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
issues: write
pull-requests: write
jobs:
deploy:
name: Deploy Website
runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: website-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.10
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/eclipsa/compiler/rust
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build optimizer native artifacts
run: bun run --filter @eclipsa/optimizer build:native:dev
- name: Build website
run: bun run --cwd docs build
- name: Resolve preview metadata
if: ${{ github.event_name == 'pull_request' }}
id: preview
shell: bash
run: |
echo "alias=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
- name: Deploy preview
if: ${{ github.event_name == 'pull_request' }}
id: deploy_preview
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
packageManager: bun
workingDirectory: docs
command: versions upload --preview-alias ${{ steps.preview.outputs.alias }}
- name: Comment preview URL
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
env:
PREVIEW_ALIAS: ${{ steps.preview.outputs.alias }}
WORKER_NAME: eclipsa
WRANGLER_OUTPUT: ${{ steps.deploy_preview.outputs.command-output }}
WRANGLER_STDERR: ${{ steps.deploy_preview.outputs.command-stderr }}
with:
script: |
const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const alias = process.env.PREVIEW_ALIAS
const workerName = process.env.WORKER_NAME
const wranglerText = [process.env.WRANGLER_OUTPUT, process.env.WRANGLER_STDERR]
.filter(Boolean)
.join('\n')
const aliasPattern = new RegExp(
`https://${escapeRegex(alias)}-${escapeRegex(workerName)}\\.[^\\s)]+\\.workers\\.dev`,
'i',
)
const previewUrl =
wranglerText.match(aliasPattern)?.[0] ??
wranglerText.match(/https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*\.workers\.dev/gi)?.[0]
if (!previewUrl) {
throw new Error(`Could not find preview URL in Wrangler output:\n${wranglerText}`)
}
const marker = '<!-- eclipsa-website-preview -->'
const body = [
marker,
`Website preview: ${previewUrl}`,
'',
`Commit: ${context.payload.pull_request.head.sha.slice(0, 7)}`,
].join('\n')
const { owner, repo } = context.repo
const issue_number = context.issue.number
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number,
per_page: 100,
})
const existing = comments.find(
(comment) =>
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker),
)
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
})
return
}
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
})
- name: Deploy production
if: ${{ github.event_name == 'push' }}
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
packageManager: bun
workingDirectory: docs
command: deploy