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 (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 27, 2024
1 parent 13dba70 commit 8f8f9be
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 38 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
27 changes: 4 additions & 23 deletions .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 @@ -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: |
Expand All @@ -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
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
21 changes: 9 additions & 12 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
- "*.*"
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 8f8f9be

Please sign in to comment.