From e9b47fbb7796e103d341ca3e0eaf59d900427e07 Mon Sep 17 00:00:00 2001 From: Christiano Gontijo Date: Tue, 12 Nov 2024 09:21:44 +1300 Subject: [PATCH] Run workflows conditioned to compare changes --- .github/workflows/backend-workflow.yml | 2 +- .github/workflows/compare-changes.yml | 19 ++++++------------- .github/workflows/frontend-workflow.yml | 3 +++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/backend-workflow.yml b/.github/workflows/backend-workflow.yml index f6de9ab..1a309fb 100644 --- a/.github/workflows/backend-workflow.yml +++ b/.github/workflows/backend-workflow.yml @@ -20,7 +20,7 @@ jobs: backend-tests: needs: - Compare-changes - + if: ${{ needs.Compare-changes.outputs.backendDisable == 'false' }} runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/compare-changes.yml b/.github/workflows/compare-changes.yml index b09f4ce..3515021 100644 --- a/.github/workflows/compare-changes.yml +++ b/.github/workflows/compare-changes.yml @@ -3,9 +3,9 @@ on: workflow_call: outputs: backendDisable: - value: ${{ jobs.compare-changes.outputs.backendDisable && jobs.compare-changes.outputs.workflowsDisable }} + value: ${{ jobs.compare-changes.outputs.backendDisable && jobs.compare-changes.outputs.workflowsNotChanged }} frontendDisable: - value: ${{ jobs.compare-changes.outputs.frontendDisable && jobs.compare-changes.outputs.workflowsDisable }} + value: ${{ jobs.compare-changes.outputs.frontendDisable && jobs.compare-changes.outputs.workflowsNotChanged }} playwrightDisable: value: ${{ jobs.compare-changes.outputs.playwrightDisable && jobs.compare-changes.outputs.workflowsDisable && jobs.compare-changes.outputs.backendDisable && jobs.compare-changes.outputs.frontendDisable }} @@ -19,7 +19,7 @@ jobs: backendDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'backend') }} frontendDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }} playwrightDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'playwright') }} - workflowsDisable: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }} + workflowsNotChanged: ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }} steps: - name: Checkout code uses: actions/checkout@v2 @@ -29,18 +29,11 @@ jobs: uses: ./.github/actions-change-labeler - run: echo "Changes detected ${{ steps.changed-files.outputs.changes }}" - echo "backend ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'backend') }}\n" echo "backend disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'backend') }}\n" - echo "backend disabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'backend') == false }}" - echo "backend enabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'backend') == true }}" - echo "frontend ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }}" echo "frontend disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }}" - echo "frontend disabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') == false }}" - echo "frontend enabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') == true }}" - echo "workflows ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }}" - echo "workflows changed ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }}" - echo "workflows disabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') == false }}" - echo "workflows enabled ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') == true }}" + echo "frontend disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'frontend') }}" + echo "playwright disabled ${{ !contains(fromJSON(steps.changed-files.outputs.changes), 'playwright') }}" + echo "workflows changed ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'workflows') }}" - name: Check for both frontend and backend changes if: ${{ contains(fromJSON(steps.changed-files.outputs.changes), 'backend') && contains(fromJSON(steps.changed-files.outputs.changes), 'frontend')}} diff --git a/.github/workflows/frontend-workflow.yml b/.github/workflows/frontend-workflow.yml index d7735c1..9845cb8 100644 --- a/.github/workflows/frontend-workflow.yml +++ b/.github/workflows/frontend-workflow.yml @@ -16,6 +16,9 @@ jobs: - run: printf "should run frontend CI ${{ needs.compare-changes.outputs.frontendDisable == 'false' }}\n" frontend-test: + needs: + - Compare-changes + if: ${{ needs.Compare-changes.outputs.backendDisable == 'false' }} runs-on: ubuntu-latest defaults: run: