|
8 | 8 | required: false |
9 | 9 | type: string |
10 | 10 | default: preview |
| 11 | + deploy-tool: |
| 12 | + description: 'Deployment CLI: wrangler (default, reads a wrangler config) or cf (Cloudflare cf CLI; deploys the cf Build Output produced by cf-wrangler build).' |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: wrangler |
11 | 16 | draft-protection: |
12 | 17 | description: 'Skip draft pull requests by default; set false to run deployments for drafts.' |
13 | 18 | required: false |
@@ -116,9 +121,17 @@ jobs: |
116 | 121 | env: |
117 | 122 | MODE: ${{ inputs.mode }} |
118 | 123 | WRANGLER_VERSION: ${{ inputs.wrangler-version }} |
| 124 | + DEPLOY_TOOL: ${{ inputs.deploy-tool }} |
| 125 | + BUILD_SCRIPT: ${{ inputs.build-script }} |
119 | 126 | run: | |
120 | 127 | set -euo pipefail |
121 | 128 | [[ "$MODE" == preview || "$MODE" == production ]] |
| 129 | + [[ "$DEPLOY_TOOL" == wrangler || "$DEPLOY_TOOL" == cf ]] |
| 130 | + [[ "$WRANGLER_VERSION" == local || "$WRANGLER_VERSION" == latest || "$WRANGLER_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]] |
| 131 | + # The cf path runs the project's cf-wrangler delegate to refresh the |
| 132 | + # Build Output; that delegate comes from the app's own dependencies, |
| 133 | + # which only the build step installs. |
| 134 | + [[ "$DEPLOY_TOOL" != cf || -n "$BUILD_SCRIPT" ]] |
122 | 135 | [[ "$WRANGLER_VERSION" == local || "$WRANGLER_VERSION" == latest || "$WRANGLER_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]] |
123 | 136 | - name: Set up Bun |
124 | 137 | if: inputs.build-script != '' || inputs['turbo-filter'] != '' |
@@ -262,8 +275,41 @@ jobs: |
262 | 275 | WRANGLER_VERSION: ${{ inputs.wrangler-version }} |
263 | 276 | MODE: ${{ inputs.mode }} |
264 | 277 | DEPLOYMENT_URL: ${{ inputs.deployment-url }} |
| 278 | + DEPLOY_TOOL: ${{ inputs.deploy-tool }} |
| 279 | + PREVIEW_NAME: ${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || github.ref_name }} |
265 | 280 | run: | |
266 | 281 | set -euo pipefail |
| 282 | + if [ "$DEPLOY_TOOL" = cf ]; then |
| 283 | + # cf path: refresh the Build Output with the project's own |
| 284 | + # cf-wrangler delegate, then deploy/preview it with the cf CLI. |
| 285 | + # Both CLIs come from the app's devDependencies installed by the |
| 286 | + # build step; the Node launcher avoids the Bun-runtime trap. |
| 287 | + cfbin=(npx --no-install) |
| 288 | + "${cfbin[@]}" cf-wrangler build |
| 289 | + if [ "$MODE" = production ]; then |
| 290 | + out="$("${cfbin[@]}" cf deploy --prebuilt)" |
| 291 | + printf '%s\n' "$out" |
| 292 | + version_id="$(printf '%s\n' "$out" | sed -n 's/.*Current Version ID: *//p' | head -1 | tr -d '[:space:]')" |
| 293 | + value="${DEPLOYMENT_URL:-$(printf '%s\n' "$out" | grep -o 'https://[^[:space:]]*' | head -1)}" |
| 294 | + else |
| 295 | + "${cfbin[@]}" cf previews deploy "$PREVIEW_NAME" > "$RUNNER_TEMP/cf-preview.json" |
| 296 | + value="$(jq -r '.preview_urls[0] // empty' "$RUNNER_TEMP/cf-preview.json")" |
| 297 | + version_id="$(jq -r '.deployment_id // empty' "$RUNNER_TEMP/cf-preview.json")" |
| 298 | + fi |
| 299 | + if [[ ! "$version_id" =~ ^[0-9a-f-]{36}$ ]]; then |
| 300 | + echo 'cf deploy did not report a Worker version ID' >&2 |
| 301 | + exit 1 |
| 302 | + fi |
| 303 | + if [[ -z "$value" || "$value" != https://* || "$value" == *'@'* || "$value" == *'#'* || "$value" == *' '* ]]; then |
| 304 | + echo 'cf deploy did not report a valid deployment URL' >&2 |
| 305 | + exit 1 |
| 306 | + fi |
| 307 | + { |
| 308 | + echo "url=$value" |
| 309 | + echo "version-id=$version_id" |
| 310 | + } >> "$GITHUB_OUTPUT" |
| 311 | + exit 0 |
| 312 | + fi |
267 | 313 | if [ "$WRANGLER_VERSION" = local ]; then |
268 | 314 | if [ -n "$BUILD_SCRIPT" ]; then |
269 | 315 | wrangler=(npx --no-install wrangler) |
|
0 commit comments