forked from Ray-D-Song/web-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (68 loc) · 2.2 KB
/
deploy.yml
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
name: Deploy
on:
push:
branches:
- main
repository_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build Service
run: pnpm build:service
- name: Install wrangler
run: npm install -g wrangler
- name: Verify Cloudflare API Token
run: |
echo "Verifying Cloudflare API Token..."
wrangler whoami
- name: Check and Create D1 Database
run: |
set -x
DB_LIST=$(wrangler d1 list --json)
DB_ID=$(echo $DB_LIST | jq -r '.[] | select(.name == "web-archive") | .uuid')
if [ -z "$DB_ID" ]; then
CREATE_OUTPUT=$(wrangler d1 create web-archive)
DB_ID=$(echo "$CREATE_OUTPUT" | sed -n 's/.*database_id = "\([^"]*\)".*/\1/p')
else
echo "Found existing web-archive database"
fi
echo "Database ID: $DB_ID"
echo "DB_ID=$DB_ID" >> $GITHUB_ENV
- name: update wrangler.toml
run: |
cd dist/service
sed -i 's/database_id = ".*"/database_id = "'$DB_ID'"/' wrangler.toml
- name: Apply D1 Migrations
run: |
cd dist/service
wrangler d1 migrations apply web-archive --remote
rm -rf ./src/sql
- name: Check and Create R2 Bucket
run: |
BUCKET_LIST=$(wrangler r2 bucket list)
if echo "$BUCKET_LIST" | grep -q "web-archive"; then
echo "Bucket already exists"
else
echo "Creating new bucket"
wrangler r2 bucket create web-archive
fi
- name: Create Pages project if not exists
run: |
if ! wrangler pages project list | grep -q "web-archive"; then
wrangler pages project create web-archive --production-branch=main
fi
- name: Deploy
run: cd dist/service && wrangler pages deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}