From f999490033908943e3ec99b7b7bb8923220674e6 Mon Sep 17 00:00:00 2001 From: bili22 Date: Fri, 21 Nov 2025 21:46:03 +0800 Subject: [PATCH] Auto create database and jwt secrets in action --- .github/workflows/push-cloudflare.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push-cloudflare.yaml b/.github/workflows/push-cloudflare.yaml index a0778b29..3b0e8adf 100644 --- a/.github/workflows/push-cloudflare.yaml +++ b/.github/workflows/push-cloudflare.yaml @@ -39,13 +39,22 @@ jobs: cargo install worker-build fi - - name: Replace D1_DATABASE_ID in wrangler.toml - run: sed -i "s/\${D1_DATABASE_ID}/${{ secrets.D1_DATABASE_ID }}/g" wrangler.toml + # - name: Replace D1_DATABASE_ID in wrangler.toml + # run: sed -i "s/\${D1_DATABASE_ID}/${{ secrets.D1_DATABASE_ID }}/g" wrangler.toml - uses: cloudflare/wrangler-action@v3 id: cf - env: - D1_DATABASE_ID: ${{ secrets.D1_DATABASE_ID }} + # env: + # D1_DATABASE_ID: ${{ secrets.D1_DATABASE_ID }} with: + preCommands: | + 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 + npx wrangler d1 execute warden-worker -y --remote --file sql/schema.sql + openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_SECRET + openssl rand -base64 48 | tr -d '\n' | npx wrangler secret put JWT_REFRESH_SECRET + secrets: | + ALLOWED_EMAILS apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + env: + ALLOWED_EMAILS: ${{ secrets.ALLOWED_EMAILS }}