Skip to content

Commit

Permalink
feat: support comment on MR automatically (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Aug 16, 2021
1 parent 574e982 commit 1308462
Show file tree
Hide file tree
Showing 22 changed files with 2,608 additions and 776 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-peas-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"changesets-gitlab": minor
---

feat: support comment on MR automatically
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
CHANGELOG.md
!/.*.js
21 changes: 5 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
uses: actions/checkout@v2

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@master
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: yarn

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

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

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

- name: Build and Lint
- name: Build, Lint and Test
run: |
yarn build
yarn lint
yarn typecov
yarn test
env:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true
13 changes: 3 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
uses: actions/checkout@v2
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 14.x
uses: actions/setup-node@master
uses: actions/setup-node@v2
with:
node-version: 14.x
cache: yarn

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

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

Expand Down
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# changesets-gitlab

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.
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.

## Usage

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

### Outputs

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

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

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

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

```yml
stages:
- comment
- release

before_script: yarn --frozen-lockfile

comment:
image: node:lts-alpine
stage: comment
only: merge_requests
script: yarn changesets-gitlab -c # comment automatically like https://github.com/changesets/bot

release:
image: node:lts-alpine
only: main
Expand All @@ -53,14 +61,21 @@ release:
#### With Publishing
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.
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.

```yml
stages:
- comment
- release
before_script: yarn --frozen-lockfile
comment:
image: node:lts-alpine
stage: comment
only: merge_requests
script: yarn changesets-gitlab -c
release:
image: node:lts-alpine
only: main
Expand All @@ -69,14 +84,14 @@ release:
INPUT_PUBLISH: yarn release
```

By default the GitHub Action creates a `.npmrc` file with the following content:
By default the GitLab CI cli creates a `.npmrc` file with the following content:

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

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.
For example, you can add a step before running the Changesets GitHub Action:
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.
For example, you can add a step before running the Changesets GitLab CI cli:

```yml
script: |
Expand All @@ -90,14 +105,22 @@ script: |

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

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.
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.

```yml
stages:
- comment
- release
before_script: yarn --frozen-lockfile
comment:
image: node:lts-alpine
stage: comment
only:
- merge_requests
script: yarn changesets-gitlab -c
release:
image: node:lts-alpine
only: main
Expand All @@ -112,10 +135,18 @@ If you are using [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp), you shoul

```yml
stages:
- comment
- release
before_script: yarn --frozen-lockfile
comment:
image: node:lts-alpine
stage: comment
only:
- merge_requests
script: yarn changesets-gitlab -c
release:
image: node:lts-alpine
only: main
Expand Down
38 changes: 33 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,40 @@
"require": "./lib/index.cjs"
},
"files": [
"lib",
"!lib/*.tsbuildinfo"
"lib"
],
"scripts": {
"build": "run-p build:*",
"build:r": "r -f cjs",
"build:ts": "tsc",
"build:ts": "tsc -p tsconfig.lib.json",
"cli": "node --loader ts-node/esm src/cli.ts",
"lint": "eslint . --cache -f friendly",
"lint": "run-p lint:*",
"lint:es": "eslint . --cache -f friendly",
"lint:tsc": "tsc --noEmit",
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn build",
"release": "changeset publish",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest",
"typecov": "type-coverage"
},
"dependencies": {
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"@gitbeaker/node": "^32.1.1",
"@changesets/assemble-release-plan": "^5.0.0",
"@changesets/config": "^1.6.0",
"@changesets/parse": "^0.3.8",
"@changesets/types": "^4.0.0",
"@gitbeaker/node": "^32.1.2",
"@manypkg/get-packages": "^1.1.1",
"@sentry/node": "^6.11.0",
"dotenv": "^10.0.0",
"fs-extra": "^10.0.0",
"global-agent": "^3.0.0",
"human-id": "^2.0.1",
"js-yaml": "^4.1.0",
"markdown-table": "^3.0.1",
"mdast-util-to-string": "^3.1.0",
"micromatch": "^4.0.4",
"remark-parse": "^10.0.0",
"remark-stringify": "^10.0.0",
"resolve-from": "^5.0.0",
Expand All @@ -51,7 +62,13 @@
"@changesets/cli": "^2.16.0",
"@pkgr/rollup": "^2.0.0",
"@types/global-agent": "^2.1.1",
"@types/jest": "^27.0.1",
"@types/js-yaml": "^4.0.2",
"@types/micromatch": "^4.0.2",
"jest": "^27.0.6",
"patch-package": "^6.4.7",
"postcss": "^8.3.6",
"ts-jest": "^27.0.4",
"ts-node": "^10.2.0",
"type-coverage": "^2.18.0",
"typescript": "^4.3.5"
Expand All @@ -62,6 +79,17 @@
"publishConfig": {
"access": "public"
},
"jest": {
"preset": "ts-jest",
"extensionsToTreatAsEsm": [
".ts"
],
"globals": {
"ts-jest": {
"useESM": true
}
}
},
"typeCoverage": {
"atLeast": 100,
"cache": true,
Expand Down
Loading

0 comments on commit 1308462

Please sign in to comment.