From 1bfb1113d3d3ecf5eb82e08f940234bca18786e0 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Wed, 27 May 2020 16:42:40 -0500 Subject: [PATCH] [7.x] Split CI into Jenkins and GitHub Actions --- .ci/run-repository.sh | 1 + .github/workflows/ci.yml | 22 +++++++++++++ test_elasticsearch/run_tests.py | 31 ++++++++++++++++--- .../test_server/test_rest_api_spec.py | 16 +++++----- .../test_server/test_rest_api_spec.py | 16 +++++----- 5 files changed, 66 insertions(+), 20 deletions(-) diff --git a/.ci/run-repository.sh b/.ci/run-repository.sh index f1082440..a4ceff9f 100755 --- a/.ci/run-repository.sh +++ b/.ci/run-repository.sh @@ -37,6 +37,7 @@ docker run \ --env "ELASTICSEARCH_HOST=${ELASTICSEARCH_URL}" \ --env "TEST_SUITE=${TEST_SUITE}" \ --env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \ + --env "TEST_TYPE=server" \ --name elasticsearch-py \ --rm \ --volume `pwd`:/code/elasticsearch-py \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c270c7b..8c272a30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,3 +53,25 @@ jobs: python3.7 -m pip install tox - name: Build the docs run: tox -e docs + + test-linux: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + python-version: [2.7, 3.5, 3.6, 3.7, 3.8] + + steps: + - name: Checkout Repository + uses: actions/checkout@v1 + - name: Set Up Python - ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install -r dev-requirements.txt + - name: Run Tests + run: | + python setup.py test diff --git a/test_elasticsearch/run_tests.py b/test_elasticsearch/run_tests.py index 4b2515a2..4b261970 100755 --- a/test_elasticsearch/run_tests.py +++ b/test_elasticsearch/run_tests.py @@ -63,8 +63,9 @@ def fetch_es_repo(): def run_all(argv=None): sys.exitfunc = lambda: sys.stderr.write("Shutting down....\n") - # fetch yaml tests - fetch_es_repo() + # fetch yaml tests anywhere that's not GitHub Actions + if "GITHUB_ACTION" not in environ: + fetch_es_repo() # always insert coverage when running tests if argv is None: @@ -80,10 +81,32 @@ def run_all(argv=None): "-vv", ] + ignores = [] + # Python 3.6+ is required for async if sys.version_info < (3, 6): - argv.append("--ignore=test_elasticsearch/test_async/") + ignores.append("test_elasticsearch/test_async/") - argv.append(abspath(dirname(__file__)),) + # GitHub Actions, run non-server tests + if "GITHUB_ACTION" in environ: + ignores.extend( + [ + "test_elasticsearch/test_server/", + "test_elasticsearch/test_async/test_server/", + ] + ) + if ignores: + argv.extend(["--ignore=%s" % ignore for ignore in ignores]) + + # Jenkins, only run server tests + if environ.get("TEST_TYPE") == "server": + test_dir = abspath(dirname(__file__)) + argv.append(join(test_dir, "test_server")) + if sys.version_info >= (3, 6): + argv.append(join(test_dir, "test_async/test_server")) + + # Not in CI, run all tests specified. + else: + argv.append(abspath(dirname(__file__))) exit_code = 0 try: diff --git a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py b/test_elasticsearch/test_async/test_server/test_rest_api_spec.py index d849f46d..45585b6b 100644 --- a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_async/test_server/test_rest_api_spec.py @@ -200,11 +200,11 @@ def async_runner(async_client): return AsyncYamlRunner(async_client) -@pytest.mark.parametrize("test_spec", YAML_TEST_SPECS) -async def test_rest_api_spec(test_spec, async_runner): - if not RUN_ASYNC_REST_API_TESTS: - pytest.skip("Skipped running async REST API tests") - if test_spec.get("skip", False): - pytest.skip("Manually skipped in 'SKIP_TESTS'") - async_runner.use_spec(test_spec) - await async_runner.run() +if RUN_ASYNC_REST_API_TESTS: + + @pytest.mark.parametrize("test_spec", YAML_TEST_SPECS) + async def test_rest_api_spec(test_spec, async_runner): + if test_spec.get("skip", False): + pytest.skip("Manually skipped in 'SKIP_TESTS'") + async_runner.use_spec(test_spec) + await async_runner.run() diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index 4e296a15..20536868 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -424,11 +424,11 @@ def sync_runner(sync_client): return YamlRunner(sync_client) -@pytest.mark.parametrize("test_spec", YAML_TEST_SPECS) -def test_rest_api_spec(test_spec, sync_runner): - if RUN_ASYNC_REST_API_TESTS: - pytest.skip("Skipped running sync REST API tests") - if test_spec.get("skip", False): - pytest.skip("Manually skipped in 'SKIP_TESTS'") - sync_runner.use_spec(test_spec) - sync_runner.run() +if not RUN_ASYNC_REST_API_TESTS: + + @pytest.mark.parametrize("test_spec", YAML_TEST_SPECS) + def test_rest_api_spec(test_spec, sync_runner): + if test_spec.get("skip", False): + pytest.skip("Manually skipped in 'SKIP_TESTS'") + sync_runner.use_spec(test_spec) + sync_runner.run()