-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ci): only check for the token on demand
- Loading branch information
1 parent
ae524dc
commit 4917437
Showing
1 changed file
with
19 additions
and
10 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 |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import { setFailed } from '@actions/core' | ||
import dotenv from 'dotenv' | ||
|
||
import type { Env } from './env.types' | ||
|
||
const prepareEnv = () => { | ||
dotenv.config() | ||
|
||
if (!process.env.GITLAB_TOKEN) { | ||
setFailed('Please add the `GITLAB_TOKEN` to the changesets action') | ||
} | ||
return { | ||
...process.env, | ||
|
||
const env = { ...process.env } | ||
env.GITLAB_CI_USER_EMAIL ??= '"gitlab[bot]@users.noreply.gitlab.com"' | ||
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', | ||
|
||
env.GITLAB_COMMENT_TYPE ??= 'discussion' | ||
env.DEBUG_GITLAB_CREDENTIAL ??= 'false' | ||
|
||
return env as Env | ||
// only check for the token if we are explicitly using it | ||
// eslint-disable-next-line sonar/function-name | ||
get GITLAB_TOKEN() { | ||
if (!process.env.GITLAB_TOKEN) { | ||
throw new Error( | ||
'Please add the `GITLAB_TOKEN` to the changesets action', | ||
) | ||
} | ||
return process.env.GITLAB_TOKEN | ||
}, | ||
} as Env | ||
} | ||
|
||
export const env = prepareEnv() |