diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 9dc6a8b9..8a57d453 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -4,9 +4,10 @@ on: workflow_dispatch: inputs: branch: - description: "Branch to build (e.g. my-feature-branch)" + description: "Branch to build (defaults to selected branch)" type: string - required: true + required: false + default: "" containers: description: "Comma-separated container names to build, or 'all' for all containers" type: string @@ -26,27 +27,33 @@ permissions: id-token: write jobs: - detect-changes: + setup: runs-on: ubuntu-latest - if: inputs.branch != 'main' outputs: + branch: ${{ steps.resolve.outputs.branch }} containers: ${{ steps.detect.outputs.containers }} downstream_containers: ${{ steps.detect.outputs.downstream_containers }} image_tag: ${{ steps.detect.outputs.image_tag }} steps: + - name: Resolve branch + id: resolve + run: | + BRANCH="${{ inputs.branch || github.ref_name }}" + echo "branch=$BRANCH" >> $GITHUB_OUTPUT + - name: Checkout repository uses: actions/checkout@v6 with: - ref: ${{ inputs.branch }} + ref: ${{ steps.resolve.outputs.branch }} - - name: Detect containers to build + - name: Resolve containers to build id: detect run: | # Compute image tag from branch name unless an explicit tag was provided if [[ -n "${{ inputs.tag }}" ]]; then IMAGE_TAG="${{ inputs.tag }}" else - IMAGE_TAG="dev-$(echo "${{ inputs.branch }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g')" + IMAGE_TAG="dev-$(echo "${{ steps.resolve.outputs.branch }}" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g')" fi echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT @@ -125,8 +132,8 @@ jobs: fi build: - needs: [ detect-changes ] - if: needs.detect-changes.outputs.containers != '[]' + needs: [ setup ] + if: needs.setup.outputs.containers != '[]' runs-on: ubuntu-24.04-arm env: PYTHON_VERSION: "3.13" @@ -134,13 +141,13 @@ jobs: strategy: fail-fast: false matrix: - container: ${{ fromJson(needs.detect-changes.outputs.containers) }} + container: ${{ fromJson(needs.setup.outputs.containers) }} steps: - name: Checkout repository uses: actions/checkout@v6 with: - ref: ${{ inputs.branch }} + ref: ${{ needs.setup.outputs.branch }} - name: Set up Python if: matrix.container == 'python-apps-base' @@ -173,8 +180,8 @@ jobs: uses: docker/metadata-action@v4 with: tags: | - type=raw,value=${{ needs.detect-changes.outputs.image_tag }} - type=raw,value=${{ needs.detect-changes.outputs.image_tag }}-${{ github.run_number }} + type=raw,value=${{ needs.setup.outputs.image_tag }} + type=raw,value=${{ needs.setup.outputs.image_tag }}-${{ github.run_number }} images: ghcr.io/${{ github.repository_owner }}/app-bricks/${{ matrix.container }} - name: Build and push Docker image @@ -192,8 +199,8 @@ jobs: REGISTRY=${{ env.DEV_REGISTRY_PATH }} build-downstream: - needs: [ detect-changes, build ] - if: needs.detect-changes.outputs.downstream_containers != '[]' + needs: [ setup, build ] + if: needs.setup.outputs.downstream_containers != '[]' runs-on: ubuntu-24.04-arm env: PYTHON_VERSION: "3.13" @@ -201,13 +208,13 @@ jobs: strategy: fail-fast: false matrix: - container: ${{ fromJson(needs.detect-changes.outputs.downstream_containers) }} + container: ${{ fromJson(needs.setup.outputs.downstream_containers) }} steps: - name: Checkout repository uses: actions/checkout@v6 with: - ref: ${{ inputs.branch }} + ref: ${{ needs.setup.outputs.branch }} - name: Set up Python if: matrix.container == 'python-apps-base' @@ -240,8 +247,8 @@ jobs: uses: docker/metadata-action@v4 with: tags: | - type=raw,value=${{ needs.detect-changes.outputs.image_tag }} - type=raw,value=${{ needs.detect-changes.outputs.image_tag }}-${{ github.run_number }} + type=raw,value=${{ needs.setup.outputs.image_tag }} + type=raw,value=${{ needs.setup.outputs.image_tag }}-${{ github.run_number }} images: ghcr.io/${{ github.repository_owner }}/app-bricks/${{ matrix.container }} - name: Build and push Docker image @@ -257,4 +264,4 @@ jobs: provenance: false build-args: | REGISTRY=${{ env.DEV_REGISTRY_PATH }} - BASE_IMAGE_VERSION=${{ needs.detect-changes.outputs.image_tag }} + BASE_IMAGE_VERSION=${{ needs.setup.outputs.image_tag }}