Skip to content

Commit

Permalink
Ensure NODE_OPTIONS is the same on local and CI (#1741)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Dec 24, 2024
1 parent f137936 commit 5ca4a7c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ preid
preinstall
prettierrc
preversion
printenv
priyamsahoo
projectuser
prsahoo
Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env:
PRETTIER_LEGACY_CLI: "1" # https://github.com/prettier/prettier/issues/15832
# https://docs.github.com/en/actions/learn-github-actions/environment-variables
# https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
WSLENV: HOSTNAME:CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p:GITHUB_ENV/p:VIRTUAL_ENV/p:SKIP_PODMAN:SKIP_DOCKER
WSLENV: HOSTNAME:CI:FORCE_COLOR:GITHUB_ACTION:GITHUB_ACTION_PATH/p:GITHUB_ACTION_REPOSITORY:GITHUB_WORKFLOW:GITHUB_WORKSPACE/p:GITHUB_PATH/p:GITHUB_ENV/p:VIRTUAL_ENV/p:SKIP_PODMAN:SKIP_DOCKER:NODE_OPTIONS
# We define a hostname because otherwise the variable might not always be accessible on runners.
HOSTNAME: gha

Expand All @@ -41,6 +41,8 @@ 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: --max-old-space-size=8192
TASKFILE_ARGS: --output=group --output-group-begin='::group::{{.TASK}}' --output-group-end='::endgroup::'

defaults:
Expand Down Expand Up @@ -183,15 +185,27 @@ jobs:
asdf exec direnv allow
asdf exec direnv reload
asdf exec direnv exec . bash -c 'echo "VIRTUAL_ENV=${VIRTUAL_ENV}"' >> "$GITHUB_ENV"
# https://github.com/direnv/direnv/wiki/GitHubActions
# Github prevents export of NODE_OPTIONS to GITHUB_ENV due to security reasons:
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
asdf exec direnv export gha >> "$GITHUB_ENV"
asdf exec direnv exec . bash -c 'echo "${VIRTUAL_ENV}/bin"' >> "$GITHUB_PATH"
- name: Ensure virtualenv is active (direnv)
- name: Ensure .envrc file is automatically loaded (direnv)
if: ${{ !contains(matrix.shell, 'wsl') }}
run: |
set -x
test "${VIRTUAL_ENV:-}" = "${HOME}/.local/share/virtualenvs/vsa"
test "$(which python3)" = "${HOME}/.local/share/virtualenvs/vsa/bin/python3"
set -ex
test "${VIRTUAL_ENV:-}" = "${HOME}/.local/share/virtualenvs/vsa" || {
echo "VIRTUAL_ENV mismatch"
exit 99
}
test "$(which python3)" = "${HOME}/.local/share/virtualenvs/vsa/bin/python3" || {
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; }
- name: Enable caching
uses: actions/cache@v4
Expand Down Expand Up @@ -227,7 +241,6 @@ jobs:
- name: task package
id: package
run: |
export NODE_OPTIONS="--max-old-space-size=8192"
task package ${{ matrix.env.TASKFILE_ARGS }}
- name: task ${{ matrix.task-name }}
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ repos:
rev: v8.16.0
hooks:
- id: cspell
args:
- --config=cspell.config.yaml
# name: Spell check with cspell
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
9 changes: 9 additions & 0 deletions tools/precheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Check that the python3 executable points to Python 3.9 or newer."""

import os
import sys

if sys.version_info < (3, 9):
Expand All @@ -8,3 +9,11 @@
file=sys.stderr,
)
sys.exit(99)

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"
" loaded. Build will likely fail.",
file=sys.stderr,
)
sys.exit(98)

0 comments on commit 5ca4a7c

Please sign in to comment.