Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
ci: replace path filters in tests and e2e with an in-job change check (#19786)
Lukasz Ostrowski58e2eb7cabb6
diff --git a/.github/actions/detect-python-changes/action.yml b/.github/actions/detect-python-changes/action.ymlnew file mode 100644index 0000000000..f149af9bd1--- /dev/null+++ b/.github/actions/detect-python-changes/action.yml@@ -0,0 +1,73 @@+name: Detect Python changes+description: >-+ Reports whether a pull request touches files that require the Python test+ suites to run.++ This replaces an `on.pull_request.paths` filter. A workflow skipped by path+ filtering never reports a check run, so it can never be made a required status+ check without deadlocking every pull request it does not match. A job that+ runs and exits early does report, so it can be required.++inputs:+ additional-file-patterns:+ description: >-+ Extra extended regular expressions, one per line, matched against the+ paths a pull request changes. Use this to make a workflow re-run when its+ own definition changes.+ required: false+ default: ""++outputs:+ changed:+ description: >-+ `true` when the pull request touches relevant files, or when the event is+ not a pull request; `false` otherwise.+ value: ${{ steps.detect.outputs.changed }}++runs:+ using: composite+ steps:+ - name: Detect Python changes+ id: detect+ shell: bash+ env:+ BASE_COMMIT_SHA: ${{ github.event.pull_request.base.sha }}+ EVENT_NAME: ${{ github.event_name }}+ # Newline separated list of extended regular expressions.+ INPUT_PATTERNS: ${{ inputs.additional-file-patterns }}+ run: |+ if [ "$EVENT_NAME" != "pull_request" ]; then+ echo "changed=true" >> "$GITHUB_OUTPUT"+ exit 0+ fi++ # Blank lines are dropped, as an empty pattern matches every path.+ mapfile -t additional_patterns < <(grep -v '^[[:space:]]*$' <<<"$INPUT_PATTERNS" || true)++ RELEVANT_PATHS=(+ '\.py$'+ '^Dockerfile$'+ '^saleor/'+ '^pyproject\.toml$'+ '^uv\.lock$'+ "${additional_patterns[@]}"+ )++ # `git config` is a workaround for https://github.com/actions/runner-images/issues/6775+ git config --global --add safe.directory "$GITHUB_WORKSPACE"++ # The checkout is shallow, so the base commit has to be fetched before diffing.+ git fetch --depth=1 origin "$BASE_COMMIT_SHA"++ # Assigned before matching so that a git failure fails the step, instead+ # of being read as "nothing relevant changed".+ changed_files=$(git diff --name-only "$BASE_COMMIT_SHA" HEAD)++ if grep -qEf <(printf '%s\n' "${RELEVANT_PATHS[@]}") <<<"$changed_files"; then+ echo "changed=true" >> "$GITHUB_OUTPUT"+ else+ MSG="No Python, Dockerfile or dependency changes."+ echo "$MSG"+ echo "$MSG" >> "$GITHUB_STEP_SUMMARY"+ echo "changed=false" >> "$GITHUB_OUTPUT"+ fidiff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.ymlindex 97841498bf..0121105243 100644--- a/.github/workflows/e2e.yml+++ b/.github/workflows/e2e.yml@@ -7,13 +7,6 @@ on:- cron: "00 2 * * 1,3,5"pull_request:types: [opened, synchronize, reopened]- paths:- - "**.py"- - Dockerfile- - "saleor/**"- - ".github/workflows/e2e.yml"- - pyproject.toml- - uv.lockpermissions: {}env:@@ -45,24 +38,35 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ - name: Check for changes requiring E2E tests+ id: changes+ uses: ./.github/actions/detect-python-changes+ with:+ # Re-run whenever this workflow itself changes.+ additional-file-patterns: '^\.github/workflows/e2e\.yml$'+- name: Install system dependencies+ if: steps.changes.outputs.changed == 'true'run: |apt-get install -y libpq-dev- - uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2+ - if: steps.changes.outputs.changed == 'true'+ uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2with:enable-cache: true- name: Install dependencies+ if: steps.changes.outputs.changed == 'true'run: |uv sync --locked- name: Run E2E tests+ if: steps.changes.outputs.changed == 'true'run: |uv run pytest -m "e2e" --junit-xml=e2e-test-results.xml- name: Surface failing tests- if: always()+ if: ${{ !cancelled() && steps.changes.outputs.changed == 'true' }}uses: pmeier/pytest-results-action@fdc7f18d9934e38aca411ca9557e6577bd25ca9c # v0.9.0with:path: e2e-test-results.xmldiff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yamlindex aaca8e426b..cf16727695 100644--- a/.github/workflows/tests.yaml+++ b/.github/workflows/tests.yaml@@ -3,13 +3,6 @@ name: Testson:pull_request:types: [opened, synchronize, reopened]- paths:- - "**.py"- - Dockerfile- - "saleor/**"- - .github/workflows/tests.yaml- - pyproject.toml- - uv.lockpush:branches:- main@@ -66,19 +59,30 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ - name: Check for changes requiring tests+ id: changes+ uses: ./.github/actions/detect-python-changes+ with:+ # Re-run whenever this workflow itself changes.+ additional-file-patterns: '^\.github/workflows/tests\.yaml$'+- name: Install system dependencies+ if: steps.changes.outputs.changed == 'true'run: |apt-get install -y libpq-dev- - uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2+ - if: steps.changes.outputs.changed == 'true'+ uses: astral-sh/setup-uv@11f9893b081a58869d3b5fccaea48c9e9e46f990 # v8.3.2with:enable-cache: true- name: Install dependencies+ if: steps.changes.outputs.changed == 'true'run: |uv sync --locked- name: Run unit tests+ if: steps.changes.outputs.changed == 'true'run: |uv run pytest \-m "not e2e" \@@ -88,6 +92,7 @@ jobs:-n logical- name: Upload Test Results+ if: ${{ !cancelled() && steps.changes.outputs.changed == 'true' }}uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1with:name: pytest-results@@ -95,18 +100,18 @@ jobs:# Throw an error if test results aren't reported. This could happen# when bumping dependencies for example.if-no-files-found: error- if: ${{ always() }}# Publish detected differences as comment- name: Compare DB Queries Results (PR)+ if: github.event_name == 'pull_request' && github.repository == 'saleor/saleor' && steps.changes.outputs.changed == 'true'uses: NyanKiyoshi/pytest-django-queries-ci-tools@45b5ac36ff19669a88fe56429b662b0661d8f46b # v1.1.1with:query_raw_dump_path: ${{ env.BENCH_PATH }}diff_endpoint: "https://dtab784j47g1o.cloudfront.net/default/saleor-db-queries-bot-diff"diff_results_base_url: "https://dtab784j47g1o.cloudfront.net"- if: github.event_name == 'pull_request' && github.repository == 'saleor/saleor'- name: Upload DB Queries Results+ if: steps.changes.outputs.changed == 'true'uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1with:name: pytest-django-db-queries-results