Skip to content

Commit

Permalink
Update deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jyx04 authored Jun 9, 2024
1 parent 2a19fc9 commit 1a68994
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,37 @@ jobs:

- name: Install Wrangler
run: npm install -g wrangler

- name: Set Cloudflare Environment Variables
run: |
echo "CLOUDFLARE_ACCOUNT_ID=${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" >> $GITHUB_ENV
echo "CLOUDFLARE_API_TOKEN=${{ secrets.CLOUDFLARE_API_TOKEN }}" >> $GITHUB_ENV
- name: Validate Cloudflare Credentials
run: |
curl -X GET "https://api.cloudflare.com/client/v4/accounts" \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
-H "Content-Type: application/json"
- name: Create or Use Existing KV Namespace
id: create_or_find_kv
run: |
echo "Listing KV namespaces"
namespace_output=$(wrangler kv namespace list)
echo "Namespace list output: $namespace_output"
existing_namespace_id=$(echo "$namespace_output" | jq -r '.[] | select(.title == "oaifreehelper-oai_global_variables_preview" or .title == "worker-oai_global_variables_preview" or .title == "oai_global_variables") | .id' | head -n 1)
existing_namespace_id=$(echo "$namespace_output" | jq -r '.[] | select(.title == "worker-oai_global_variables" or .title == "oaifreehelper-oai_global_variables" or .title == "oaifreehelper-oai_global_variables_preview" or .title == "worker-oai_global_variables_preview" or .title == "oai_global_variables1") | .id' | head -n 1)
if [ -z "$existing_namespace_id" ]; then
echo "No existing KV namespace found, creating a new one."
namespace_creation_output=$(wrangler kv namespace create "oai_global_variables" --preview) || exit 1
namespace_creation_output=$(wrangler kv namespace create "oai_global_variables") || exit 1
echo "Namespace creation output: $namespace_creation_output"
namespace_id=$(echo "$namespace_creation_output" | grep -oP '(?<=preview_id = ")[^"]+')
namespace_id=$(echo "$namespace_creation_output" | grep -oP '(?<=id = ")[^"]+')
echo "CF_KV_NAMESPACE_ID=$namespace_id" >> $GITHUB_ENV
else
echo "Found existing KV namespace with ID: $existing_namespace_id"
echo "CF_KV_NAMESPACE_ID=$existing_namespace_id" >> $GITHUB_ENV
fi
- name: Generate wrangler.toml for main worker
run: |
echo "name = \"oaifreehelper\"" > wrangler.toml
Expand Down

0 comments on commit 1a68994

Please sign in to comment.