Skip to content

Unable to Update Some Environment Variables #155

@githubdev58yashi

Description

@githubdev58yashi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions