Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ inputs:
description: 'Target build stage (optional, for multi-stage builds)'
required: false
default: ''
pre-build-targets:
description: 'Comma-separated list of build targets to run before final build (e.g., "lint,test" for validation stages)'
required: false
default: ''
outputs:
tag: # id of output
description: 'Tag used for the docker image'
Expand Down Expand Up @@ -137,6 +141,54 @@ runs:
touch /tmp/build-secrets/uvconfig.toml
fi
shell: bash
- name: Auto-detect build stages
id: detect-stages
run: |
DOCKERFILE="${{ inputs.docker-build-context }}/${{ inputs.dockerfile }}"
DETECTED_TARGETS=""

# Check for lint stage
if grep -q "^FROM .* AS lint" "$DOCKERFILE"; then
echo "Detected lint stage"
DETECTED_TARGETS="lint"
fi

# Check for test stage
if grep -q "^FROM .* AS test" "$DOCKERFILE"; then
echo "Detected test stage"
if [ -n "$DETECTED_TARGETS" ]; then
DETECTED_TARGETS="${DETECTED_TARGETS},test"
else
DETECTED_TARGETS="test"
fi
fi

# Use detected targets if pre-build-targets not explicitly set
if [ -z "${{ inputs.pre-build-targets }}" ]; then
echo "auto-targets=$DETECTED_TARGETS" >> $GITHUB_OUTPUT
echo "Using auto-detected targets: $DETECTED_TARGETS"
else
echo "auto-targets=${{ inputs.pre-build-targets }}" >> $GITHUB_OUTPUT
echo "Using explicitly configured targets: ${{ inputs.pre-build-targets }}"
fi
shell: bash
- name: Run pre-build targets with Depot
if: ${{ inputs.depot-token != '' && steps.detect-stages.outputs.auto-targets != '' }}
shell: bash
run: |
IFS=',' read -ra TARGETS <<< "${{ steps.detect-stages.outputs.auto-targets }}"
for target in "${TARGETS[@]}"; do
echo "Building target: $target"
depot build \
--project ${{ inputs.depot-project }} \
--token ${{ inputs.depot-token }} \
--platform ${{ inputs.platforms }} \
--target "$target" \
--secret id=pipconf,src=/tmp/build-secrets/pipconf \
--secret id=uvconfig,src=/tmp/build-secrets/uvconfig.toml \
--file ${{ inputs.dockerfile }} \
${{ inputs.docker-build-context }}
done
Comment on lines +175 to +191
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing error handling and whitespace trimming in target parsing.

The pre-build step has two issues:

  1. No error handling: If a depot build command fails for any target, the loop continues silently and the main build proceeds. This defeats the purpose of validation stages (lint, test, etc.). You likely want to fail the workflow if any pre-build target fails.

  2. Whitespace not trimmed: If users provide "lint, test" (with spaces), the parsed target becomes " test" with a leading space, which won't match the actual target name "test".

Apply this diff to add error handling and trim whitespace:

     - name: Run pre-build targets with Depot
       if: ${{ inputs.depot-token != '' && inputs.pre-build-targets != '' }}
       shell: bash
       run: |
         IFS=',' read -ra TARGETS <<< "${{ inputs.pre-build-targets }}"
         for target in "${TARGETS[@]}"; do
+          target="${target#"${target%%[![:space:]]*}"}"
+          target="${target%"${target##*[![:space:]]}"}"
           echo "Building target: $target"
           depot build \
             --project ${{ inputs.depot-project }} \
             --token ${{ inputs.depot-token }} \
             --platform ${{ inputs.platforms }} \
             --target "$target" \
             --secret id=pipconf,src=/tmp/build-secrets/pipconf \
             --secret id=uvconfig,src=/tmp/build-secrets/uvconfig.toml \
             --file ${{ inputs.dockerfile }} \
-            ${{ inputs.docker-build-context }}
+            ${{ inputs.docker-build-context }} || exit 1
         done

Alternatively, use a cleaner approach with xargs:

     - name: Run pre-build targets with Depot
       if: ${{ inputs.depot-token != '' && inputs.pre-build-targets != '' }}
       shell: bash
       run: |
         echo "${{ inputs.pre-build-targets }}" | tr ',' '\n' | while read -r target; do
           target="${target#"${target%%[![:space:]]*}"}"
           target="${target%"${target##*[![:space:]]}"}"
           [ -z "$target" ] && continue
           echo "Building target: $target"
           depot build \
             --project ${{ inputs.depot-project }} \
             --token ${{ inputs.depot-token }} \
             --platform ${{ inputs.platforms }} \
             --target "$target" \
             --secret id=pipconf,src=/tmp/build-secrets/pipconf \
             --secret id=uvconfig,src=/tmp/build-secrets/uvconfig.toml \
             --file ${{ inputs.dockerfile }} \
             ${{ inputs.docker-build-context }} || exit 1
         done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run pre-build targets with Depot
if: ${{ inputs.depot-token != '' && inputs.pre-build-targets != '' }}
shell: bash
run: |
IFS=',' read -ra TARGETS <<< "${{ inputs.pre-build-targets }}"
for target in "${TARGETS[@]}"; do
echo "Building target: $target"
depot build \
--project ${{ inputs.depot-project }} \
--token ${{ inputs.depot-token }} \
--platform ${{ inputs.platforms }} \
--target "$target" \
--secret id=pipconf,src=/tmp/build-secrets/pipconf \
--secret id=uvconfig,src=/tmp/build-secrets/uvconfig.toml \
--file ${{ inputs.dockerfile }} \
${{ inputs.docker-build-context }}
done
- name: Run pre-build targets with Depot
if: ${{ inputs.depot-token != '' && inputs.pre-build-targets != '' }}
shell: bash
run: |
IFS=',' read -ra TARGETS <<< "${{ inputs.pre-build-targets }}"
for target in "${TARGETS[@]}"; do
target="${target#"${target%%[![:space:]]*}"}"
target="${target%"${target##*[![:space:]]}"}"
echo "Building target: $target"
depot build \
--project ${{ inputs.depot-project }} \
--token ${{ inputs.depot-token }} \
--platform ${{ inputs.platforms }} \
--target "$target" \
--secret id=pipconf,src=/tmp/build-secrets/pipconf \
--secret id=uvconfig,src=/tmp/build-secrets/uvconfig.toml \
--file ${{ inputs.dockerfile }} \
${{ inputs.docker-build-context }} || exit 1
done
🤖 Prompt for AI Agents
In action.yml around lines 144 to 160, the pre-build loop neither trims
whitespace from comma-separated targets nor fails the workflow when a depot
build fails; update the shell block to (1) make the script fail fast by enabling
strict mode (e.g. set -euo pipefail) or by testing each depot build's exit
status and exiting with that status on failure, and (2) trim whitespace from
each parsed target before use (e.g. trim with xargs or shell parameter
expansion) and ensure inputs are properly quoted when passed to depot so targets
like "lint, test" become "lint" and "test" and any failed depot build aborts the
workflow.

- name: Build and push with Depot
id: docker_build_depot
if: ${{ inputs.depot-token != '' }}
Expand Down