Skip to content

Commit

Permalink
Setup Changesets (#1722)
Browse files Browse the repository at this point in the history
* chore(changesets): setup changesets for this repository

* chore(changeset): add changeset for package release
  • Loading branch information
ajimae authored Nov 5, 2021
1 parent 8faa5de commit d839b67
Show file tree
Hide file tree
Showing 7 changed files with 665 additions and 403 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
12 changes: 12 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://unpkg.com/@changesets/config@1.6.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "commercetools/nodejs"
}
],
"commit": false,
"access": "restricted",
"baseBranch": "master"
}
65 changes: 65 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Pass a personal access token (using our `ct-release-bot` account) to be able to trigger
# other workflows
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
# https://github.community/t/action-does-not-trigger-another-on-push-tag-action/17148/8
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node (uses version in .nvmrc)
uses: actions/setup-node@v2
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

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

- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
email=npmjs@commercetools.com
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Building packages
run: yarn build

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@master
with:
publish: yarn changeset publish
version: yarn changeset:version-and-format
commit: 'ci(changesets): version packages'
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ To ensure the lock file is up-to-date with the new versions, it's recommended to

## Releases

We use lerna for releasing packages. Just run `yarn release` from `master` (after pulling in the latest merges) to publish a single or a set of modules. Lerna will check changes on packages providing semver bumps according to the commit messages used for each package.
We use lerna to manage our multi-package (monorepo) repository and we use changesets to publish packages to npm, the following steps will allow you to add a changeset to a change you wish to publish

This will also append all PRs up until the release in the `CHANGELOG.md` and push it as a separate commit with the message `docs: update changelog`. For this to work, we need to have a `Type`-label on the PRs, so please make sure they are added.
- Run the command `yarn changeset`, a list of packages will be listed.
- Select the package(s) that include the changes.
- Add the packages you wish to publish to npm
- Commit the changes, push to Github and then create a PR

For this to work, it is essential that you create and export a github token that has read access to your public repos.

`$ export GITHUB_AUTH=<your_token>`
When this PR is merged into the base branch, a new release PR will be created by changeset and this PR is repsonsible for the actual package release.

#### Commit message

Expand Down
22 changes: 1 addition & 21 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,5 @@
"lerna": "3.16.4",
"version": "independent",
"useWorkspaces": true,
"npmclient": "yarn",
"changelog": {
"rootPath": ".",
"repo": "commercetools/nodejs",
"labels": {
"Type: New Feature": ":rocket: New Feature",
"Type: Breaking Change": ":boom: Breaking Change",
"Type: Bug": ":bug: Bug Fix",
"Type: Enhancement": ":nail_care: Enhancement",
"Type: Documentation": ":memo: Documentation",
"Type: Maintenance": ":house: Maintenance"
},
"cacheDir": ".changelog",
"ignoreCommitters": ["renovate", "renovate-bot"]
},
"command": {
"publish": {
"npmClient": "yarn",
"message": "chore(release): releasing component"
}
}
"npmclient": "yarn"
}
16 changes: 5 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"clean": "rm -rf coverage; lerna exec -- rimraf lib dist",
"commit": "git-cz",
"build": "lerna run build --no-private",
"build:changelog": "lerna-changelog --from=$(git log --grep='chore(release): releasing component' --format='%H' | sed -n 2p) > tmp && cat CHANGELOG.md >> tmp && cat tmp > CHANGELOG.md && rm tmp",
"push:changelog": "git add CHANGELOG.md && git commit -m 'docs: update changelog' && git push",
"check-gh-auth-token": "if [[ -z \"${GITHUB_AUTH}\" ]]; then echo \"Need to set GITHUB_AUTH\" && exit 1; fi",
"build:typings": "NODE_ENV=production lerna run build:typings --no-private",
"lint": "jest --projects jest.eslint.config.js jest.flow.config.js",
Expand All @@ -28,7 +26,6 @@
"test:coverage": "yarn build && npm test -- --no-watchman --coverage",
"test:ci": "yarn test -- --ci --no-watchman --maxWorkers=10",
"test:coverage:ci": "yarn test:ci -- --coverage && codecov",
"release": "yarn check-gh-auth-token && cross-env NODE_ENV=cli yarn build && lerna publish --registry=https://registry.npmjs.org/ && yarn build:changelog && yarn push:changelog && yarn docs:publish",
"docs:clean": "rimraf _book",
"docs:prepare": "gitbook install",
"docs:build": "yarn docs:prepare && gitbook build && cp logo/apple-touch-icon.png _book/gitbook/images/apple-touch-icon-precomposed-152.png && cp logo/favicon.ico _book/gitbook/images",
Expand All @@ -37,7 +34,9 @@
"typecheck": "yarn typecheck:flow && yarn typecheck:ts",
"typecheck:flow": "flow check --include-warnings",
"typecheck:ts": "lerna run typecheck:ts",
"package-readme-entry": "./scripts/package-readme-entry.sh"
"package-readme-entry": "./scripts/package-readme-entry.sh",
"changeset": "changeset",
"changeset:version-and-format": "changeset version && prettier --write --parser json '**/package.json'"
},
"workspaces": [
"integration-tests",
Expand All @@ -57,6 +56,8 @@
"@babel/preset-env": "7.11.0",
"@babel/preset-flow": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@changesets/changelog-github": "^0.4.1",
"@changesets/cli": "^2.17.0",
"@commitlint/cli": "9.1.2",
"@commitlint/config-conventional": "9.1.2",
"@rollup/plugin-alias": "3.1.1",
Expand All @@ -73,7 +74,6 @@
"commitizen": "4.1.2",
"common-tags": "1.8.0",
"cross-env": "7.0.2",
"cz-lerna-changelog": "2.0.3",
"debug": "4.1.1",
"eslint": "7.7.0",
"eslint-config-airbnb": "18.2.0",
Expand Down Expand Up @@ -102,7 +102,6 @@
"jest-runner-flowtype": "0.0.7",
"jest-silent-reporter": "0.2.1",
"lerna": "3.22.1",
"lerna-changelog": "1.0.1",
"lint-staged": "10.2.11",
"npm-check-updates": "7.1.1",
"prettier": "2.0.5",
Expand Down Expand Up @@ -136,10 +135,5 @@
"serialize-javascript": "3.1.0",
"diff": "3.5.0",
"object-path": "0.11.5"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-lerna-changelog"
}
}
}
Loading

0 comments on commit d839b67

Please sign in to comment.