Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Improve test-setup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 26, 2024
1 parent 13dba70 commit 8ba27f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nodejs 18.19.0 20.11.0
task 3.33.1
28 changes: 16 additions & 12 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
- "*.*"
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 8ba27f4

Please sign in to comment.