Skip to content

Commit

Permalink
Run workflows conditioned to compare changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiswift committed Nov 11, 2024
1 parent 29ab01e commit e9b47fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
backend-tests:
needs:
- Compare-changes

if: ${{ needs.Compare-changes.outputs.backendDisable == 'false' }}
runs-on: ubuntu-latest
defaults:
run:
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/compare-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand All @@ -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')}}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/frontend-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e9b47fb

Please sign in to comment.