diff --git a/README.md b/README.md index 89f4776..59a474c 100644 --- a/README.md +++ b/README.md @@ -12,19 +12,19 @@ Adapted from https://github.com/madcoda/dotenv-shell ## Outputs -[set-env](https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable) workflow commands to stdout. +[`echo "{name}={value}"`](https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable) workflow commands to `$GITHUB_ENV`. -``` -::set-env name=TEST_DEFAULT_ENVFILE::expected -::set-env name=TEST_DOTENV_OVERRIDES_DEFAULT::unexpected -::set-env name=TEST_UNQUOTED::unexpected -::set-env name=TEST_UNQUOTED::a=1 b=2 c=3 -::set-env name=TEST_SINGLE_QUOTED::1 2 3 4 -::set-env name=TEST_DOUBLE_QUOTED::1 2 3 4 -::set-env name=TEST_INTERPOLATION::a=1 b=2 c=3 d=4 -::set-env name=TEST_EXISTING::new-value -::set-env name=TEST_DOTENV_OVERRIDES_DEFAULT::expected -::set-env name=TEST_NO_NEWLINE::still there +```shell +echo "TEST_DEFAULT_ENVFILE=expected" >> $GITHUB_ENV +echo "TEST_DOTENV_OVERRIDES_DEFAULT=unexpected" >> $GITHUB_ENV +echo "TEST_UNQUOTED=unexpected" >> $GITHUB_ENV +echo "TEST_UNQUOTED=a=1 b=2 c=3" >> $GITHUB_ENV +echo "TEST_SINGLE_QUOTED=1 2 3 4" >> $GITHUB_ENV +echo "TEST_DOUBLE_QUOTED=1 2 3 4" >> $GITHUB_ENV +echo "TEST_INTERPOLATION=a=1 b=2 c=3 d=4" >> $GITHUB_ENV +echo "TEST_EXISTING=new-value" >> $GITHUB_ENV +echo "TEST_DOTENV_OVERRIDES_DEFAULT=expected" >> $GITHUB_ENV +echo "TEST_NO_NEWLINE=still there" >> $GITHUB_ENV ``` ## Example Usage @@ -39,16 +39,18 @@ with: ``` $ bash tests/dotenv-test.sh -::set-env name=TEST_DEFAULT_ENVFILE::expected -::set-env name=TEST_DOTENV_OVERRIDES_DEFAULT::unexpected -::set-env name=TEST_UNQUOTED::unexpected -::set-env name=TEST_UNQUOTED::a=1 b=2 c=3 -::set-env name=TEST_SINGLE_QUOTED::1 2 3 4 -::set-env name=TEST_DOUBLE_QUOTED::1 2 3 4 -::set-env name=TEST_INTERPOLATION::a=1 b=2 c=3 d=4 -::set-env name=TEST_EXISTING::new-value -::set-env name=TEST_DOTENV_OVERRIDES_DEFAULT::expected -::set-env name=TEST_NO_NEWLINE::still there +Contents of $GITHUB_ENV file: +TEST_DEFAULT_ENVFILE=expected +TEST_DOTENV_OVERRIDES_DEFAULT=unexpected +TEST_UNQUOTED=unexpected +TEST_UNQUOTED=a=1 b=2 c=3 +TEST_SINGLE_QUOTED=1 2 3 4 +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_NO_NEWLINE=still there + Testing blank line parsing: ok Testing unquoted: ok Testing single quoted: ok @@ -58,5 +60,6 @@ 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 +Test error message from missing .env file: ok $ ``` diff --git a/dotenv.sh b/dotenv.sh index ad176fe..b88c8dc 100755 --- a/dotenv.sh +++ b/dotenv.sh @@ -56,9 +56,9 @@ export_envs() { continue fi - value=$(eval echo "$temp") - eval export "$key='$value'"; - echo "::set-env name=$key::$value" + value=$(eval echo "$temp") + eval export "$key='$value'"; + echo "$key=$value" >> $GITHUB_ENV done < $1 } diff --git a/tests/dotenv-test.sh b/tests/dotenv-test.sh index daff58a..a458a08 100755 --- a/tests/dotenv-test.sh +++ b/tests/dotenv-test.sh @@ -3,11 +3,16 @@ main() { cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1 + export GITHUB_ENV=$(mktemp) # shellcheck disable=SC1091 export TEST_EXISTING="expected" export DOTENV_DEFAULT="default.env" source ../dotenv.sh + echo "Contents of \$GITHUB_ENV file:" + cat "$GITHUB_ENV" + echo + echo "Testing blank line parsing: ok" # i.e. didn't crash assert_equal "$TEST_UNQUOTED" 'a=1 b=2 c=3' 'Testing unquoted' assert_equal "$TEST_SINGLE_QUOTED" '1 2 3 4' 'Testing single quoted' @@ -18,8 +23,10 @@ main() { assert_equal "$TEST_DEFAULT_ENVFILE" 'expected' 'Test loading variables from default.env file' assert_equal "$TEST_DOTENV_OVERRIDES_DEFAULT" 'expected' 'Test .env variables override variables from default.env file' - TEST_NO_ENVFILE=`DOTENV_FILE=nonexistent.env ../dotenv.sh 2>&1 >&3 3>&-` # Close stdout for this test + 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' + + rm "$GITHUB_ENV" } assert_equal() {