Skip to content

Commit

Permalink
Attempt to resolve failing action
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 20, 2023
1 parent 65b1a43 commit 66d4d6e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand All @@ -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
$
```
10 changes: 10 additions & 0 deletions dotenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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"
4 changes: 4 additions & 0 deletions tests/dotenv-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
Expand Down

0 comments on commit 66d4d6e

Please sign in to comment.