diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index d166a42529..06ff7d35ec 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -1,6 +1,11 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 + on: + push: + paths: + - 'src/**' + - 'test/**' workflow_call: inputs: push: @@ -93,7 +98,23 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - + - name: Check for file changes + id: check_changes + if: ${{ !inputs.push }} + run: | + DOCKERFILE_DIR=$(dirname ${{ matrix.file_tag.file }}) + FILES_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} -- $DOCKERFILE_DIR) + if [ -z "$FILES_CHANGED" ]; then + echo "No changes in ${{ matrix.file_tag.context }}, skipping build." + echo "skip=true >> $GITHUB_OUTPUT" + else + echo "Changes detected in ${{ matrix.file_tag.context }}, proceeding with build." + echo "skip=false >> $GITHUB_OUTPUT" + fi + - name: Override skip for push + if: ${{ inputs.push }} + run: echo "skip=false >> $GITHUB_OUTPUT" + id: override_skip - name: Log in to the Container registry uses: docker/login-action@v2 with: @@ -101,27 +122,24 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} if: ${{ inputs.push }} - - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} if: ${{ inputs.push }} - - name: Set up QEMU uses: docker/setup-qemu-action@v2 with: image: tonistiigi/binfmt:master - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: config-inline: | [worker.oci] - max-parallelism = 2 - + max-parallelism = 2 - name: Matrix Build and push demo images + if: steps.check_changes.outputs.skip == 'false' || steps.override_skip.outputs.skip == 'false' uses: docker/build-push-action@v3.3.1 with: context: ${{ matrix.file_tag.context }}