From febbdd4207ff0868d185afc8b465caa09235eed7 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sun, 28 Sep 2025 08:59:05 -0700 Subject: [PATCH] Update bind-everything.yml --- .github/workflows/bind-everything.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bind-everything.yml b/.github/workflows/bind-everything.yml index 63038a1..362e0fd 100644 --- a/.github/workflows/bind-everything.yml +++ b/.github/workflows/bind-everything.yml @@ -1,5 +1,6 @@ on: push: + branches: ["**"] workflow_dispatch: permissions: @@ -20,23 +21,29 @@ jobs: - name: Install Dependencies run: npm install -g wrangler - - name: Fetch Cloudflare Account ID & Sync Bindings + - name: Sync Cloudflare Bindings env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} run: | export CLOUDFLARE_ACCOUNT_ID=$(curl -sX GET "https://api.cloudflare.com/client/v4/accounts" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type:application/json" | jq -r '.result[0].id') + wrangler d1 list --json | jq -c '.[]' | while read -r db; do - id=$(jq -r .uuid <<< "$db") + id=$(jq -r .uuid <<< "$db"); name=$(jq -r .name <<< "$db") if ! grep -q "$id" wrangler.toml; then - name=$(jq -r .name <<< "$db") - binding=$(echo "$name" | tr '[:lower:]-' '[:upper:]_') - printf '\n[[d1_databases]]\nbinding = "%s"\ndatabase_name = "%s"\ndatabase_id = "%s"\n' "$binding" "$name" "$id" >> wrangler.toml + printf '\n[[d1_databases]]\nbinding = "%s"\ndatabase_name = "%s"\ndatabase_id = "%s"\n' "$(echo "$name"|tr '[:lower:]-' '[:upper:]_')" "$name" "$id" >> wrangler.toml + fi + done + + wrangler kv:namespace list --json | jq -c '.[]' | while read -r kv; do + id=$(jq -r .id <<< "$kv"); title=$(jq -r .title <<< "$kv") + if ! grep -q "$id" wrangler.toml; then + printf '\n[[kv_namespaces]]\nbinding = "%s"\nid = "%s"\n' "$(echo "$title"|tr '[:lower:]-' '[:upper:]_')" "$id" >> wrangler.toml fi done - name: Commit and Push Changes uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "chore: Sync D1 database bindings" + commit_message: "chore: Sync Cloudflare D1 & KV bindings" file_pattern: wrangler.toml