Hi! I modified the code, but jest was not working properly, so I decided to create an issue.
Expected Behavior
The following values set in the .env file should be reflected:
GITHUB_GRAPHQL_URL="github_graphql_url"
GITHUB_REPOSITORY="github_repository"
Current Behavior
These values are not being reflected. For example, the following values are being set:
GITHUB_GRAPHQL_URL: https://api.github.com/graphql
GITHUB_REPOSITORY: githubdev58yashi/typescript-action
Cause
There seems to be an issue with the config used to load the .env file in src/commands/run.ts. When running in debug mode, logs indicate that existing values cannot be updated.
Code that loads the .env file:
-config({ path: path.resolve(process.cwd(), EnvMeta.dotenvFile) })
+config({ path: path.resolve(process.cwd(), EnvMeta.dotenvFile), debug: true })
Result:
[dotenv@16.4.5][DEBUG] No encoding is specified. UTF-8 is used by default
[dotenv@16.4.5][DEBUG] "GITHUB_GRAPHQL_URL" is already defined and was NOT overwritten
[dotenv@16.4.5][DEBUG] "GITHUB_REPOSITORY" is already defined and was NOT overwritten
This can be resolved by setting the override option to allow updating the values.
-config({ path: path.resolve(process.cwd(), EnvMeta.dotenvFile) })
+config({ path: path.resolve(process.cwd(), EnvMeta.dotenvFile), override: true })
https://github.com/motdotla/dotenv?tab=readme-ov-file#what-happens-to-environment-variables-that-were-already-set
By default, we will never modify any environment variables that have already been set. In particular, if there is a variable in your .env file which collides with one that already exists in your environment, then that variable will be skipped.
If instead, you want to override process.env use the override option.
require('dotenv').config({ override: true })
Environment
Hi! I modified the code, but jest was not working properly, so I decided to create an issue.
Expected Behavior
The following values set in the
.envfile should be reflected:Current Behavior
These values are not being reflected. For example, the following values are being set:
Cause
There seems to be an issue with the
configused to load the.envfile in src/commands/run.ts. When running in debug mode, logs indicate that existing values cannot be updated.Code that loads the .env file:
Result:
This can be resolved by setting the
overrideoption to allow updating the values.https://github.com/motdotla/dotenv?tab=readme-ov-file#what-happens-to-environment-variables-that-were-already-set
Environment