Update bind-everything.yml

This commit is contained in:
2025-09-28 08:59:05 -07:00
committed by GitHub
parent 5edb3513be
commit febbdd4207

View File

@@ -1,5 +1,6 @@
on: on:
push: push:
branches: ["**"]
workflow_dispatch: workflow_dispatch:
permissions: permissions:
@@ -20,23 +21,29 @@ jobs:
- name: Install Dependencies - name: Install Dependencies
run: npm install -g wrangler run: npm install -g wrangler
- name: Fetch Cloudflare Account ID & Sync Bindings - name: Sync Cloudflare Bindings
env: env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: | 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') 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 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 if ! grep -q "$id" wrangler.toml; then
name=$(jq -r .name <<< "$db") printf '\n[[d1_databases]]\nbinding = "%s"\ndatabase_name = "%s"\ndatabase_id = "%s"\n' "$(echo "$name"|tr '[:lower:]-' '[:upper:]_')" "$name" "$id" >> wrangler.toml
binding=$(echo "$name" | tr '[:lower:]-' '[:upper:]_') fi
printf '\n[[d1_databases]]\nbinding = "%s"\ndatabase_name = "%s"\ndatabase_id = "%s"\n' "$binding" "$name" "$id" >> wrangler.toml 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 fi
done done
- name: Commit and Push Changes - name: Commit and Push Changes
uses: stefanzweifel/git-auto-commit-action@v5 uses: stefanzweifel/git-auto-commit-action@v5
with: with:
commit_message: "chore: Sync D1 database bindings" commit_message: "chore: Sync Cloudflare D1 & KV bindings"
file_pattern: wrangler.toml file_pattern: wrangler.toml