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..7c5a25e8 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: @@ -145,28 +147,6 @@ jobs: ~/.config/containers key: ${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles('package.json', 'yarn.lock', '.config/Dockerfile', '**/Taskfile.yml', 'tools/*.*') }} - - name: Install Task - if: "!contains(matrix.shell, 'wsl')" - uses: arduino/setup-task@v1 - with: - version: 3.x - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Task (wsl) - if: "contains(matrix.shell, 'wsl')" - run: | - sudo apt-get update && sudo apt-get install -y curl - sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin - task --version - - - name: Install task inside WSL - if: "contains(matrix.shell, 'wsl')" - run: | - mkdir -p ~/.local/bin - sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin - echo $PATH - command -v task - - name: Install asdf inside WSL if: "contains(matrix.shell, 'wsl')" run: | @@ -177,6 +157,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..d4897bec 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,15 +3,13 @@ version: "3" env: &env # basically the same thing from .envrc file: - VIRTUAL_ENV: # "{{.VIRTUAL_ENV}}" - sh: echo "${VIRTUAL_ENV:-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: + sh: echo "${VIRTUAL_ENV:-${PWD}/out/venvs/${HOSTNAME:-localhost}}" tasks: default: desc: Run most commands @@ -38,10 +36,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 +82,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 +95,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 +120,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 +144,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 +153,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..0a0c02d0 100755 --- a/tools/test-setup.sh +++ b/tools/test-setup.sh @@ -7,7 +7,6 @@ set -euo pipefail IMAGE=ghcr.io/ansible/creator-ee:$(./tools/get-image-version) PIP_LOG_FILE=out/log/pip.log -HOSTNAME="${HOSTNAME:-localhost}" ERR=0 EE_ANSIBLE_VERSION=null EE_ANSIBLE_LINT_VERSION=null @@ -54,6 +53,11 @@ log () { >&2 echo -e "${prefix}${2}${NC}" } +if [[ -z "${HOSTNAME:-}" ]]; then + log error "A valid HOSTNAME environment variable is required but is missing or empty." + exit 2 +fi + log notice "Install latest lts version of nodejs (used by 'node-lts' job)" asdf install @@ -176,7 +180,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}"