diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c4ac590..c8063bb 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,11 +20,26 @@ concurrency: cancel-in-progress: true jobs: + extract-targets: + runs-on: ubuntu-latest + outputs: + targets: ${{ steps.get-targets.outputs.targets }} + steps: + - uses: actions/checkout@v4 + - name: Extract targets as JSON array + uses: dcarbone/install-jq-action@v2 + - name: Get targets from bake file + id: get-targets + run: | + TARGETS=$(docker buildx bake --file docker-bake.hcl --print | jq -c '[.target | keys[] | select(. != "default")]') + echo "targets=$TARGETS" >> "$GITHUB_OUTPUT" + build: + needs: extract-targets + runs-on: ubuntu-latest strategy: matrix: - target: [ "all", "20", "20-alpine", "19", "19-alpine", "18", "18-alpine", "17", "17-alpine", "16", "16-alpine", "15", "14", "13", "12", "11", "10", "9", "8", "7"] - runs-on: ubuntu-latest + target: ${{ fromJson(needs.extract-targets.outputs.targets) }} steps: - uses: actions/checkout@v4 @@ -34,17 +49,18 @@ jobs: - name: Check formatting run: make install-deps && make lint - - name: Login container registries - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin - - name: Check buildx bake run: docker buildx bake --file docker-bake.hcl --print - name: Build image for tag ${{ matrix.target }} run: docker buildx bake --file docker-bake.hcl ${{ matrix.target }} + - name: Login container registries + if: github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch' + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin + - name: Publish image for tag ${{ matrix.target }} if: github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch' run: docker buildx bake --file docker-bake.hcl ${{ matrix.target }} --push diff --git a/docker-bake.hcl b/docker-bake.hcl index cf782b0..023ae91 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -45,7 +45,7 @@ target "all" { "${GITHUB_REPO}:all" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -65,7 +65,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -85,7 +85,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -105,7 +105,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -124,7 +124,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -143,7 +143,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -162,7 +162,7 @@ target "clang-tools" { "${GITHUB_REPO}:${tgt}" ] platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + output = ["type=image"] } target "clang-tools" { @@ -180,6 +180,6 @@ target "clang-tools" { "${DOCKER_REPO}:${tgt}", "${GITHUB_REPO}:${tgt}" ] - platforms = ["linux/amd64", "linux/arm64"] - output = ["type=registry"] + platforms = ["linux/amd64"] + output = ["type=image"] }