-
-
Notifications
You must be signed in to change notification settings - Fork 17
118 lines (104 loc) · 4.09 KB
/
website.yml
File metadata and controls
118 lines (104 loc) · 4.09 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
name: Deploy Website
on:
push:
branches: [main]
paths:
- 'website/**'
- '.github/workflows/website.yml'
pull_request:
types: [opened, synchronize, reopened, closed]
paths:
- 'website/**'
- '.github/workflows/website.yml'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: corepack enable
- run: npm ci
- run: npm run build
- name: Build website (production)
if: github.event_name != 'pull_request'
run: npm run build:website
- name: Build website (PR preview)
if: github.event_name == 'pull_request'
run: npm run build:website
env:
DOCUSAURUS_BASEURL: /preview/pr-${{ github.event.pull_request.number }}/
- name: Deploy to production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
working-directory: website
run: node scripts/deploy-bunny.mjs
env:
BUNNY_STORAGE_ZONE: ${{ secrets.BUNNY_WEBSITE_STORAGE_ZONE }}
BUNNY_STORAGE_PASSWORD: ${{ secrets.BUNNY_WEBSITE_STORAGE_PASSWORD }}
BUNNY_API_KEY: ${{ secrets.BUNNY_API_KEY }}
BUNNY_PULLZONE_URL: ${{ secrets.BUNNY_WEBSITE_PULLZONE_URL }}
- name: Deploy PR preview
if: github.event_name == 'pull_request'
working-directory: website
run: node scripts/deploy-bunny.mjs
env:
BUNNY_STORAGE_ZONE: ${{ secrets.BUNNY_WEBSITE_STORAGE_ZONE }}
BUNNY_STORAGE_PASSWORD: ${{ secrets.BUNNY_WEBSITE_STORAGE_PASSWORD }}
BUNNY_API_KEY: ${{ secrets.BUNNY_API_KEY }}
BUNNY_PULLZONE_URL: ${{ secrets.BUNNY_WEBSITE_PULLZONE_URL }}
DEPLOY_PATH: preview/pr-${{ github.event.pull_request.number }}
- name: Comment PR with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const previewUrl = `${{ secrets.BUNNY_WEBSITE_PULLZONE_URL }}/preview/pr-${{ github.event.pull_request.number }}/`;
const body = `### Preview deployed\n\n${previewUrl}`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('### Preview deployed'));
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,
});
}
cleanup:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Delete preview folder
run: |
curl -X DELETE \
"https://storage.bunnycdn.com/${{ secrets.BUNNY_WEBSITE_STORAGE_ZONE }}/preview/pr-${{ github.event.pull_request.number }}/" \
-H "AccessKey: ${{ secrets.BUNNY_WEBSITE_STORAGE_PASSWORD }}"
echo "Deleted preview/pr-${{ github.event.pull_request.number }}/"
- name: Purge preview cache
run: |
curl -X POST \
"https://api.bunny.net/purge?url=$(echo '${{ secrets.BUNNY_WEBSITE_PULLZONE_URL }}/preview/pr-${{ github.event.pull_request.number }}/*' | jq -sRr @uri)" \
-H "AccessKey: ${{ secrets.BUNNY_API_KEY }}"
echo "Cache purged"