From 66d4d6e4d462b1ec49ef079db8cddd20225c59cf Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 20 Nov 2023 20:14:01 +1100 Subject: [PATCH] Attempt to resolve failing action --- README.md | 19 +++++++++++++++++++ dotenv.sh | 10 ++++++++++ tests/.env | 5 ++++- tests/dotenv-test.sh | 4 ++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79ea9ee..c64842e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,19 @@ with: env-file: .env ``` +## Usage with `NODE_OPTIONS` + +``` + - uses: c-py/action-dotenv-to-setenv@v2 + id: source-env + with: + env-file: .env + + - + +``` + + ## Tests ``` @@ -45,21 +58,27 @@ TEST_DOTENV_OVERRIDES_DEFAULT=unexpected TEST_UNQUOTED=unexpected TEST_UNQUOTED=a=1 b=2 c=3 TEST_SINGLE_QUOTED=1 2 3 4 +TEST_SINGLE_QUOTE_NO_INTERPOLATE=${TEST} TEST_DOUBLE_QUOTED=1 2 3 4 TEST_INTERPOLATION=a=1 b=2 c=3 d=4 TEST_EXISTING=new-value TEST_DOTENV_OVERRIDES_DEFAULT=expected +TEST_SPECIAL_CHARACTER=special(character TEST_NO_NEWLINE=still there Testing blank line parsing: ok Testing unquoted: ok Testing single quoted: ok +Testing single-quoted variables arent interpolated: ok Testing double quoted: ok Testing interpolation: ok Testing overwrite of existing variables: ok Testing parsing of last line: ok Test loading variables from default.env file: ok Test .env variables override variables from default.env file: ok +Testing special characters: ok Test error message from missing .env file: ok +Test NODE_OPTIONS skipped: ok +Test NODE_OPTIONS set in output: ok $ ``` diff --git a/dotenv.sh b/dotenv.sh index e229bbd..6c959a1 100755 --- a/dotenv.sh +++ b/dotenv.sh @@ -46,6 +46,10 @@ is_blank() { return 1 } +is_node_options() { + [[ "$1" == "NODE_OPTIONS" ]] +} + export_envs() { while IFS='=' read -r key temp || [ -n "$key" ]; do if is_comment "$key"; then @@ -65,6 +69,12 @@ export_envs() { # shellcheck disable=SC2086 value=$(eval echo ${temp}); + # If this is node options output it to GITHUB_OUTPUT + if is_node_options "$key"; then + echo "node_options=$value" >> $GITHUB_OUTPUT + continue + fi + eval export "$key='$value'"; echo "$key=$value" >> $GITHUB_ENV; done < $1 diff --git a/tests/.env b/tests/.env index 0fb9baf..aca9e76 100644 --- a/tests/.env +++ b/tests/.env @@ -21,4 +21,7 @@ TEST_DOTENV_OVERRIDES_DEFAULT="expected" TEST_SPECIAL_CHARACTER=special(character # Test that the last variable is parsed despite no trailing new line -TEST_NO_NEWLINE="still there" \ No newline at end of file +TEST_NO_NEWLINE="still there" + +# Test node options are skipped https://github.com/c-py/action-dotenv-to-setenv/issues/9 +NODE_OPTIONS="--max-old-space-size=2048" diff --git a/tests/dotenv-test.sh b/tests/dotenv-test.sh index a9640d7..e119faf 100755 --- a/tests/dotenv-test.sh +++ b/tests/dotenv-test.sh @@ -4,6 +4,7 @@ main() { cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1 export GITHUB_ENV=$(mktemp) + export GITHUB_OUTPUT=$(mktemp) # shellcheck disable=SC1091 export TEST_EXISTING="expected" export DOTENV_DEFAULT="default.env" @@ -29,6 +30,9 @@ main() { TEST_NO_ENVFILE=`DOTENV_FILE=nonexistent.env ../dotenv.sh 2>&1` # Close stdout for this test assert_equal "$TEST_NO_ENVFILE" "nonexistent.env file not found" 'Test error message from missing .env file' + + assert_equal "$NODE_OPTIONS" "" "Test NODE_OPTIONS skipped" + assert_equal "$(cat $GITHUB_OUTPUT)" "node_options=--max-old-space-size=2048" "Test NODE_OPTIONS set in output" rm "$GITHUB_ENV" }