From d696fcaa069be3d37da64d639c56a7f6dfdbd8e6 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Wed, 26 May 2021 09:49:10 -0400 Subject: [PATCH] Clean up CI build (#89) * Clean up CI build There were a few problems with the existing build process, such as, the python version not being passed during sanity tests and versions being hard coded elsewhere. This change ensures that each test scenario gets the correct parameters passed through. It also generally cleans up the process for building the test environment to let ansible-galaxy do its thing. This will make sure the correct version of dependencies get installed. * Add changelog fragment --- .github/workflows/ansible-test.yml | 73 +++--------------------- Makefile | 30 +++++----- changelogs/fragments/89-clean-up-ci.yaml | 3 + ci/downstream.sh | 42 ++++---------- molecule/default/molecule.yml | 3 + requirements.yml | 3 + 6 files changed, 45 insertions(+), 109 deletions(-) create mode 100644 changelogs/fragments/89-clean-up-ci.yaml create mode 100644 requirements.yml diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index be539cb..90fc5d3 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -27,11 +27,8 @@ jobs: - stable-2.11 - devel python: - - 2.7 - 3.7 - 3.8 - exclude: - - python: 3.8 # blocked by ansible/ansible#70155 runs-on: ubuntu-latest steps: - name: Check out code @@ -52,73 +49,20 @@ jobs: # The docker container has all the pinned dependencies that are required. # Explicitly specify the version of Python we want to test - name: Run sanity tests - run: make upstream-test-sanity TEST_ARGS='--python ${{ matrix.python }}' + run: make upstream-test-sanity PYTHON_VERSION='${{ matrix.python }}' working-directory: ./ansible_collections/community/okd -### -# Integration tests (RECOMMENDED) -# -# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html - - # integration: - # runs-on: ubuntu-latest - # name: Integration (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}}) - # strategy: - # fail-fast: false - # matrix: - # ansible: - # - stable-2.9 - # - stable-2.10 - # - devel - # python: - # - 2.7 - # - 3.7 - # - 3.8 - # exclude: - # - python: 3.8 # blocked by ansible/ansible#70155 - - # steps: - # - name: Check out code - # uses: actions/checkout@v2 - # with: - # path: ansible_collections/community/okd - - # - name: Set up Python ${{ matrix.ansible }} - # uses: actions/setup-python@v2 - # with: - # python-version: ${{ matrix.python }} - - # - name: Install ansible-base (${{ matrix.ansible }}) - # run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check - - # # OPTIONAL If your integration test requires Python libraries or modules from other collections - # # Install them like this - # - name: Install collection dependencies - # run: ansible-galaxy collection install kubernetes.core -p . - - # # Run the integration tests - # - name: Run integration test - # run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage - # working-directory: ./ansible_collections/community/okd - - # # ansible-test support producing code coverage date - # - name: Generate coverage report - # run: ansible-test coverage xml -v --requirements --group-by command --group-by version - # working-directory: ./ansible_collections/community/okd - - # # See the reports at https://codecov.io/gh/ansible_collections/GITHUBORG/REPONAME - # - uses: codecov/codecov-action@v1 - # with: - # fail_ci_if_error: false - # downstream-sanity-29: name: Downstream Sanity (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}) strategy: matrix: ansible: - stable-2.9 + - stable-2.10 + - stable-2.11 python: - - 3.6 + - 3.7 + - 3.8 runs-on: ubuntu-latest steps: - name: Check out code @@ -131,12 +75,13 @@ jobs: with: python-version: ${{ matrix.python }} - - name: Install ansible 2.9 - run: pip install "ansible>=2.9.0,<2.10.0" + # Install the head of the given branch (devel, stable-2.10) + - name: Install ansible-base (${{ matrix.ansible }}) + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check # run ansible-test sanity inside of Docker. # The docker container has all the pinned dependencies that are required. # Explicitly specify the version of Python we want to test - name: Run sanity tests - run: make downstream-test-sanity + run: make downstream-test-sanity PYTHON_VERSION='${{ matrix.python }}' working-directory: ./ansible_collections/community/okd diff --git a/Makefile b/Makefile index 4a4c9b3..3ab36ce 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,38 @@ +.PHONY: molecule + # Also needs to be updated in galaxy.yml VERSION = 1.1.2 -# To run sanity tests in a venv, set SANITY_TEST_ARGS to '--venv' SANITY_TEST_ARGS ?= --docker --color +PYTHON_VERSION ?= `python3 -c 'import platform; print("{0}.{1}".format(platform.python_version_tuple()[0], platform.python_version_tuple()[1]))'` clean: rm -f community-okd-$(VERSION).tar.gz + rm -f redhat-openshift-$(VERSION).tar.gz rm -rf ansible_collections build: clean ansible-galaxy collection build -install-kubernetes-src: - ansible-galaxy collection install -p ansible_collections kubernetes.core - -install: build install-kubernetes-src +install: build ansible-galaxy collection install -p ansible_collections community-okd-$(VERSION).tar.gz +sanity: install + cd ansible_collections/community/okd && ansible-test sanity -v --python $(PYTHON_VERSION) $(SANITY_TEST_ARGS) + +molecule: install + molecule test + +test-integration: upstream-test-integration downstream-test-integration + +test-sanity: upstream-test-sanity downstream-test-sanity + test-integration-incluster: ./ci/incluster_integration.sh -test-sanity: upstream-test-sanity downstream-test-sanity +upstream-test-sanity: sanity -test-integration: upstream-test-integration downstream-test-integration - -upstream-test-integration: install - molecule test - -upstream-test-sanity: install - cd ansible_collections/community/okd && ansible-test sanity --exclude ci/ -v $(SANITY_TEST_ARGS) +upstream-test-integration: molecule downstream-test-sanity: ./ci/downstream.sh -s diff --git a/changelogs/fragments/89-clean-up-ci.yaml b/changelogs/fragments/89-clean-up-ci.yaml new file mode 100644 index 0000000..d6a1442 --- /dev/null +++ b/changelogs/fragments/89-clean-up-ci.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - fixes test suite to use correct versions of python and dependencies (https://github.com/ansible-collections/community.okd/pull/89). diff --git a/ci/downstream.sh b/ci/downstream.sh index dc1e2d6..49a3f47 100755 --- a/ci/downstream.sh +++ b/ci/downstream.sh @@ -67,6 +67,7 @@ f_prep() setup.cfg .yamllint requirements.txt + requirements.yml ) # Directories to recursively copy downstream (relative repo root dir path) @@ -179,17 +180,6 @@ f_handle_doc_fragments_workaround() } -f_install_kubernetes_core() -{ - f_log_info "${FUNCNAME[0]}" - local install_collections_dir="${_tmp_dir}/ansible_collections" - - pushd "${_tmp_dir}" - ansible-galaxy collection install -p "${install_collections_dir}" kubernetes.core - popd -} - - f_copy_collection_to_working_dir() { f_log_info "${FUNCNAME[0]}" @@ -211,20 +201,15 @@ f_test_sanity_option() { f_log_info "${FUNCNAME[0]}" f_common_steps - f_install_kubernetes_core pushd "${_build_dir}" || return - ansible-galaxy collection build - f_log_info "SANITY TEST PWD: ${PWD}" - ## Can't do this because the upstream kubernetes.core dependency logic - ## is bound as a Makefile dep to the test-sanity target - #SANITY_TEST_ARGS="--docker --color --python 3.6" make test-sanity - # Run tests in docker if available, venv otherwise if command -v docker &> /dev/null - then - ansible-test sanity --docker -v --exclude ci/ --color --python 3.6 - else - ansible-test sanity --venv -v --exclude ci/ --color --python 3.6 - fi + then + make sanity + else + SANITY_TEST_ARGS="--venv --color" make sanity + fi + f_log_info "SANITY TEST PWD: ${PWD}" + make sanity popd || return f_cleanup } @@ -234,10 +219,9 @@ f_test_integration_option() { f_log_info "${FUNCNAME[0]}" f_common_steps - f_install_kubernetes_core pushd "${_build_dir}" || return f_log_info "INTEGRATION TEST WD: ${PWD}" - OVERRIDE_COLLECTION_PATH="${_tmp_dir}" molecule test + make molecule popd || return f_cleanup } @@ -249,13 +233,7 @@ f_build_option() f_common_steps pushd "${_build_dir}" || return f_log_info "BUILD WD: ${PWD}" - # FIXME - # This doesn't work because we end up either recursively curl'ing - # kubernetes.core and redoing the text replacement over and over - # - # make build - ansible-galaxy collection build - + make build popd || return f_copy_collection_to_working_dir f_cleanup diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 76b53b1..43407bd 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,6 +1,8 @@ --- dependency: name: galaxy + options: + requirements-file: requirements.yml driver: name: delegated platforms: @@ -38,6 +40,7 @@ verifier: scenario: name: default test_sequence: + - dependency - lint - syntax - prepare diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..77ada44 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +collections: + - name: kubernetes.core + version: '>=1.2.0,<1.3.0'