Skip to content

Commit b50abbb

Browse files
committed
improvements
1 parent 671c94e commit b50abbb

File tree

2 files changed

+8
-62
lines changed

2 files changed

+8
-62
lines changed

.dev.vars.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
CLOUDFLARE_API_TOKEN=
1+
CLOUDFLARE_API_TOKEN=
2+
CLOUDFLARE_ACCOUNT_ID=

.github/workflows/wrangler.yaml

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,17 @@
1-
name: Deploy
2-
1+
name: Deploy Worker
32
on:
43
push:
54
branches:
6-
- "*"
7-
5+
- main
86
jobs:
97
deploy:
108
runs-on: ubuntu-latest
11-
name: Deploy
9+
timeout-minutes: 60
10+
needs: test
1211
steps:
1312
- uses: actions/checkout@v4
14-
15-
- name: Setup Node.js
16-
uses: actions/setup-node@v4
17-
with:
18-
node-version: "20"
19-
20-
- name: Install Dependencies
21-
run: npm install
22-
23-
- name: Check wrangler.toml for environments
24-
id: check-env
25-
run: |
26-
BRANCH_NAME=${GITHUB_REF#refs/heads/}
27-
if [ ! -f "wrangler.toml" ]; then
28-
echo "env_flag=" >> $GITHUB_OUTPUT
29-
exit 0
30-
fi
31-
if grep -q "\\[env\\.${BRANCH_NAME}\\]" wrangler.toml; then
32-
echo "env_flag=--env ${BRANCH_NAME}" >> $GITHUB_OUTPUT
33-
else
34-
echo "env_flag=" >> $GITHUB_OUTPUT
35-
fi
36-
37-
- name: Install wrangler
38-
run: npm install -g wrangler
39-
40-
- name: Sync All Secrets to Cloudflare
41-
env:
42-
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
43-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
44-
run: |
45-
# Create a temporary file with secret names and values
46-
echo "$SECRETS_CONTEXT" | jq -r 'to_entries | .[] | select(.key | startswith("github_") | not) | select(.key != "CLOUDFLARE_API_TOKEN") | [.key, .value] | @tsv' > secrets.txt
47-
48-
# Function to set a secret
49-
set_secret() {
50-
secret_name="$1"
51-
secret_value="$2"
52-
if [ -n "${{ steps.check-env.outputs.env_flag }}" ]; then
53-
echo "Setting $secret_name for environment ${{ steps.check-env.outputs.env_flag }}"
54-
echo "$secret_value" | wrangler secret put "$secret_name" ${{ steps.check-env.outputs.env_flag }}
55-
else
56-
echo "Setting $secret_name for default environment"
57-
echo "$secret_value" | wrangler secret put "$secret_name"
58-
fi
59-
}
60-
export -f set_secret
61-
62-
# Use parallel to set secrets (2 arguments per job)
63-
parallel --colsep '\t' set_secret {1} {2} :::: secrets.txt
64-
65-
# Clean up
66-
rm secrets.txt
67-
68-
- name: Deploy
13+
- name: Build & Deploy Worker
6914
uses: cloudflare/wrangler-action@v3
7015
with:
7116
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
72-
command: deploy ${{ steps.check-env.outputs.env_flag }}
17+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

0 commit comments

Comments
 (0)