Skip to content

Commit 1308462

Browse files
authored
feat: support comment on MR automatically (#5)
1 parent 574e982 commit 1308462

File tree

22 files changed

+2608
-776
lines changed

22 files changed

+2608
-776
lines changed

.changeset/nasty-peas-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changesets-gitlab": minor
3+
---
4+
5+
feat: support comment on MR automatically

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
lib
2+
CHANGELOG.md
23
!/.*.js

.github/workflows/ci.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,25 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout Repo
19-
uses: actions/checkout@master
19+
uses: actions/checkout@v2
2020

2121
- name: Setup Node.js ${{ matrix.node }}
22-
uses: actions/setup-node@master
22+
uses: actions/setup-node@v2
2323
with:
2424
node-version: ${{ matrix.node }}
25+
cache: yarn
2526

2627
- name: Link Yarn global binaries into PATH
2728
run: echo "$(yarn global bin)" >> $GITHUB_PATH
2829

29-
- name: Get yarn cache directory path
30-
id: yarn-cache-dir-path
31-
run: echo "::set-output name=dir::$(yarn cache dir)"
32-
33-
- uses: actions/cache@v2
34-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
35-
with:
36-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
37-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
38-
restore-keys: |
39-
${{ runner.os }}-yarn-
40-
4130
- name: Install Dependencies
4231
run: yarn --frozen-lockfile
4332

44-
- name: Build and Lint
33+
- name: Build, Lint and Test
4534
run: |
4635
yarn build
4736
yarn lint
48-
yarn typecov
37+
yarn test
4938
env:
5039
EFF_NO_LINK_RULES: true
5140
PARSER_NO_WATCH: true

.github/workflows/release.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,21 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout Repo
14-
uses: actions/checkout@master
14+
uses: actions/checkout@v2
1515
with:
1616
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1717
fetch-depth: 0
1818

1919
- name: Setup Node.js 14.x
20-
uses: actions/setup-node@master
20+
uses: actions/setup-node@v2
2121
with:
2222
node-version: 14.x
23+
cache: yarn
2324

2425
- name: Get yarn cache directory path
2526
id: yarn-cache-dir-path
2627
run: echo "::set-output name=dir::$(yarn cache dir)"
2728

28-
- uses: actions/cache@v2
29-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
30-
with:
31-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
32-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
33-
restore-keys: |
34-
${{ runner.os }}-yarn-
35-
3629
- name: Install Dependencies
3730
run: yarn --frozen-lockfile
3831

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# changesets-gitlab
22

3-
GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its [GitHub Action](https://github.com/changesets/action), it creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on master, the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.
3+
GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its [GitHub Action](https://github.com/changesets/action), it creates a merge request with all of the package versions updated and changelogs updated and when there are new changesets on master, the MR will be updated. When you're ready, you can merge the merge request and you can either publish the packages to npm manually or setup the action to do it for you.
44

55
## Usage
66

@@ -11,7 +11,7 @@ GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its
1111
- publish - The command to use to build and publish packages
1212
- version - The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided
1313
- commit - The commit message to use. Default to `Version Packages`
14-
- title - The pull request title. Default to `Version Packages`
14+
- title - The merge request title. Default to `Version Packages`
1515

1616
### Outputs
1717

@@ -29,8 +29,9 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests
2929

3030
GITLAB_HOST # optional, if you're using custom GitLab host
3131

32-
GITLAB_TOKEN # required, token with accessibility to push
33-
GITLAB_USER_NAME # required, username with accessibility to push, used in pairs of the above token
32+
GITLAB_TOKEN # required, token with accessibility to push
33+
GITLAB_CI_USER_NAME # required, username with accessibility to push, used in pairs of the above token
34+
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
3435
```
3536

3637
### Example workflow
@@ -41,10 +42,17 @@ Create a file at `.gitlab-ci.yml` with the following content.
4142

4243
```yml
4344
stages:
45+
- comment
4446
- release
4547

4648
before_script: yarn --frozen-lockfile
4749

50+
comment:
51+
image: node:lts-alpine
52+
stage: comment
53+
only: merge_requests
54+
script: yarn changesets-gitlab -c # comment automatically like https://github.com/changesets/bot
55+
4856
release:
4957
image: node:lts-alpine
5058
only: main
@@ -53,14 +61,21 @@ release:
5361
5462
#### With Publishing
5563
56-
Before you can setup this action with publishing, you'll need to have an [npm token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) that can publish the packages in the repo you're setting up the action for and doesn't have 2FA on publish enabled ([2FA on auth can be enabled](https://docs.npmjs.com/about-two-factor-authentication)). You'll also need to [add it as a secret on your GitHub repo](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) with the name `NPM_TOKEN`. Once you've done that, you can create a file at `.github/workflows/release.yml` with the following content.
64+
Before you can setup this action with publishing, you'll need to have an [npm token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) that can publish the packages in the repo you're setting up the action for and doesn't have 2FA on publish enabled ([2FA on auth can be enabled](https://docs.npmjs.com/about-two-factor-authentication)). You'll also need to [add it as a custom environment variable on your GitLab repo](https://docs.gitlab.com/ee/ci/variables/#custom-cicd-variables) with the name `NPM_TOKEN`. Once you've done that, you can create a file at `.gitlab-ci.yml` with the following content.
5765

5866
```yml
5967
stages:
68+
- comment
6069
- release
6170
6271
before_script: yarn --frozen-lockfile
6372
73+
comment:
74+
image: node:lts-alpine
75+
stage: comment
76+
only: merge_requests
77+
script: yarn changesets-gitlab -c
78+
6479
release:
6580
image: node:lts-alpine
6681
only: main
@@ -69,14 +84,14 @@ release:
6984
INPUT_PUBLISH: yarn release
7085
```
7186

72-
By default the GitHub Action creates a `.npmrc` file with the following content:
87+
By default the GitLab CI cli creates a `.npmrc` file with the following content:
7388

7489
```sh
7590
//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}
7691
```
7792

78-
However, if a `.npmrc` file is found, the GitHub Action does not recreate the file. This is useful if you need to configure the `.npmrc` file on your own.
79-
For example, you can add a step before running the Changesets GitHub Action:
93+
However, if a `.npmrc` file is found, the GitLab CI cli does not recreate the file. This is useful if you need to configure the `.npmrc` file on your own.
94+
For example, you can add a step before running the Changesets GitLab CI cli:
8095

8196
```yml
8297
script: |
@@ -90,14 +105,22 @@ script: |
90105

91106
If you need to add additional logic to the version command, you can do so by using a version script.
92107

93-
If the version script is present, this action will run that script instead of `changeset version`, so please make sure that your script calls `changeset version` at some point. All the changes made by the script will be included in the PR.
108+
If the version script is present, this action will run that script instead of `changeset version`, so please make sure that your script calls `changeset version` at some point. All the changes made by the script will be included in the MR.
94109

95110
```yml
96111
stages:
112+
- comment
97113
- release
98114
99115
before_script: yarn --frozen-lockfile
100116
117+
comment:
118+
image: node:lts-alpine
119+
stage: comment
120+
only:
121+
- merge_requests
122+
script: yarn changesets-gitlab -c
123+
101124
release:
102125
image: node:lts-alpine
103126
only: main
@@ -112,10 +135,18 @@ If you are using [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp), you shoul
112135

113136
```yml
114137
stages:
138+
- comment
115139
- release
116140
117141
before_script: yarn --frozen-lockfile
118142
143+
comment:
144+
image: node:lts-alpine
145+
stage: comment
146+
only:
147+
- merge_requests
148+
script: yarn changesets-gitlab -c
149+
119150
release:
120151
image: node:lts-alpine
121152
only: main

package.json

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,40 @@
1616
"require": "./lib/index.cjs"
1717
},
1818
"files": [
19-
"lib",
20-
"!lib/*.tsbuildinfo"
19+
"lib"
2120
],
2221
"scripts": {
2322
"build": "run-p build:*",
2423
"build:r": "r -f cjs",
25-
"build:ts": "tsc",
24+
"build:ts": "tsc -p tsconfig.lib.json",
2625
"cli": "node --loader ts-node/esm src/cli.ts",
27-
"lint": "eslint . --cache -f friendly",
26+
"lint": "run-p lint:*",
27+
"lint:es": "eslint . --cache -f friendly",
28+
"lint:tsc": "tsc --noEmit",
2829
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
2930
"prerelease": "yarn build",
3031
"release": "changeset publish",
32+
"test": "node --experimental-vm-modules ./node_modules/.bin/jest",
3133
"typecov": "type-coverage"
3234
},
3335
"dependencies": {
3436
"@actions/core": "^1.4.0",
3537
"@actions/exec": "^1.1.0",
36-
"@gitbeaker/node": "^32.1.1",
38+
"@changesets/assemble-release-plan": "^5.0.0",
39+
"@changesets/config": "^1.6.0",
40+
"@changesets/parse": "^0.3.8",
41+
"@changesets/types": "^4.0.0",
42+
"@gitbeaker/node": "^32.1.2",
3743
"@manypkg/get-packages": "^1.1.1",
44+
"@sentry/node": "^6.11.0",
3845
"dotenv": "^10.0.0",
3946
"fs-extra": "^10.0.0",
4047
"global-agent": "^3.0.0",
48+
"human-id": "^2.0.1",
49+
"js-yaml": "^4.1.0",
50+
"markdown-table": "^3.0.1",
4151
"mdast-util-to-string": "^3.1.0",
52+
"micromatch": "^4.0.4",
4253
"remark-parse": "^10.0.0",
4354
"remark-stringify": "^10.0.0",
4455
"resolve-from": "^5.0.0",
@@ -51,7 +62,13 @@
5162
"@changesets/cli": "^2.16.0",
5263
"@pkgr/rollup": "^2.0.0",
5364
"@types/global-agent": "^2.1.1",
65+
"@types/jest": "^27.0.1",
66+
"@types/js-yaml": "^4.0.2",
67+
"@types/micromatch": "^4.0.2",
68+
"jest": "^27.0.6",
5469
"patch-package": "^6.4.7",
70+
"postcss": "^8.3.6",
71+
"ts-jest": "^27.0.4",
5572
"ts-node": "^10.2.0",
5673
"type-coverage": "^2.18.0",
5774
"typescript": "^4.3.5"
@@ -62,6 +79,17 @@
6279
"publishConfig": {
6380
"access": "public"
6481
},
82+
"jest": {
83+
"preset": "ts-jest",
84+
"extensionsToTreatAsEsm": [
85+
".ts"
86+
],
87+
"globals": {
88+
"ts-jest": {
89+
"useESM": true
90+
}
91+
}
92+
},
6593
"typeCoverage": {
6694
"atLeast": 100,
6795
"cache": true,

0 commit comments

Comments
 (0)