From b326c55f706a231a2830de3e90c4ee8181e62e2e Mon Sep 17 00:00:00 2001 From: Brandon Wilson Date: Wed, 21 Aug 2024 10:54:58 -0500 Subject: [PATCH] fix(ci): deploy correct bundled script file --- .github/workflows/deploy-worker.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-worker.yml b/.github/workflows/deploy-worker.yml index 973f4e8..bcc1073 100644 --- a/.github/workflows/deploy-worker.yml +++ b/.github/workflows/deploy-worker.yml @@ -67,13 +67,6 @@ jobs: jq 'del(.d1_databases)' | \ docker run -i ghcr.io/pelletier/go-toml:v2 jsontoml > wrangler.toml - - name: Extract wrangler.toml [main] - id: wrangler-main - working-directory: ${{ github.event.inputs.directory }} - run: | - wrangler_main=$(docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < wrangler.toml | jq -r '.main') - echo "WRANGLER_MAIN=${wrangler_main}" >> "$GITHUB_OUTPUT" - - name: Check for [build] field in wrangler.toml id: check-custom-build working-directory: ${{ github.event.inputs.directory }} @@ -86,7 +79,23 @@ jobs: with: wranglerVersion: ${{ env.wranglerVersion }} workingDirectory: ${{ github.event.inputs.directory }} - 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 }} + 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 @@ -95,4 +104,4 @@ jobs: 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.check-custom-build.outputs.CUSTOM_BUILD == 'false' && format('{0}/', env.outDir) || '' }}${{ steps.wrangler-main.outputs.WRANGLER_MAIN }} + command: deploy --no-bundle --name=${{ github.event.inputs.appId }} --dispatch-namespace ${{ github.event.inputs.dispatchNamespace }} ${{ steps.get-script.outputs.WORKER_SCRIPT }}