From 8ba27f448cb0d24ab1479d10077a8fba4a504038 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 25 Jan 2024 12:49:29 +0000 Subject: [PATCH] Improve test-setup.sh --- .envrc | 2 +- .github/workflows/task.yml | 5 ++++- .tool-versions | 1 + Taskfile.yml | 28 ++++++++++++++++------------ tools/test-setup.sh | 10 +++++++++- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.envrc b/.envrc index e578f9bb..d9ed7e59 100644 --- a/.envrc +++ b/.envrc @@ -5,7 +5,7 @@ # This VIRTUAL_ENV value is also configured inside .vscode/settings.json: export HOSTNAME="${HOSTNAME:-localhost}" -export VIRTUAL_ENV="out/venvs/${HOSTNAME}" +export VIRTUAL_ENV="${PWD}/out/venvs/${HOSTNAME}" # Activate virtualenv (creates it if needed) layout python diff --git a/.github/workflows/task.yml b/.github/workflows/task.yml index 32158772..90ffcdb8 100644 --- a/.github/workflows/task.yml +++ b/.github/workflows/task.yml @@ -17,7 +17,9 @@ env: FORCE_COLOR: "1" # make mocha output colorful # https://docs.github.com/en/actions/learn-github-actions/environment-variables # https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ - WSLENV: CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p + WSLENV: HOSTNAME:CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p + # We define a hostname because otherwise the variable might not always be accessible on runners. + HOSTNAME: gha # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -177,6 +179,7 @@ jobs: . "$HOME/.asdf/asdf.sh" asdf plugin add nodejs asdf plugin add python + asdf plugin add task asdf install asdf info diff --git a/.tool-versions b/.tool-versions index 4c1fdbc6..555e9757 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ nodejs 18.19.0 20.11.0 +task 3.33.1 diff --git a/Taskfile.yml b/Taskfile.yml index e0bc4354..b2c480a7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,16 +3,21 @@ version: "3" env: &env # basically the same thing from .envrc file: - VIRTUAL_ENV: # "{{.VIRTUAL_ENV}}" - sh: echo "${VIRTUAL_ENV:-out/venvs/${HOSTNAME:-localhost}}" + # VIRTUAL_ENV: # "{{.VIRTUAL_ENV}}" + # sh: echo "${VIRTUAL_ENV:-${PWD}/out/venvs/${HOSTNAME:-localhost}}" # Avoid undesired extra hints from docker when pulling images DOCKER_CLI_HINTS: "false" vars: - HOSTNAME: - sh: echo ${HOSTNAME:-localhost} EE_VERSION: sh: ./tools/get-image-version + VIRTUAL_ENV: # "{{.VIRTUAL_ENV}}" + sh: echo "${VIRTUAL_ENV:-${PWD}/out/venvs/${HOSTNAME:-localhost}}" tasks: + foo: + cmds: + - bash -c "set | grep VIRTUAL_ENV" + - "echo 'XX: {{.VIRTUAL_ENV}}'" + - bash -c "set | grep HOSTNAME" default: desc: Run most commands deps: @@ -38,10 +43,9 @@ tasks: cmds: # Retrieve possibly missing commits: - $(git rev-parse --is-shallow-repository) && git fetch --unshallow > /dev/null || true - - git fetch --tags + - git fetch --tags --force - npm run generate-settings-readme - - source $VIRTUAL_ENV/bin/activate && - mkdocs build --strict + - "source {{.VIRTUAL_ENV}}/bin/activate && mkdocs build --strict" setup: desc: Install dependencies @@ -85,7 +89,7 @@ tasks: # as we want to avoid using different node versions across the projects. # 2nd node version is used for preparing for new versions - asdf local nodejs latest:18 latest:$(asdf nodejs resolve lts) - - $VIRTUAL_ENV/bin/python -m pre_commit autoupdate + - "{{.VIRTUAL_ENV}}/bin/python -m pre_commit autoupdate" # bumps some developments dependencies - npx ncu -u --dep dev # running install after ncu is needed in order to update the lock file @@ -98,7 +102,7 @@ tasks: <<: *env PRE_COMMIT_COLOR: always cmds: - - $VIRTUAL_ENV/bin/python -m pre_commit run -a + - "{{.VIRTUAL_ENV}}/bin/python -m pre_commit run -a" silent: true sources: - "*.*" @@ -123,7 +127,7 @@ tasks: # Tests that container engine is functional and that we have the image: - "{{.ENGINE}} run -i ghcr.io/ansible/creator-ee:{{ .EE_VERSION }} ansible-lint --version" - > - source $VIRTUAL_ENV/bin/activate && + source {{.VIRTUAL_ENV}}/bin/activate && command -v ansible-lint && npm run test interactive: true @@ -147,7 +151,7 @@ tasks: - setup cmds: - > - source $VIRTUAL_ENV/bin/activate && + source {{.VIRTUAL_ENV}}/bin/activate && bash -c 'npm run test-with-ee' interactive: true test-without-ee: @@ -156,7 +160,7 @@ tasks: - setup cmds: - > - source $VIRTUAL_ENV/bin/activate && + source {{.VIRTUAL_ENV}}/bin/activate && bash -c 'npm run test-without-ee' interactive: true package: diff --git a/tools/test-setup.sh b/tools/test-setup.sh index 234ac282..237dcf00 100755 --- a/tools/test-setup.sh +++ b/tools/test-setup.sh @@ -5,6 +5,9 @@ # (cspell: disable-next-line) set -euo pipefail +set | grep HOSTNAME +set | grep VIRTUAL_ENV || true + IMAGE=ghcr.io/ansible/creator-ee:$(./tools/get-image-version) PIP_LOG_FILE=out/log/pip.log HOSTNAME="${HOSTNAME:-localhost}" @@ -176,7 +179,12 @@ if [[ "$(command -v npm || true)" == '/mnt/c/Program Files/nodejs/npm' ]]; then nodejs gcc g++ make python3-dev fi -VIRTUAL_ENV=${VIRTUAL_ENV:-out/venvs/${HOSTNAME}} +# if a virtualenv is already active, ensure is the expected one +EXPECTED_VENV="${PWD}/out/venvs/${HOSTNAME}" +if [[ -d "${VIRTUAL_ENV:-}" && "${VIRTUAL_ENV:-}" != "${EXPECTED_VENV}" ]]; then + log warning "Detected another virtualenv active ($VIRTUAL_ENV) than expected one, switching it to ${EXPECTED_VENV}" +fi +VIRTUAL_ENV=${EXPECTED_VENV} if [[ ! -d "${VIRTUAL_ENV}" ]]; then log notice "Creating virtualenv ..." python3 -m venv "${VIRTUAL_ENV}"