-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve internal usage of environment variables with prepar…
…ed env (#142)
- Loading branch information
1 parent
d690151
commit 2c2db37
Showing
9 changed files
with
111 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,9 @@ | |
"useESM": true | ||
} | ||
] | ||
}, | ||
"moduleNameMapper": { | ||
"^(\\.{1,2}/.*)\\.js$": "$1" | ||
} | ||
}, | ||
"typeCoverage": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
import { setFailed } from '@actions/core' | ||
import dotenv from 'dotenv' | ||
|
||
import type { Env } from './types' | ||
|
||
dotenv.config() | ||
|
||
let isGitlabTokenValidated = false | ||
|
||
export const env = { | ||
...process.env, | ||
|
||
CI_MERGE_REQUEST_IID: +process.env.CI_MERGE_REQUEST_IID!, | ||
GITLAB_CI_USER_EMAIL: | ||
process.env.GITLAB_CI_USER_EMAIL || 'gitlab[bot]@users.noreply.gitlab.com', | ||
GITLAB_COMMENT_TYPE: process.env.GITLAB_COMMENT_TYPE ?? 'discussion', | ||
DEBUG_GITLAB_CREDENTIAL: process.env.DEBUG_GITLAB_CREDENTIAL ?? 'false', | ||
|
||
// only check for the token if we are explicitly using it | ||
// eslint-disable-next-line sonar/function-name | ||
get GITLAB_TOKEN() { | ||
if (!isGitlabTokenValidated) { | ||
isGitlabTokenValidated = true | ||
if (!process.env.GITLAB_TOKEN) { | ||
setFailed('Please add the `GITLAB_TOKEN` to the changesets action') | ||
} | ||
} | ||
return process.env.GITLAB_TOKEN as string | ||
}, | ||
} as Env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters