From 94c48c90c65a7f1ad6ef184f7423d17123180196 Mon Sep 17 00:00:00 2001 From: Jelte van Boheemen Date: Wed, 12 Jun 2024 17:11:06 +0200 Subject: [PATCH] Succeed action when irrelevant tests are not run. Instead of not running an action at all when relevant files are unchanged, run the action but skip the actual tests. This allows required checks to succees. --- .github/workflows/backend-test.yml | 28 ++++++++++++++++++++++------ .github/workflows/frontend-test.yml | 28 ++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backend-test.yml b/.github/workflows/backend-test.yml index 2b87893d4..a737d0e0a 100644 --- a/.github/workflows/backend-test.yml +++ b/.github/workflows/backend-test.yml @@ -13,15 +13,31 @@ on: - 'hotfix/**' - 'release/**' - 'dependabot/**' - paths-ignore: - - 'frontend/**' - - '**.md' jobs: backend-test: name: Test Backend runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Run backend tests - run: sudo mkdir -p /ci-data && sudo docker-compose --env-file .env-ci run backend pytest + - name: Check if files have been changed in the backend + uses: actions/github-script@0.9.0 + id: backend-changed + with: + result-encoding: string + script: | + const result = await github.pulls.listFiles({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: context.payload.number, + per_page: 100 + }) + const backendChanged = result.data.filter(f => f.filename.startsWith("backend/") || f.filename.startsWith(".github") || f.filename.startsWith("docker-compose") || f.filename.startsWith(".env-ci")).length > 0 + console.log("backend changed: ", backendChanged) + return backendChanged + + - name: Checkout repository + if: ${{ steps.backend-changed.outputs.result == 'true' }} + uses: actions/checkout@v3 + + - name: Run backend tests + run: sudo mkdir -p /ci-data && sudo docker-compose --env-file .env-ci run backend pytest diff --git a/.github/workflows/frontend-test.yml b/.github/workflows/frontend-test.yml index fdb14f20e..218399ef4 100644 --- a/.github/workflows/frontend-test.yml +++ b/.github/workflows/frontend-test.yml @@ -13,15 +13,31 @@ on: - 'hotfix/**' - 'release/**' - 'dependabot/**' - paths-ignore: - - 'backend/**' - - '**.md' jobs: frontend-test: name: Test Frontend runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Run frontend tests - run: sudo docker-compose --env-file .env-ci run frontend yarn test + - name: Check if files have been changed in the frontend + uses: actions/github-script@0.9.0 + id: frontend-changed + with: + result-encoding: string + script: | + const result = await github.pulls.listFiles({ + owner: context.payload.repository.owner.login, + repo: context.payload.repository.name, + pull_number: context.payload.number, + per_page: 100 + }) + const frontendChanged = result.data.filter(f => f.filename.startsWith("frontend/") || f.filename.startsWith(".github") || f.filename.startsWith("docker-compose") || f.filename.startsWith(".env-ci")).length > 0 + console.log("Frontend changed: ", frontendChanged) + return frontendChanged + + - name: Checkout repository + if: ${{ steps.frontend-changed.outputs.result == 'true' }} + uses: actions/checkout@v3 + + - name: Run frontend tests + run: sudo docker-compose --env-file .env-ci run frontend yarn test