Enhance GitHub workflows to conditionally run tests based on file changes. Added checks for 'circuits' in circuits.yml and 'contracts' or 'common' in contracts.yml to determine if tests should execute on dev branch. This avoids too wide changelist in trigger filter that is problematic

This commit is contained in:
Javier Cortejoso
2025-12-19 10:36:38 +01:00
parent f3d7f6bb6a
commit b68f52ed14
2 changed files with 52 additions and 7 deletions

View File

@@ -5,11 +5,34 @@ on:
- dev
- staging
- main
paths:
- "circuits/**"
jobs:
check_changes:
runs-on: ubuntu-slim
outputs:
should_run: ${{ steps.filter.outputs.should_run }}
steps:
- uses: actions/checkout@v6
- name: Check if should run
id: filter
run: |
if [[ "${{ github.base_ref }}" == "main" ]] || [[ "${{ github.base_ref }}" == "staging" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for ${{ github.base_ref }} - no path filter"
else
# For dev branch, check if circuits files changed
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^circuits/"; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for dev - circuits files changed"
else
echo "should_run=false" >> $GITHUB_OUTPUT
echo "Skipping for dev - no circuits files changed"
fi
fi
run_circuit_tests:
if: github.event.pull_request.draft == false
needs: check_changes
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
runs-on: ubuntu-latest
environment: development
permissions:

View File

@@ -5,17 +5,39 @@ on:
- dev
- staging
- main
paths:
- "contracts/**"
- "common/**"
concurrency:
group: contracts-ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check_changes:
runs-on: ubuntu-slim
outputs:
should_run: ${{ steps.filter.outputs.should_run }}
steps:
- uses: actions/checkout@v6
- name: Check if should run
id: filter
run: |
if [[ "${{ github.base_ref }}" == "main" ]] || [[ "${{ github.base_ref }}" == "staging" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for ${{ github.base_ref }} - no path filter"
else
# For dev branch, check if contracts or common files changed
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -qE "^(contracts|common)/"; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for dev - contracts or common files changed"
else
echo "should_run=false" >> $GITHUB_OUTPUT
echo "Skipping for dev - no contracts or common files changed"
fi
fi
test_contracts:
if: github.event.pull_request.draft == false
needs: check_changes
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
runs-on: ubuntu-latest
environment: development
steps: