Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: conditionally skip python and frontend tests #12583

Merged
merged 6 commits into from
Feb 5, 2021

Conversation

villebro
Copy link
Member

@villebro villebro commented Jan 18, 2021

SUMMARY

This PR changes Python CI workflows to skip unit test execution for PRs that don't have changes that are relevant for those workflows. Here we're leveraging continue-on-error to check if files relevant to unit tests have changed, namely

Python changes:

  • tests/*
  • superset/*
  • requirements/*.txt
  • setup.py

Frontend changes:

  • superset_frontend/*

This is done to ensure that skipped workflows return a successful status for required checks despite not executing the expensive test steps. If any of the aforementioned file have changed, a failure exit code is triggered, which subsequent steps listen in on; if the check step returned a failure, the tests run, otherwise they are skipped.
To check changes, run check_no_file_changes.sh with the following arguments (the GITHUB_REPO and PR_NUMBER env variables need to be set):

  • Only check python changes: ./check_no_file_changes.sh python
  • Only check frontend changes: ./check_no_file_changes.sh frontend
  • Check python and frontend changes: ./check_no_file_changes.sh python frontend (order doesn't matter)

E2E tests have not been included in this PR, as some steps there depend in failure() which might need tweaking to run properly with this script.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Example of skipped frontend changes:
image
This shows the results for a PR with python changes:

Searching for changes in python files
Detected changes... Exiting with FAILURE code
bash-3.2$ PR_NUMBER=12960 GITHUB_REPO=apache/superset ./ci_check_no_file_changes.sh python
CHANGED FILES:
superset/migrations/versions/070c043f2fdb_add_granularity_to_charts_where_missing.py

Searching for changes in python files
Detected changes... Exiting with FAILURE code
bash-3.2$ PR_NUMBER=12960 GITHUB_REPO=apache/superset ./ci_check_no_file_changes.sh frontend
CHANGED FILES:
superset/migrations/versions/070c043f2fdb_add_granularity_to_charts_where_missing.py

Searching for changes in frontend files
No changes detected... Exiting with SUCCESS code
bash-3.2$ PR_NUMBER=12960 GITHUB_REPO=apache/superset ./ci_check_no_file_changes.sh python frontend
CHANGED FILES:
superset/migrations/versions/070c043f2fdb_add_granularity_to_charts_where_missing.py

When checking for both python and frontend changes on a PR with frontend changes, the following happens:

bash-3.2$ PR_NUMBER=12920 GITHUB_REPO=apache/superset ./ci_check_no_file_changes.sh python frontend
CHANGED FILES:
superset-frontend/spec/javascripts/sqllab/TableElement_spec.jsx
superset-frontend/src/SqlLab/components/SqlEditorLeftBar.jsx
superset-frontend/src/SqlLab/components/TableElement.jsx
superset-frontend/src/SqlLab/main.less
superset-frontend/src/common/components/Collapse/Collapse.stories.tsx
superset-frontend/src/common/components/Collapse/index.tsx
superset-frontend/src/common/components/common.stories.tsx
superset-frontend/src/common/components/index.tsx
superset-frontend/src/dashboard/components/FiltersBadge/DetailsPanel.tsx
superset-frontend/src/explore/components/ControlPanelsContainer.jsx
superset-frontend/src/explore/components/DataTablesPane.tsx
superset-frontend/src/explore/components/DatasourcePanel.tsx
superset-frontend/src/explore/components/controls/FixedOrMetricControl.jsx
superset-frontend/src/explore/main.less
superset-frontend/src/views/CRUD/welcome/Welcome.tsx

Searching for changes in python files
Searching for changes in frontend files
Detected changes... Exiting with FAILURE code

TEST PLAN

Tested to correctly detect frontend and python changes locally, as well as skip tests when they are not needed to run

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-io
Copy link

codecov-io commented Jan 18, 2021

Codecov Report

Merging #12583 (5e39697) into master (0f243c6) will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12583      +/-   ##
==========================================
- Coverage   66.75%   66.67%   -0.08%     
==========================================
  Files        1015     1015              
  Lines       49634    49634              
  Branches     4839     4970     +131     
==========================================
- Hits        33131    33094      -37     
- Misses      16380    16417      +37     
  Partials      123      123              
Flag Coverage Δ
cypress 50.98% <ø> (+<0.01%) ⬆️
javascript 60.74% <ø> (ø)
python 63.83% <ø> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/db_engine_specs/presto.py 73.37% <0.00%> (-8.01%) ⬇️
superset/models/core.py 88.58% <0.00%> (-0.28%) ⬇️
...rontend/src/explore/components/DatasourcePanel.tsx 90.69% <0.00%> (ø)
...set-frontend/src/dashboard/util/getDropPosition.js 93.65% <0.00%> (+1.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f243c6...5262a77. Read the comment docs.

@villebro villebro force-pushed the villebro/ci-skip-python branch 2 times, most recently from 8d3f9bf to 5e39697 Compare January 18, 2021 17:55
@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 18, 2021
@villebro villebro force-pushed the villebro/ci-skip-python branch from 5e39697 to 5262a77 Compare January 18, 2021 18:49
Copy link
Member

@amitmiran137 amitmiran137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this will reduce CI waiting time dramatically.
Thank you for that!

@villebro villebro changed the title [WIP] ci: conditionally skip python tests ci: conditionally skip python tests Jan 19, 2021
@villebro villebro requested review from ktmud, dpgaspar and nytai January 19, 2021 08:37
@junlincc
Copy link
Member

junlincc commented Jan 19, 2021

@ktmud could you help review and stamp it?

@ktmud
Copy link
Member

ktmud commented Jan 19, 2021

You probably wouldn't want to ignore tests/*.py for E2E because it also contains some scripts to fill examples data.

I'm also wondering what's the difference between this solution and using Github Action's built-in on.<push|pull_request>.paths config?

We can probably get away with something like this:

name: E2E

on:
  push:
    branches-ignore:
      - "dependabot/**/docs/**"
    paths-ignore:
      - "docs/**"
      - *.md
      - docker/**
      - helm/**
  pull_request:
    paths-ignore:
      - "docs/**"
      - *.md
      - docker/**
      - helm/**
# Python MySQL unit tests
name: Python MySQL

on:
  push:
    branches-ignore:
      - "dependabot/npm_and_yarn/**"
    paths:
      - superset/**
      - tests/**
      - requirements/**
      - scripts/**
      - setup.py
  pull_request:
    paths:
      - superset/**
      - tests/**
      - requirements/**
      - scripts/**
      - setup.py

@nytai
Copy link
Member

nytai commented Jan 19, 2021

@ktmud using the github syntax causes the action to forever remain in a "pending" state which block PR merges for actions that are marked required. This approach causes the action to report back ✅ even if no tests were actually run.

Copy link
Member

@nytai nytai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The python checks only took ~20s!

@ktmud
Copy link
Member

ktmud commented Jan 19, 2021

@ktmud using the github syntax causes the action to forever remain in a "pending" state which block PR merges for actions that are marked required. This approach causes the action to report back ✅ even if no tests were actually run.

Right. Totally forgot about this... We've talked about this before, lol.

@ktmud
Copy link
Member

ktmud commented Jan 19, 2021

Anyway, I still don't think you can skip test/*.py for E2E tests.

continue-on-error: true
run: |
./scripts/ci_check_python_changes.sh
./scripts/ci_check_python_test_changes.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe parameterize this script to avoid creating two largely identical files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I still don't think you can skip test/*.py for E2E tests.

are we? I'm not seeing any changes to superset-e2e.yml

I wanted to keep the scope of this PR as small as possible, hence didn't het add the E2E changes. Once this is merged I'll add similar logic to frontend and E2E tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another benefit of parameterizing this is to allow more advanced skipping in the future---for example, we may split/skip E2E tests based on product areas.

@nytai
Copy link
Member

nytai commented Jan 19, 2021

Anyway, I still don't think you can skip test/*.py for E2E tests.

are we? I'm not seeing any changes to superset-e2e.yml

@ktmud
Copy link
Member

ktmud commented Jan 19, 2021

Anyway, I still don't think you can skip test/*.py for E2E tests.

are we? I'm not seeing any changes to superset-e2e.yml

It was stated in the PR description as the reason for having two .sh files. Then maybe we don't need two files.

@ktmud
Copy link
Member

ktmud commented Jan 19, 2021

BTW, we should probably also skip superset-frontend.yml for pure Python changes.

@nytai
Copy link
Member

nytai commented Jan 19, 2021

Ah, I didn't read the PR description fully. I agree, since e2e is supposed to be out final catch-all check it should probably always run. Also there is code in tests/*.py that can affect e2e test runs

@villebro
Copy link
Member Author

Thanks for the reviews and good comments @nytai and @ktmud , I'll update the PR accordingly

@villebro
Copy link
Member Author

BTW, we should probably also skip superset-frontend.yml for pure Python changes.

Yes, I'll do this in a follow-up PR.

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a non blocking comment, agree that E2E should run also on python changes

EOF

if [[ "${FILES}" =~ (superset\/.+\.py|setup\.py|requirements\/.+\.txt) ]]; then
echo "Detected changes in python files... Exiting with FAILURE code"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems logically odd that a script named check_python_changes returns "False" if there were changes, assuming it's easier to detect if: steps.check.outcome == 'failure' maybe rename the script to a negative

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point also. I'll rename the files to be in line with what's being asserted.

@villebro villebro force-pushed the villebro/ci-skip-python branch from 5262a77 to 6e488cc Compare February 5, 2021 09:28
@pull-request-size pull-request-size bot added size/M and removed size/L labels Feb 5, 2021
@villebro villebro changed the title ci: conditionally skip python tests ci: conditionally skip python and frontend tests Feb 5, 2021
@ktmud
Copy link
Member

ktmud commented Feb 5, 2021

The ci_check_no_file_changes.sh file seems to be missing!

@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 5, 2021
@villebro villebro changed the title ci: conditionally skip python and frontend tests [WIP] ci: conditionally skip python and frontend tests Feb 5, 2021
@villebro villebro force-pushed the villebro/ci-skip-python branch from 8bc148a to f10c40c Compare February 5, 2021 13:29
@villebro villebro changed the title [WIP] ci: conditionally skip python and frontend tests ci: conditionally skip python and frontend tests Feb 5, 2021
Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @villebro, one step forward to a faster CI

# To check for python and frontend changes, run with CHECKS="python frontend"

URL="https://api.github.com/repos/${GITHUB_REPO}/pulls/${PR_NUMBER}/files"
FILES=$(curl -s -X GET -G $URL | jq -r '.[] | .filename')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: SC2086: Double quote to prevent globbing and word splitting.

@villebro villebro merged commit 5d55c43 into apache:master Feb 5, 2021
@villebro villebro deleted the villebro/ci-skip-python branch February 5, 2021 15:40
@ktmud ktmud mentioned this pull request Feb 25, 2021
6 tasks
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants