-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from 7Sageer/test
fix: using kv instead of R2
- Loading branch information
Showing
4 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: Deploy Worker | ||
|
||
on: | ||
workflow_dispatch: | ||
repository_dispatch: | ||
|
@@ -17,27 +18,31 @@ jobs: | |
with: | ||
node-version: '21' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Install wrangler | ||
run: npm install -g wrangler | ||
- name: Install dependencies and wrangler | ||
run: | | ||
npm install | ||
npm install -g wrangler | ||
- name: Check and Create R2 Bucket | ||
- name: Check and Create KV Namespace | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | ||
run: | | ||
BUCKET_NAME="sublink-worker" | ||
if ! wrangler r2 bucket list | grep -q "$BUCKET_NAME"; then | ||
echo "Bucket $BUCKET_NAME does not exist. Creating..." | ||
wrangler r2 bucket create "$BUCKET_NAME" | ||
echo "Bucket $BUCKET_NAME created successfully." | ||
else | ||
echo "Bucket $BUCKET_NAME already exists. Skipping creation." | ||
KV_NAMESPACE="SUBLINK_KV" | ||
KV_ID=$(wrangler kv:namespace list | jq -r '.[] | select(.title == "sublink-worker-'$KV_NAMESPACE'") | .id') | ||
if [ -z "$KV_ID" ]; then | ||
KV_ID=$(wrangler kv:namespace create "$KV_NAMESPACE" | jq -r '.id') | ||
fi | ||
echo "KV_ID=$KV_ID" >> $GITHUB_ENV | ||
- name: Update wrangler.toml | ||
run: sed -i 's/id = "[^"]*"/id = "'$KV_ID'"/' wrangler.toml | ||
|
||
- name: Deploy to Cloudflare Workers | ||
uses: cloudflare/[email protected] | ||
with: | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
|
||
- name: Display deployment logs | ||
if: failure() | ||
run: wrangler tail --format pretty |
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
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
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