@@ -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 }}
0 commit comments