Skip to content

Commit 5eb5da6

Browse files
committed
ci(cloudflare): 添加自动创建D1数据库和应用schema的步骤
重构Cloudflare部署流程,将D1数据库创建和schema应用从preCommands拆分为独立步骤 更新Rust依赖版本,包括worker和wasm-bindgen相关包
1 parent 576c573 commit 5eb5da6

2 files changed

Lines changed: 79 additions & 53 deletions

File tree

‎.github/workflows/push-cloudflare.yaml‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,44 @@ jobs:
4242
# - name: Replace D1_DATABASE_ID in wrangler.toml
4343
# run: sed -i "s/\${D1_DATABASE_ID}/${{ secrets.D1_DATABASE_ID }}/g" wrangler.toml
4444

45+
- name: Create D1 Database and Capture ID
46+
id: create_d1
47+
run: |
48+
db_output=$(npx wrangler d1 create --location apac warden-worker)
49+
if [ $? -ne 0 ]; then
50+
echo "::error::Failed to create D1 database."
51+
exit 1
52+
fi
53+
db_id=$(echo "$db_output" | grep -oE '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}')
54+
if [ -z "$db_id" ]; then
55+
echo "::error::Failed to extract D1 database ID."
56+
echo "Wrangler output: $db_output"
57+
exit 1
58+
fi
59+
echo "D1_DATABASE_ID=$db_id" >> $GITHUB_ENV
60+
echo "Successfully created D1 database with ID: $db_id"
61+
62+
- name: Replace D1_DATABASE_ID in wrangler.toml
63+
run: |
64+
if [ -z "${{ env.D1_DATABASE_ID }}" ]; then
65+
echo "::error::D1_DATABASE_ID is not set."
66+
exit 1
67+
fi
68+
sed -i "s/\${D1_DATABASE_ID}/${{ env.D1_DATABASE_ID }}/g" wrangler.toml
69+
echo "Successfully replaced D1_DATABASE_ID in wrangler.toml."
70+
71+
- name: Apply D1 Database Schema
72+
run: npx wrangler d1 execute warden-worker -y --remote --file sql/schema.sql
73+
74+
- name: Create JWT_SECRET
75+
run: openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_SECRET
76+
77+
- name: Create JWT_REFRESH_SECRET
78+
run: openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_REFRESH_SECRET
79+
4580
- uses: cloudflare/wrangler-action@v3
4681
id: cf
47-
# env:
48-
# D1_DATABASE_ID: ${{ secrets.D1_DATABASE_ID }}
4982
with:
50-
preCommands: |
51-
sed -i "s/\${D1_DATABASE_ID}/$(npx wrangler d1 create --location apac warden-worker | grep -oE '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}')/g" wrangler.toml
52-
npx wrangler d1 execute warden-worker -y --remote --file sql/schema.sql
53-
openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_SECRET
54-
openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_REFRESH_SECRET
5583
secrets: |
5684
ALLOWED_EMAILS
5785
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

‎Cargo.lock‎

Lines changed: 44 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)