From 9b84f4fdd8a2845f8adb71b968ee8662db5f7d8f Mon Sep 17 00:00:00 2001 From: qaz741wsd856 Date: Mon, 8 Dec 2025 06:26:17 +0000 Subject: [PATCH] fix: add r2 binding to github action and update readme --- .github/workflows/deploy-dev.yaml | 12 ++++++++++++ .github/workflows/push-cloudflare.yaml | 12 ++++++++++++ README.md | 15 ++++++--------- wrangler.toml | 15 ++++++++++++++- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml index 53bc037..d97b44e 100644 --- a/.github/workflows/deploy-dev.yaml +++ b/.github/workflows/deploy-dev.yaml @@ -56,6 +56,18 @@ jobs: - name: Replace D1_DATABASE_ID_DEV in wrangler.toml run: sed -i "s/\${D1_DATABASE_ID_DEV}/${{ secrets.D1_DATABASE_ID_DEV }}/g" wrangler.toml + - name: Enable R2 binding when R2_NAME_DEV is provided + if: secrets.R2_NAME_DEV != '' + env: + R2_NAME_DEV: ${{ secrets.R2_NAME_DEV }} + run: | + echo "🔧 Enabling dev R2 bucket binding for ${R2_NAME_DEV}" + cat <> wrangler.toml +[[env.dev.r2_buckets]] +binding = "ATTACHMENTS_BUCKET" +bucket_name = "${R2_NAME_DEV}" +EOF + - name: Apply D1 database migrations (dev) env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/.github/workflows/push-cloudflare.yaml b/.github/workflows/push-cloudflare.yaml index 7e422be..db1cd28 100644 --- a/.github/workflows/push-cloudflare.yaml +++ b/.github/workflows/push-cloudflare.yaml @@ -67,6 +67,18 @@ jobs: - name: Replace D1_DATABASE_ID in wrangler.toml run: sed -i "s/\${D1_DATABASE_ID}/${{ secrets.D1_DATABASE_ID }}/g" wrangler.toml + - name: Enable R2 binding when R2_NAME is provided + if: secrets.R2_NAME != '' + env: + R2_NAME: ${{ secrets.R2_NAME }} + run: | + echo "🔧 Enabling R2 bucket binding for ${R2_NAME}" + cat <> wrangler.toml +[[r2_buckets]] +binding = "ATTACHMENTS_BUCKET" +bucket_name = "${R2_NAME}" +EOF + - name: Apply D1 database migrations env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/README.md b/README.md index a2559ef..a1b3005 100644 --- a/README.md +++ b/README.md @@ -189,17 +189,14 @@ Add the following secrets to your GitHub repository (`Settings > Secrets and var If you want to use file attachments: - 1. **Create R2 buckets:** - - Log in to [Cloudflare Dashboard](https://dash.cloudflare.com/) + 1. **Create R2 buckets in Cloudflare Dashboard before running the action:** - Go to **Storage & databases** → **R2** → **Create bucket** - - Create buckets named `warden-attachments` + - Create a production bucket (e.g., `warden-attachments`) - 2. **Add R2 bindings:** - - Go to **Workers & Pages** → Select your `warden-worker` - - Click **Settings** → **Bindings** - - Click **Add binding** → **R2 bucket** - - Variable name: `ATTACHMENTS_BUCKET` - - R2 bucket: `warden-attachments` + 2. **Add the bucket names as GitHub Action secrets:** + - `R2_NAME` → production bucket name + + The workflows will auto-append the `ATTACHMENTS_BUCKET` binding into `wrangler.toml` when these secrets are present - no manual binding in the Cloudflare console is required. 4. **Manually trigger the `Build` Action** from the GitHub Actions tab in your repository diff --git a/wrangler.toml b/wrangler.toml index 866b118..7ac9da0 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -85,4 +85,17 @@ migrations_dir = "migrations" # Uncomment and configure this section to enable file attachments # [[env.dev.r2_buckets]] # binding = "ATTACHMENTS_BUCKET" -# bucket_name = "warden-attachments-dev" \ No newline at end of file +# bucket_name = "warden-attachments-dev" + +# logs +[env.dev.observability] +[env.dev.observability.logs] +enabled = true +head_sampling_rate = 1 +invocation_logs = true +persist = true + +[env.dev.observability.traces] +enabled = false +persist = true +head_sampling_rate = 1 \ No newline at end of file