-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (92 loc) · 3.83 KB
/
deploy-worker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
on:
workflow_dispatch:
inputs:
dispatchNamespace:
description: "Cloudflare Workers for Platforms dispatch namespace"
required: true
appId:
description: "Worker App ID"
required: true
repo:
description: "GitHub repository name"
required: true
commit:
description: "Git commit hash"
required: true
directory:
description: "Directory to deploy"
required: false
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
env:
wranglerVersion: "3.68.0"
outDir: "codius-dist"
steps:
- name: ${{github.event.inputs.appId}}
run: echo run identifier ${{ github.run_id }}
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.commit }}
- name: Check for pnpm-lock.yaml
id: check-pnpm-lock
run: |
directory=${{ inputs.directory }}
file_path="${directory:+${directory}/}pnpm-lock.yaml"
if [ -f "$file_path" ]; then
echo "PNPM lock file found"
echo "::set-output name=setup_pnpm::true"
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup PNPM
if: ${{ steps.check-pnpm-lock.outputs.setup_pnpm == 'true' }}
uses: pnpm/action-setup@v4
- name: Pull go-toml Docker image
run: docker pull ghcr.io/pelletier/go-toml:v2
- name: Sanitize wrangler.toml
working-directory: ${{ github.event.inputs.directory }}
run: |
mv wrangler.toml wrangler.toml.orig
docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml.orig | \
jq 'del(.d1_databases)' | \
docker run -i ghcr.io/pelletier/go-toml:v2 jsontoml > wrangler.toml
- name: Check for [build] field in wrangler.toml
id: check-custom-build
working-directory: ${{ github.event.inputs.directory }}
run: |
CUSTOM_BUILD=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -e '.build' > /dev/null && echo "true" || echo "false")
echo "CUSTOM_BUILD=${CUSTOM_BUILD}" >> "$GITHUB_OUTPUT"
- name: Bundle/Build Worker
uses: cloudflare/wrangler-action@v3
with:
wranglerVersion: ${{ env.wranglerVersion }}
workingDirectory: ${{ github.event.inputs.directory }}
command: deploy --dry-run ${{ env.OUT_DIR }} --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }}
env:
OUT_DIR: ${{ steps.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('--outdir={0}', env.outDir) || '' }}
- name: Determine worker entry script
id: get-script
working-directory: ${{ github.event.inputs.directory }}
run: |
wrangler_main=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -r '.main')
if [ "${{ steps.check-custom-build.outputs.CUSTOM_BUILD }}" == "false" ]; then
worker_script=$(grep -rl "// ${wrangler_main}" ${env.outDir} | head -n 1)
else
worker_script="${wrangler_main}"
fi
echo "WORKER_SCRIPT=${worker_script}" >> "$GITHUB_OUTPUT"
- name: Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: ${{ env.wranglerVersion }}
workingDirectory: ${{ github.event.inputs.directory }}
command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.get-script.outputs.WORKER_SCRIPT }}