Skip building Ruby images that already exist #14
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Ruby | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - ruby/Dockerfile | |
| - .github/workflows/ruby.yml | |
| pull_request: | |
| paths: | |
| - ruby/Dockerfile | |
| - .github/workflows/ruby.yml | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: Rebuild all images | |
| type: boolean | |
| default: false | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }}/ruby | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| ruby-version: | |
| - "3.3.10" | |
| - "3.4.8" | |
| - "3.4.9" | |
| - "4.0.1" | |
| - "4.0.2" | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: docker/setup-qemu-action@v4 | |
| - 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: | | |
| 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' && (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: 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 | |
| build-args: RUBY_VERSION=${{ matrix.ruby-version }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ruby-version }} |