Update wrangler.toml #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Worker | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '21' | |
- name: Install dependencies | |
run: npm install | |
- name: Install wrangler | |
run: npm install -g wrangler | |
- name: Check and Create KV Namespace | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
run: | | |
KV_NAMESPACE="SUBLINK_KV" | |
echo "Checking for KV namespace: $KV_NAMESPACE" | |
LIST_OUTPUT=$(wrangler kv:namespace list) | |
echo "KV namespace list output: $LIST_OUTPUT" | |
KV_ID=$(echo "$LIST_OUTPUT" | jq -r '.[] | select(.title == "sublink-worker-'$KV_NAMESPACE'") | .id') | |
if [ -z "$KV_ID" ]; then | |
echo "KV namespace $KV_NAMESPACE does not exist. Creating..." | |
CREATE_OUTPUT=$(wrangler kv:namespace create "$KV_NAMESPACE") | |
echo "Create KV namespace output: $CREATE_OUTPUT" | |
KV_ID=$(echo "$CREATE_OUTPUT" | jq -r '.id') | |
if [ -z "$KV_ID" ]; then | |
echo "Failed to extract KV ID. Full output: $CREATE_OUTPUT" | |
exit 1 | |
fi | |
echo "KV namespace $KV_NAMESPACE created successfully with ID: $KV_ID" | |
else | |
echo "KV namespace $KV_NAMESPACE already exists with ID: $KV_ID" | |
fi | |
echo "Final KV_ID: $KV_ID" | |
echo "KV_ID=$KV_ID" >> $GITHUB_ENV | |
- name: Display wrangler.toml before update | |
run: cat wrangler.toml | |
- name: Update wrangler.toml | |
run: | | |
sed -i 's/id = "[^"]*"/id = "'$KV_ID'"/' wrangler.toml | |
echo "Updated wrangler.toml content:" | |
cat wrangler.toml | |
- name: Deploy to Cloudflare Workers | |
uses: cloudflare/[email protected] | |
with: | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
- name: Display deployment logs | |
if: failure() | |
run: | | |
echo "Deployment failed. Displaying recent logs:" | |
wrangler tail --format pretty |