From c04b7383a6601c4cbf7c043ef53b093a258bc244 Mon Sep 17 00:00:00 2001 From: defangdevs Date: Fri, 23 Oct 2026 12:05:29 -0700 Subject: [PATCH 1/2] feat: add build input for deployment commands Adds a `build` boolean-style input that passes `--build` to the CLI for deployment commands (`up`, `compose up`, `deploy`) only. `down` and other commands are unaffected, and an explicit `--build` already present in `command` takes precedence. Default preserves current behavior. Fixes #61 Co-Authored-By: Claude Sonnet 5 --- .github/workflows/test.yaml | 1 + README.md | 16 ++++++++++++++++ action.yaml | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5fb111e..0f75265 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -47,4 +47,5 @@ jobs: cwd: "./test" compose-files: "" verbose: true + build: true command: "compose up --dry-run --project-name github-action-test" diff --git a/README.md b/README.md index e89b935..13ef7ae 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,22 @@ jobs: command: "compose up --project-name my-project" ``` +### Enabling Source Builds + +Set `build: true` to pass `--build` to the CLI for deployment commands (`up`, `compose up`, `deploy`). This has no effect on `down` or other commands, and is skipped if `command` already contains `--build`: + +```yaml +jobs: + test: + # [...] + steps: + # [...] + - name: Deploy + uses: DefangLabs/defang-github-action@v2 + with: + build: true +``` + ### Capturing Output Set `capture-output: true` to capture the command's stdout as an output (`outputs.stdout`). This is off by default because large deployments can exceed GitHub Actions' memory limits and cause the workflow to fail even though the deployment succeeded: diff --git a/action.yaml b/action.yaml index 4986854..91a267f 100644 --- a/action.yaml +++ b/action.yaml @@ -58,6 +58,10 @@ inputs: description: "Allow upgrading the CD image and Pulumi version to the latest available" required: false default: "false" + build: + description: "Pass '--build' to the CLI for deployment commands ('up', 'compose up', 'deploy'). Has no effect on 'down' or other commands, and is skipped if 'command' already contains '--build'. Defaults to current behavior (no '--build')." + required: false + default: "false" capture-output: description: "Capture the command's stdout as the 'stdout' output. Off by default: large deployments can exceed GitHub Actions memory limits." required: false @@ -208,6 +212,23 @@ runs: y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1) params+=("--allow-upgrade") ;; esac + # Only add --build for deployment commands (up/compose up/deploy), and + # only if the command doesn't already specify --build itself (an + # explicit flag in `command` takes precedence). Other commands (e.g. + # down) don't accept --build, so this must stay scoped to deployment. + case "${{ inputs['build'] }}" in + y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1) + case "$COMMAND" in + up|"up "*|"compose up"|"compose up "*|deploy|"deploy "*) + case "$COMMAND" in + *--build*) ;; + *) params+=("--build") ;; + esac + ;; + esac + ;; + esac + # Unset config vars to avoid Defang CLI warning user that config from shell env is ignored unset $CONFIG_VARS_INIT_RANDOM $CONFIG_ENV_VARS $CONFIG_ENV_VARS_INIT dont_complain_on_empty From fa6ca74eea27dd078aa2f67d204571d1ed09b21e Mon Sep 17 00:00:00 2001 From: defangdevs Date: Fri, 23 Oct 2026 12:44:14 -0700 Subject: [PATCH 2/2] fix: harden build-flag handling per CodeRabbit review - Pass the `build` input through a step env var (BUILD) instead of interpolating it directly into the script, matching the existing pattern used for COMMAND and other inputs. - Match `--build` in `command` only as a standalone token or as `--build=...`, not as a substring of another flag (e.g. `--buildx`). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Nc7PZ72AnXPGnDyDYDMPVk --- action.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/action.yaml b/action.yaml index 91a267f..98e5124 100644 --- a/action.yaml +++ b/action.yaml @@ -216,12 +216,12 @@ runs: # only if the command doesn't already specify --build itself (an # explicit flag in `command` takes precedence). Other commands (e.g. # down) don't accept --build, so this must stay scoped to deployment. - case "${{ inputs['build'] }}" in + case "$BUILD" in y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1) case "$COMMAND" in up|"up "*|"compose up"|"compose up "*|deploy|"deploy "*) - case "$COMMAND" in - *--build*) ;; + case " $COMMAND " in + *" --build "*|*" --build="*) ;; *) params+=("--build") ;; esac ;; @@ -243,6 +243,7 @@ runs: fi env: COMMAND: ${{ inputs['command'] }} + BUILD: ${{ inputs['build'] }} CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }} CONFIG_ENV_VARS_INIT: ${{ inputs['config-env-vars-init'] }} CONFIG_VARS_INIT_RANDOM: ${{ inputs['config-vars-init-random'] }}