From 5266dfeb4a5cc1e1fcc4e8f577c31e2a784aaee9 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 2 Jan 2025 15:54:17 +0000 Subject: [PATCH] Make build environment more flexible (#1748) --- .env | 13 +++++++++ .envrc | 20 +++---------- .github/workflows/ci.yaml | 8 +++--- .tool-versions | 2 +- .vscode/settings.json | 5 ---- Taskfile.yml | 2 +- packages/ansible-language-server/Taskfile.yml | 2 +- tools/precheck.py | 2 +- tools/test-setup.sh | 28 +++++++++++++------ 9 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 000000000..6e4d64091 --- /dev/null +++ b/.env @@ -0,0 +1,13 @@ +#!/bin/bash +export HOSTNAME="${HOSTNAME:-${HOST:-$(hostname)}}" +# 'vsa' is acronym for 'visual studio ansible' +# we use HOME location below to avoid polluting the project directory with, +# temporary data and to allow us to mount the codebase on multiple machines +# for build and testing purposes. +export VIRTUAL_ENV="${HOME}/.local/share/virtualenvs/vsa" + +# Command such `yarn webpack-dev` might fail with +# Reached heap limit Allocation failed - JavaScript heap out of memory +# https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes +# default 16 MiB for 64-bit systems and 8 MiB for 32-bit systems +export NODE_OPTIONS="--max-old-space-size=8192" diff --git a/.envrc b/.envrc index 0d1303a50..5a2a9c8c1 100644 --- a/.envrc +++ b/.envrc @@ -1,20 +1,8 @@ #!/bin/bash -# Helps direnv 2.32.1+ auto activate virtualenv but we do not require -# developers to use it. -# https://github.com/direnv/direnv/wiki/Python -export HOSTNAME="${HOSTNAME:-${HOST:-$(hostname)}}" -# 'vsa' is acronym for 'visual studio ansible' -# we use HOME location below to avoid polluting the project directory with, -# temporary data and to allow us to mount the codebase on multiple machines -# for build and testing purposes. -export VIRTUAL_ENV="${HOME}/.local/share/virtualenvs/vsa" +# direnv specifics: activate virtualenv (creates it if needed) +# for normal env vars, use .env file instead, we do not make direnv a hard +# build dependency. -# Command such `yarn webpack-dev` might fail with -# Reached heap limit Allocation failed - JavaScript heap out of memory -# https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes -# default 16 MiB for 64-bit systems and 8 MiB for 32-bit systems -export NODE_OPTIONS="--max-old-space-size=8192" - -# Activate virtualenv (creates it if needed) +source .env layout python3 source_up 2>/dev/null || true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 986bef116..98d5e1a21 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -41,7 +41,7 @@ jobs: env: SKIP_DOCKER: ${{ matrix.env.SKIP_DOCKER || 0 }} SKIP_PODMAN: ${{ matrix.env.SKIP_PODMAN || 0 }} - # NODE_OPTIONS must be kept in sync with one inside .envrc file + # NODE_OPTIONS must be kept in sync with one inside .env file NODE_OPTIONS: --max-old-space-size=8192 TASKFILE_ARGS: --output=group --output-group-begin='::group::{{.TASK}}' --output-group-end='::endgroup::' @@ -192,7 +192,7 @@ jobs: asdf exec direnv exec . bash -c 'echo "${VIRTUAL_ENV}/bin"' >> "$GITHUB_PATH" - - name: Ensure .envrc file is automatically loaded (direnv) + - name: Ensure .env file is automatically loaded (direnv) if: ${{ !contains(matrix.shell, 'wsl') }} run: | set -ex @@ -204,8 +204,8 @@ jobs: echo "python3 mismatch" exit 98 } - # Ensure NODE_OPTIONS config on CI is identical with the one in .envrc - [[ "${NODE_OPTIONS:-}" == "$(asdf exec direnv exec . printenv NODE_OPTIONS)" ]] || { echo "NODE_OPTIONS mismatch between .envrc and ci.yaml"; exit 97; } + # Ensure NODE_OPTIONS config on CI is identical with the one in .env + [[ "${NODE_OPTIONS:-}" == "$(asdf exec direnv exec . printenv NODE_OPTIONS)" ]] || { echo "NODE_OPTIONS mismatch between .env and ci.yaml"; exit 97; } - name: Enable caching uses: actions/cache@v4 diff --git a/.tool-versions b/.tool-versions index 1c3e8b76e..c196cd0d6 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -direnv 2.34.0 +direnv 2.35.0 nodejs 20.18.0 # asdf install task latest task 3.37.2 diff --git a/.vscode/settings.json b/.vscode/settings.json index 952a27422..b533b2137 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,5 @@ { "explorer.fileNesting.enabled": true, - "explorer.fileNesting.patterns": { - ".gitignore": "pyproject.toml, setup.py, tox.ini, mypy.ini, .pylintrc, .yamllint, .isort.cfg, requirements.in, requirements.txt, constraints.txt, .prettierrc.yaml, .prettierignore, .mocharc.json, .pre-commit-config.yaml, cspell.config.yaml, .config, .gitattributes, .git_archival.txt, .flake8, .darglint, .ansible-lint, .packit.yaml, pytest.ini, codecov.yml, .readthedocs.yml, .prettierrc, .pre-commit-hooks.yaml, .editorconfig, .envrc, Jenkinsfile, commitlint.config.js, package-lock.json, package.nls.json, yarn.lock, tsconfig.json, .eslintrc.json, .mocharc.yml, .ncurc.json, .yarnrc.yml, .vscodeignore, webpack.config.js, webpack.config.js", - "README.md": "CONTRIBUTING.md, LICENSE, CHANGELOG.md, USAGE_DATA.md", - "Containerfile": "Dockerfile" - }, "editor.codeActionsOnSave": ["source.fixAll.eslint"], "editor.formatOnSave": true, "[javascript]": { diff --git a/Taskfile.yml b/Taskfile.yml index 7eda1ab80..1abadaae9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -14,7 +14,7 @@ env: # keep in mind that these do *not* override shell vars: https://github.com/go-task/task/issues/1733 FORCE_COLOR: "true" PRE_COMMIT_COLOR: always - # basically the same thing from .envrc file: + # basically the same thing from .env file: vars: HOSTNAME: sh: echo ${HOSTNAME:-${HOST:-$(hostname)}} diff --git a/packages/ansible-language-server/Taskfile.yml b/packages/ansible-language-server/Taskfile.yml index 5fe90bea4..bf07826a1 100644 --- a/packages/ansible-language-server/Taskfile.yml +++ b/packages/ansible-language-server/Taskfile.yml @@ -7,7 +7,7 @@ includes: dir: ../.. internal: true env: &env - # basically the same thing from .envrc file: + # basically the same thing from .env file: # Avoid undesired extra hints from docker when pulling images DOCKER_CLI_HINTS: "false" vars: diff --git a/tools/precheck.py b/tools/precheck.py index ae8d2fc19..38de37b9a 100644 --- a/tools/precheck.py +++ b/tools/precheck.py @@ -12,7 +12,7 @@ if "--max-old-space-size" not in os.environ.get("NODE_OPTIONS", "") != "ignore": print( - "FATAL: NODE_OPTIONS variable was not found, this likely means that .envrc file was not" + "FATAL: NODE_OPTIONS variable was not found, this likely means that .env file was not" " loaded. Build will likely fail.", file=sys.stderr, ) diff --git a/tools/test-setup.sh b/tools/test-setup.sh index b662f3c91..8f507e5ff 100755 --- a/tools/test-setup.sh +++ b/tools/test-setup.sh @@ -76,15 +76,26 @@ if [[ -z "${HOSTNAME:-}" ]]; then fi log notice "Install required build tools" -for PLUGIN in yarn nodejs task python direnv; do - if ! asdf plugin-list | grep -q $PLUGIN; then - asdf plugin add $PLUGIN - fi -done -asdf install +if type mise >/dev/null; then + log notice "Found mise..." + mise install + mise ls + mise doctor +elif type asdf >/dev/null; then + log notice "Found asdf..." + for PLUGIN in yarn nodejs task python direnv; do + if ! asdf plugin-list | grep -q $PLUGIN; then + asdf plugin add $PLUGIN + fi + done + asdf install -log notice "Report current build tool versions..." -asdf current + log notice "Report current build tool versions..." + asdf current +else + log fatal "Neither mise nor asdf found." + exit 3 +fi if [[ "${OSTYPE:-}" != darwin* ]]; then pgrep "dbus-(daemon|broker)" >/dev/null || { @@ -479,7 +490,6 @@ env: tools: ansible-lint: $(get_version ansible-lint) ansible: $(get_version ansible) - asdf: $(get_version asdf) bash: $(get_version bash) gh: $(get_version gh || echo null) git: $(get_version git)