mirror of
https://github.com/deployflare/test.git
synced 2026-01-13 16:18:02 +00:00
Fix: use CF API; drop kv:namespace --json
This commit is contained in:
33
.github/workflows/bind-everything.yml
vendored
33
.github/workflows/bind-everything.yml
vendored
@@ -18,28 +18,31 @@ jobs:
|
|||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm install -g wrangler
|
run: npm i -g wrangler
|
||||||
|
|
||||||
- name: Sync Cloudflare Bindings
|
- name: Sync Cloudflare Bindings
|
||||||
env:
|
env:
|
||||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
AID=$(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')
|
set -euo pipefail
|
||||||
if [ -z "$AID" ] || [ "$AID" == "null" ]; then echo "::error::Failed to retrieve Cloudflare Account ID." >&2; exit 1; fi
|
hdr=(-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type: application/json")
|
||||||
|
AID=$(curl -fsSL "${hdr[@]}" https://api.cloudflare.com/client/v4/accounts | jq -r '.result[0].id // empty')
|
||||||
|
[ -n "$AID" ] || { echo "::error::Failed to retrieve Cloudflare Account ID."; exit 1; }
|
||||||
|
touch wrangler.toml
|
||||||
|
|
||||||
wrangler d1 list --json --account-id $AID | jq -c '.[]' | while read -r db; do
|
curl -fsSL "${hdr[@]}" "https://api.cloudflare.com/client/v4/accounts/$AID/d1/database/list?per_page=1000" \
|
||||||
id=$(jq -r .uuid <<< "$db"); name=$(jq -r .name <<< "$db")
|
| jq -Mc '.result[]' \
|
||||||
if ! grep -q "$id" wrangler.toml; then
|
| while read -r db; do
|
||||||
printf '\n[[d1_databases]]\nbinding = "%s"\ndatabase_name = "%s"\ndatabase_id = "%s"\n' "$(echo "$name"|tr '[:lower:]-' '[:upper:]_')" "$name" "$id" >> wrangler.toml
|
id=$(jq -r .uuid<<<"$db"); name=$(jq -r .name<<<"$db"); bind=$(tr '[:lower:]-' '[:upper:]_'<<<"$name")
|
||||||
fi
|
grep -q "$id" wrangler.toml || printf '\n[[d1_databases]]\nbinding="%s"\ndatabase_name="%s"\ndatabase_id="%s"\n' "$bind" "$name" "$id" >> wrangler.toml
|
||||||
done
|
done
|
||||||
|
|
||||||
wrangler kv:namespace list --json --account-id $AID | jq -c '.[]' | while read -r kv; do
|
curl -fsSL "${hdr[@]}" "https://api.cloudflare.com/client/v4/accounts/$AID/storage/kv/namespaces?per_page=1000" \
|
||||||
id=$(jq -r .id <<< "$kv"); title=$(jq -r .title <<< "$kv")
|
| jq -Mc '.result[]' \
|
||||||
if ! grep -q "$id" wrangler.toml; then
|
| while read -r kv; do
|
||||||
printf '\n[[kv_namespaces]]\nbinding = "%s"\nid = "%s"\n' "$(echo "$title"|tr '[:lower:]-' '[:upper:]_')" "$id" >> wrangler.toml
|
id=$(jq -r .id<<<"$kv"); title=$(jq -r .title<<<"$kv"); bind=$(tr '[:lower:]-' '[:upper:]_'<<<"$title")
|
||||||
fi
|
grep -q "$id" wrangler.toml || printf '\n[[kv_namespaces]]\nbinding="%s"\nid="%s"\n' "$bind" "$id" >> wrangler.toml
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user