From e6edb501d41d767905f1a9900a4aa8f0e3c2e748 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Thu, 18 Jul 2024 21:47:12 +0100 Subject: [PATCH] Add back integration tests --- .github/actions/integration-tests/action.yml | 59 ------------------- .../workflows/docker-build-test-upload.yml | 22 ++++++- Dockerfile | 8 +-- README.md | 9 ++- requirements-docker.txt | 13 ++-- tests_integration/conftest.py | 10 +--- tests_integration/docker-compose.yml | 2 +- 7 files changed, 35 insertions(+), 88 deletions(-) delete mode 100644 .github/actions/integration-tests/action.yml diff --git a/.github/actions/integration-tests/action.yml b/.github/actions/integration-tests/action.yml deleted file mode 100644 index ed3f92cc3..000000000 --- a/.github/actions/integration-tests/action.yml +++ /dev/null @@ -1,59 +0,0 @@ ---- -name: Downstream tests -description: Integration downstream tests the bulid image - -inputs: - architecture: - description: Image architecture - required: true - type: string - runsOn: - description: GitHub Actions Runner image - required: true - type: string - -runs: - using: composite - - steps: - - name: Set jupyter token env - run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV - shell: bash - - - name: Run pytest to test image is working - run: TAG=newly-baked pytest tests_integration/test_image.py - shell: bash - - # The Firefox and its engine geckodrive need do be installed manually to run - # selenium tests. This only works on amd64 architecture and it should be enough only test this - # on one architecture. - - name: Install Firefox - if : ${{ inputs.architecture == 'amd64' }} - uses: browser-actions/setup-firefox@latest - with: - firefox-version: '96.0' - - - name: Install geckodriver - if : ${{ inputs.architecture == 'amd64' }} - run: | - wget -c https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz - tar xf geckodriver-v0.30.0-linux64.tar.gz -C /usr/local/bin - shell: bash - - - name: Run pytest for firefox - if : ${{ inputs.architecture == 'amd64' }} - run: TAG=newly-baked pytest --driver Firefox tests_integration/test_app.py - shell: bash - - - name: Run pytest for Chrome - if : ${{ inputs.architecture == 'amd64' }} - run: TAG=newly-baked pytest --driver Chrome tests_integration/test_app.py - shell: bash - - - name: Upload screenshots as artifacts - if : ${{ inputs.architecture == 'amd64' }} - uses: actions/upload-artifact@v4 - with: - name: Screenshots-CI-${{ inputs.architecture }} - path: screenshots/ - if-no-files-found: error diff --git a/.github/workflows/docker-build-test-upload.yml b/.github/workflows/docker-build-test-upload.yml index 52364203b..e42134699 100644 --- a/.github/workflows/docker-build-test-upload.yml +++ b/.github/workflows/docker-build-test-upload.yml @@ -12,6 +12,8 @@ on: env: FORCE_COLOR: 1 + IMAGE: ghcr.io/aiidalab/qe + BUILDKIT_PROGRESS: plain # https://docs.github.com/en/actions/using-jobs/using-concurrency concurrency: @@ -45,14 +47,14 @@ jobs: uses: docker/metadata-action@v4 with: images: | - name=ghcr.io/aiidalab/qe + name=${{ env.IMAGE }} tags: | type=edge,enable={{is_default_branch}} type=ref,event=pr type=match,pattern=v(\d{2}\.\d{2}.\d+.*),group=1 type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} - - name: Build and load to Docker + - name: Build and push image id: build-upload uses: docker/build-push-action@v5 with: @@ -73,3 +75,19 @@ jobs: - name: Install Dev Dependencies 📦 run: pip install -r requirements-docker.txt + + - name: Set jupyter token env + run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV + + - name: Run pytest for Chrome + run: pytest --driver Chrome tests_integration/ + env: + QE_IMAGE: ${{ env.IMAGE }}@${{ steps.build-upload.outputs.digest }} + + - name: Upload screenshots as artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: Screenshots + path: screenshots/ + if-no-files-found: error diff --git a/Dockerfile b/Dockerfile index 0d0dad7a1..c53456900 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ # syntax=docker/dockerfile:1 -FROM ghcr.io/astral-sh/uv:0.2.18 as uv +FROM ghcr.io/astral-sh/uv:0.2.18 AS uv FROM ghcr.io/aiidalab/full-stack:2024.1019 # Copy whole repo and pre-install the dependencies and app to the tmp folder. # In the before notebook scripts the app will be re-installed by moving it to the app folder. -ENV PREINSTALL_APP_FOLDER ${CONDA_DIR}/aiidalab-qe +ENV PREINSTALL_APP_FOLDER=${CONDA_DIR}/aiidalab-qe COPY --chown=${NB_UID}:${NB_GID} . ${PREINSTALL_APP_FOLDER} USER ${NB_USER} @@ -12,7 +12,7 @@ USER ${NB_USER} # Using uv to speed up installation, per docs: # https://github.com/astral-sh/uv/blob/main/docs/guides/docker.md#using-uv-temporarily # Use the same constraint file as PIP -ENV UV_CONSTRAINT ${PIP_CONSTRAINT} +ENV UV_CONSTRAINT=${PIP_CONSTRAINT} RUN --mount=from=uv,source=/uv,target=/bin/uv \ cd ${PREINSTALL_APP_FOLDER} && \ # Remove all untracked files and directories. For example the setup lock flag file. @@ -39,7 +39,7 @@ RUN mamba create -p /opt/conda/envs/quantum-espresso --yes \ fix-permissions "/home/${NB_USER}" # Download the QE pseudopotentials to the folder for afterware installation. -ENV PSEUDO_FOLDER ${CONDA_DIR}/pseudo +ENV PSEUDO_FOLDER=${CONDA_DIR}/pseudo RUN mkdir -p ${PSEUDO_FOLDER} && \ python -m aiidalab_qe download-pseudos --dest ${PSEUDO_FOLDER} diff --git a/README.md b/README.md index 2c3725ab2..f5c167709 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,14 @@ pytest -sv tests To run the integration tests, you need to build the Docker image first: ``` -cd docker/ -docker buildx bake -f build.json -f docker-bake.hcl --set "*.platform=linux/amd64" --load +docker build . -t aiidalab/qe ``` Then, you can run the integration tests with: ```bash -JUPYTER_TOKEN=max TAG=newly-baked pytest --driver Chrome tests_integration -sv -`````` +pytest --driver Chrome tests_integration +``` ## For maintainers @@ -57,7 +56,7 @@ Additional notes: - Use the `--dry` option to preview the release change. - The release tag (e.g. a/b/rc) is determined from the last release. Use the `--tag` option to switch the release tag. - - For making "outdate" release since we fix minor version to `2x.04.xx` and `2x.10.xx`, use e.g. `bumpver update --set-version v23.10.0rc4 --ignore-vcs-tag` to make the release. + - For making "outdated" release since we fix minor version to `2x.04.xx` and `2x.10.xx`, use e.g. `bumpver update --set-version v23.10.0rc4 --ignore-vcs-tag` to make the release. ## Acknowledgements We acknowledge support from: diff --git a/requirements-docker.txt b/requirements-docker.txt index 4c8d31491..4cfdbb2c9 100644 --- a/requirements-docker.txt +++ b/requirements-docker.txt @@ -1,11 +1,6 @@ docker requests -pre-commit -pytest -pytest-docker - -# test dependencies -pytest-selenium -pytest-html<4.0 -selenium~=4.9.0 -webdriver-manager +pytest~=8.2.0 +pytest-docker~=3.0 +pytest-selenium~=4.1 +selenium==4.20.0 diff --git a/tests_integration/conftest.py b/tests_integration/conftest.py index f27cc24ac..cbd576174 100644 --- a/tests_integration/conftest.py +++ b/tests_integration/conftest.py @@ -4,7 +4,7 @@ import pytest import requests -import selenium.webdriver.support.expected_conditions as EC +import selenium.webdriver.support.expected_conditions as ec from requests.exceptions import ConnectionError from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait @@ -85,7 +85,7 @@ def _selenium_driver(nb_path, wait_time=5.0): selenium.find_element(By.ID, "ipython-main-app") selenium.find_element(By.ID, "notebook-container") WebDriverWait(selenium, 100).until( - EC.invisibility_of_element((By.ID, "appmode-busy")) + ec.invisibility_of_element((By.ID, "appmode-busy")) ) return selenium @@ -116,12 +116,6 @@ def screenshot_dir(): return sdir -@pytest.fixture -def firefox_options(firefox_options): - firefox_options.add_argument("--headless") - return firefox_options - - @pytest.fixture def chrome_options(chrome_options): chrome_options.add_argument("--headless") diff --git a/tests_integration/docker-compose.yml b/tests_integration/docker-compose.yml index 5c506843b..9a5a6809b 100644 --- a/tests_integration/docker-compose.yml +++ b/tests_integration/docker-compose.yml @@ -4,7 +4,7 @@ version: '3.4' services: aiidalab: - image: ${REGISTRY:-}${QE_IMAGE:-aiidalab/qe}:${TAG:-newly-baked} + image: ${REGISTRY:-}${QE_IMAGE:-aiidalab/qe}${TAG} environment: TZ: Europe/Zurich DOCKER_STACKS_JUPYTER_CMD: notebook