Skip to content

Commit 166602e

Browse files
committed
improvements
1 parent b50abbb commit 166602e

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

.github/workflows/wrangler.yaml

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,73 @@
1-
name: Deploy Worker
1+
name: Deploy
2+
23
on:
34
push:
45
branches:
5-
- main
6+
- "*"
7+
68
jobs:
79
deploy:
810
runs-on: ubuntu-latest
9-
timeout-minutes: 60
10-
needs: test
11+
name: Deploy
1112
steps:
1213
- uses: actions/checkout@v4
13-
- name: Build & Deploy Worker
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
1469
uses: cloudflare/wrangler-action@v3
1570
with:
1671
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
1772
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
73+
command: deploy ${{ steps.check-env.outputs.env_flag }}

0 commit comments

Comments
 (0)