From 429ff3801a67fe4b62eba5d686763f702f274d91 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Fri, 2 Feb 2024 22:24:34 +0100 Subject: [PATCH] Run CI depending on changed files --- .github/file-filters.yml | 11 +++++++++++ .github/workflows/ci.yml | 29 ++++++++++++++++++++++++++++- .github/workflows/docker-image.yml | 3 ++- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/file-filters.yml diff --git a/.github/file-filters.yml b/.github/file-filters.yml new file mode 100644 index 0000000..685f5dd --- /dev/null +++ b/.github/file-filters.yml @@ -0,0 +1,11 @@ +--- +ci: &ci + - ".github/workflows/ci.yml" + - ".github/file-filters.yml" + +composer: &composer + - "composer.json" + - "composer.lock" + +php: &php + - "**/*.php" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d31be2..c86b790 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,28 @@ on: - pull_request jobs: + changed-files: + name: Detect changed files + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + ci: ${{ steps.changes.outputs.ci }} + composer: ${{ steps.changes.outputs.composer}} + php: ${{ steps.changes.outputs.php }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check for file changes + uses: dorny/paths-filter@v2 + id: changes + with: + filters: .github/file-filters.yml + composer-validation: + if: needs.changed-files.outputs.composer == 'true' + needs: + - changed-files runs-on: ubuntu-latest steps: - name: Checkout @@ -15,6 +36,9 @@ jobs: run: composer validate --strict tests: + if: needs.changed-files.outputs.php == 'true' + needs: + - changed-files runs-on: ubuntu-latest strategy: matrix: @@ -36,9 +60,12 @@ jobs: run: ./scripts/cibuild.sh docker-build: - if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' + if: | + github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && + needs.changed-files.outputs.composer == 'true' && needs.changed-files.outputs.php == 'true' needs: - composer-validation + - changed-files - tests runs-on: ubuntu-latest steps: diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 0e6c45a..3149f2a 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,7 +7,7 @@ on: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -18,6 +18,7 @@ jobs: uses: docker/metadata-action@v5 id: meta with: + images: ${{ github.repository }} tags: type=semver,pattern={{version}} type=semver,pattern={{major}}