|
1 |
| -name: Deploy |
2 |
| - |
| 1 | +name: Deploy Worker |
3 | 2 | on:
|
4 | 3 | push:
|
5 | 4 | branches:
|
6 |
| - - "*" |
7 |
| - |
| 5 | + - main |
8 | 6 | jobs:
|
9 | 7 | deploy:
|
10 | 8 | runs-on: ubuntu-latest
|
11 |
| - name: Deploy |
| 9 | + timeout-minutes: 60 |
| 10 | + needs: test |
12 | 11 | steps:
|
13 | 12 | - 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 |
69 | 14 | uses: cloudflare/wrangler-action@v3
|
70 | 15 | with:
|
71 | 16 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
72 |
| - command: deploy ${{ steps.check-env.outputs.env_flag }} |
| 17 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
0 commit comments