Skip to content

Commit 95b1def

Browse files
committedJul 4, 2024
fix: add ability to run install command to update locks
1 parent a5db1b4 commit 95b1def

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed
 

‎README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests
4848

4949
GITLAB_HOST # optional, if you're using custom GitLab host, will fallback to `CI_SERVER_URL` if not provided
5050

51-
GITLAB_TOKEN # required, token with accessibility to push
52-
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
53-
GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API
54-
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
55-
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
56-
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
57-
DEBUG_GITLAB_CREDENTIAL # optional, default `false`
58-
GITLAB_COMMENT_CUSTOM_LINKS # optional, allow the linkS for the absent comment to be overwritten
51+
GITLAB_TOKEN # required, token with accessibility to push
52+
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
53+
GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API
54+
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
55+
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
56+
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
57+
DEBUG_GITLAB_CREDENTIAL # optional, default `false`
58+
GITLAB_COMMENT_CUSTOM_LINKS # optional, allow the linkS for the absent comment to be overwritten
59+
UPDATE_PACKAGE_LOCK_BEFORE_MR # optional, default `false`
60+
UPDATE_PACKAGE_LOCK_SCRIPT # optional, default `npm install`
5961
```
6062

6163
### Example workflow

‎src/env.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const env = {
2121
DEBUG_GITLAB_CREDENTIAL: process.env.DEBUG_GITLAB_CREDENTIAL ?? 'false',
2222
GITLAB_COMMENT_CUSTOM_LINKS:
2323
process.env.GITLAB_COMMENT_CUSTOM_LINKS ?? 'false',
24+
UPDATE_PACKAGE_LOCK_BEFORE_MR:
25+
process.env.UPDATE_PACKAGE_LOCK_BEFORE_MR ?? 'false',
26+
UPDATE_PACKAGE_LOCK_SCRIPT:
27+
process.env.UPDATE_PACKAGE_LOCK_BEFORE_MR ?? 'npm install',
2428

2529
// only check for the token if we are explicitly using it
2630
// eslint-disable-next-line sonar/function-name

‎src/run.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import resolveFrom from 'resolve-from'
1010
import semver from 'semver'
1111

1212
import * as context from './context.js'
13+
import { env } from './env.js'
1314
import * as gitUtils from './gitUtils.js'
1415
import readChangesetState from './readChangesetState.js'
1516
import {
@@ -290,6 +291,12 @@ ${
290291
await gitUtils.commitAll(finalCommitMessage)
291292
}
292293

294+
// Allow user to update their lockfiles before mr is created
295+
if (env.UPDATE_PACKAGE_LOCK_BEFORE_MR === 'true') {
296+
const script = env.UPDATE_PACKAGE_LOCK_SCRIPT
297+
await exec(script)
298+
}
299+
293300
await gitUtils.push(versionBranch, { force: true })
294301

295302
const searchResult = await api.MergeRequests.all({

‎src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export type Env = GitLabCIPredefinedVariables &
2323
GITLAB_ADD_CHANGESET_MESSAGE?: string
2424
DEBUG_GITLAB_CREDENTIAL: LooseString<'1' | 'true'>
2525
GITLAB_COMMENT_CUSTOM_LINKS: string
26+
UPDATE_PACKAGE_LOCK_BEFORE_MR: LooseString<'false' | 'true'>
27+
UPDATE_PACKAGE_LOCK_SCRIPT: string
2628

2729
HOME: string
2830
NPM_TOKEN?: string

0 commit comments

Comments
 (0)