Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip NODE_OPTIONS and output in step output #10

Merged
merged 8 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on: push

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Environment
id: source-env
uses: ./
with:
env-file: tests/.env
- name: Test GITHUB_OPTIONS is output
if: ${{ !steps.source-env.outputs.node_options }}
run: exit 1
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`

Unfortunately, `NODE_OPTIONS` cannot be set in this action due to GitHub [security settings](https://github.com/c-py/action-dotenv-to-setenv/issues/9). To work around this `NODE_OPTIONS` is automatically output under `node_options`.

```
- uses: c-py/action-dotenv-to-setenv@v2
id: source-env
with:
env-file: .env
- run: echo ${{ steps.source-env.outputs.node_options }}
```


## 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