Skip to content

Commit 84c9cd5

Browse files
committed
fix(ci): deploy correct bundled script file
1 parent c3f7b77 commit 84c9cd5

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

.github/workflows/deploy-worker.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ jobs:
6767
jq 'del(.d1_databases)' | \
6868
docker run -i ghcr.io/pelletier/go-toml:v2 jsontoml > wrangler.toml
6969
70-
- name: Extract wrangler.toml [main]
71-
id: wrangler-main
72-
working-directory: ${{ github.event.inputs.directory }}
73-
run: |
74-
wrangler_main=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -r '.main')
75-
echo "WRANGLER_MAIN=${wrangler_main}" >> "$GITHUB_OUTPUT"
76-
7770
- name: Check for [build] field in wrangler.toml
7871
id: check-custom-build
7972
working-directory: ${{ github.event.inputs.directory }}
@@ -86,7 +79,33 @@ jobs:
8679
with:
8780
wranglerVersion: ${{ env.wranglerVersion }}
8881
workingDirectory: ${{ github.event.inputs.directory }}
89-
command: deploy --dry-run ${{ steps.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('--outdir={0}', env.outDir) || '' }} --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }}
82+
command: deploy --dry-run ${{ env.OUT_DIR }} --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }}
83+
env:
84+
OUT_DIR: ${{ steps.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('--outdir={0}', env.outDir) || '' }}
85+
86+
- name: Determine worker entry script
87+
id: get-script
88+
working-directory: ${{ github.event.inputs.directory }}
89+
run: |
90+
wrangler_main=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -r '.main')
91+
echo "wrangler_main: $wrangler_main"
92+
93+
if [ "${{ steps.check-custom-build.outputs.CUSTOM_BUILD }}" == "false" ]; then
94+
trimmed_wrangler_main=$(echo ${wrangler_main} | sed 's|^\./||')
95+
echo "Custom build is false; looking for the bundled script in ${outDir} containing // ${trimmed_wrangler_main}"
96+
worker_script=$(grep -rl "// ${trimmed_wrangler_main}" "${{ env.outDir }}" | head -n 1)
97+
echo "Found worker_script: $worker_script"
98+
else
99+
echo "Custom build is true; using the wrangler.toml main entry..."
100+
worker_script="${wrangler_main}"
101+
fi
102+
103+
if [ -z "$worker_script" ]; then
104+
echo "Error: WORKER_SCRIPT is empty!"
105+
exit 1
106+
fi
107+
108+
echo "WORKER_SCRIPT=${worker_script}" >> "$GITHUB_OUTPUT"
90109
91110
- name: Deploy Worker
92111
uses: cloudflare/wrangler-action@v3
@@ -95,4 +114,4 @@ jobs:
95114
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
96115
wranglerVersion: ${{ env.wranglerVersion }}
97116
workingDirectory: ${{ github.event.inputs.directory }}
98-
command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('{0}/', env.outDir) || '' }}${{ steps.wrangler-main.outputs.WRANGLER_MAIN }}
117+
command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.get-script.outputs.WORKER_SCRIPT }}

0 commit comments

Comments
 (0)