From c86ab88cb3fd071473f34aa3e8b5f80211c14398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Mon, 23 Mar 2026 15:25:41 +0100 Subject: [PATCH 1/4] Skip building Ruby images that already exist in GHCR Checks if the image tag exists before building. New versions added to the matrix get built, existing ones are skipped. Manual workflow dispatch with force=true rebuilds everything. --- .github/workflows/ruby.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index cb22c31..8c9b679 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -11,6 +11,11 @@ on: - ruby/Dockerfile - .github/workflows/ruby.yml workflow_dispatch: + inputs: + force: + description: Rebuild all images + type: boolean + default: false env: REGISTRY: ghcr.io @@ -37,14 +42,24 @@ jobs: - uses: docker/setup-buildx-action@v4 + - name: Check if image exists + id: check + run: | + if docker buildx imagetools inspect "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ruby-version }}" >/dev/null 2>&1; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + - uses: docker/login-action@v4 - if: github.event_name != 'pull_request' + if: (steps.check.outputs.exists != 'true' || inputs.force) && github.event_name != 'pull_request' with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/build-push-action@v7 + if: steps.check.outputs.exists != 'true' || inputs.force with: context: ruby platforms: linux/amd64,linux/arm64 From b51e9677183ce5a4d46ec60f5ea0ab846a73d9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Mon, 23 Mar 2026 15:33:13 +0100 Subject: [PATCH 2/4] Guard inputs.force for non-dispatch events, always build on PRs --- .github/workflows/ruby.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8c9b679..e6a77d3 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -52,14 +52,14 @@ jobs: fi - uses: docker/login-action@v4 - if: (steps.check.outputs.exists != 'true' || inputs.force) && github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && (steps.check.outputs.exists != 'true' || (github.event_name == 'workflow_dispatch' && inputs.force)) with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/build-push-action@v7 - if: steps.check.outputs.exists != 'true' || inputs.force + if: github.event_name == 'pull_request' || steps.check.outputs.exists != 'true' || (github.event_name == 'workflow_dispatch' && inputs.force) with: context: ruby platforms: linux/amd64,linux/arm64 From 9578f34366fde825f06809b5050f67b202a4d8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Mon, 23 Mar 2026 15:37:10 +0100 Subject: [PATCH 3/4] Only trigger PR builds on Dockerfile changes --- .github/workflows/ruby.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index e6a77d3..e83cb94 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,7 +9,6 @@ on: pull_request: paths: - ruby/Dockerfile - - .github/workflows/ruby.yml workflow_dispatch: inputs: force: From 5f6b5209388ccb7e137b82aacdcc251a8e018835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Mon, 23 Mar 2026 15:53:28 +0100 Subject: [PATCH 4/4] Detect Dockerfile changes to decide when to rebuild all versions On PRs and pushes, only build versions that don't exist in GHCR yet. If the Dockerfile itself changed, rebuild all versions to validate (without pushing on PRs). --- .github/workflows/ruby.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index e83cb94..0578133 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,6 +9,7 @@ on: pull_request: paths: - ruby/Dockerfile + - .github/workflows/ruby.yml workflow_dispatch: inputs: force: @@ -41,6 +42,20 @@ jobs: - uses: docker/setup-buildx-action@v4 + - name: Check if Dockerfile changed + id: dockerfile + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + BASE="${{ github.event.pull_request.base.sha }}" + else + BASE="${{ github.event.before }}" + fi + if git diff --name-only "$BASE" "${{ github.sha }}" -- ruby/Dockerfile | grep -q .; then + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + - name: Check if image exists id: check run: | @@ -51,14 +66,14 @@ jobs: fi - uses: docker/login-action@v4 - if: github.event_name != 'pull_request' && (steps.check.outputs.exists != 'true' || (github.event_name == 'workflow_dispatch' && inputs.force)) + if: github.event_name != 'pull_request' && (steps.check.outputs.exists != 'true' || steps.dockerfile.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force)) with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: docker/build-push-action@v7 - if: github.event_name == 'pull_request' || steps.check.outputs.exists != 'true' || (github.event_name == 'workflow_dispatch' && inputs.force) + if: steps.check.outputs.exists != 'true' || steps.dockerfile.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force) with: context: ruby platforms: linux/amd64,linux/arm64