Skip to content

Commit

Permalink
fix(ci): only check for the token on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
alan910127 committed Nov 17, 2023
1 parent ae524dc commit 4917437
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/env.ts
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()

0 comments on commit 4917437

Please sign in to comment.