Skip to content

Commit 6b3355d

Browse files
Chagesets Setup (#1143)
* Initial changeset setup * Update package.json * - to : in script names * Update release.yml * Regen lock * Release guide * Update CONTRIBUTING.md * Update CONTRIBUTING.md Co-authored-by: Ryan Roemer <[email protected]> Co-authored-by: Ryan Roemer <[email protected]>
1 parent 17f80b0 commit 6b3355d

File tree

7 files changed

+950
-32
lines changed

7 files changed

+950
-32
lines changed

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@svitejs/changesets-changelog-github-compact",
5+
{
6+
"repo": "FormidableLabs/spectacle"
7+
}
8+
],
9+
"access": "public",
10+
"baseBranch": "main"
11+
}

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Please describe the tests that you ran to verify your changes. Provide instructi
2525

2626
### Checklist: (Feel free to delete this section upon completion)
2727

28+
- [ ] I have included a [changeset](../CONTRIBUTING.md#changesets) if this change will require a version change to one of the packages.
2829
- [ ] I have performed a self-review of my own code
2930
- [ ] I have commented my code, particularly in hard-to-understand areas
3031
- [ ] I have made corresponding changes to the documentation

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Check Code ${{ matrix.node-version }}
5454
run: yarn check-ci
5555

56-
# NOTE! build-examples also builds the core.
56+
# NOTE! build:examples also builds the core.
5757
# This dependency will be more explicit with wireit
5858
- name: Build Examples ${{ matrix.node-version }}
59-
run: yarn build-examples
59+
run: yarn build:examples

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Spectacle Release Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Use Node.js
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: 18.x
21+
22+
- uses: pnpm/[email protected]
23+
with:
24+
version: 7
25+
26+
- name: Get pnpm store directory
27+
id: pnpm-cache
28+
run: echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
29+
30+
- name: Setup pnpm cache
31+
uses: actions/cache@v3
32+
with:
33+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-pnpm-store-
37+
38+
- name: Install dependencies
39+
run: pnpm install
40+
41+
- name: Build packages
42+
run: pnpm run build
43+
44+
- name: PR or Publish
45+
id: changesets
46+
uses: changesets/action@v1
47+
with:
48+
version: pnpm run version
49+
publish: pnpm changeset publish
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

CONTRIBUTING.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Our examples are spread out across multiple projects depending on where the core
4141
We have various deck scenarios in `examples` in this repository that are part of the development process.
4242

4343
We follow the convention of `start:NAME` to run an in-memory dev server for a specific
44-
example, but we also have a `pnpm run build-examples` script task to make sure we're actually
44+
example, but we also have a `pnpm run build:examples` script task to make sure we're actually
4545
producing non-broken sample presentations as a CI / assurance test.
4646

4747
#### `examples/js`
@@ -94,7 +94,7 @@ $ pnpm run start:one-page
9494

9595
**Note**: This file is published and used by `spectacle-cli`.
9696

97-
**Development Note**: This JS code portion of this file is programmatically updated from the source in `examples/js/index.js` directly into `one-page.html`. Rather than editing directly, please run `pnpm run build-one-page` and verify changes look good.
97+
**Development Note**: This JS code portion of this file is programmatically updated from the source in `examples/js/index.js` directly into `one-page.html`. Rather than editing directly, please run `pnpm run build:one-page` and verify changes look good.
9898

9999
### Examples integration with `spectacle-cli`
100100

@@ -141,14 +141,14 @@ To check (and fix) code:
141141

142142
```bash
143143
$ pnpm run lint
144-
$ pnpm run lint-fix
144+
$ pnpm run lint:fix
145145
```
146146

147147
To check (and fix) formatting of MD, JSON, _and_ code:
148148

149149
```bash
150-
$ pnpm run prettier-check
151-
$ pnpm run prettier-fix
150+
$ pnpm run prettier:check
151+
$ pnpm run prettier:fix
152152
```
153153

154154
We also have a simple one-liner for running both of these fix-checks back-to-back:
@@ -166,34 +166,87 @@ Thanks for taking the time to help us make Spectacle even better! Before you go
166166
ahead and submit a PR, make sure that you have done the following:
167167

168168
- Run all checks using `pnpm run check-ci`.
169-
- Run `pnpm run build-one-page` and check + commit changes to `examples/one-page/index.html`
169+
- Run `pnpm run build:one-page` and check + commit changes to `examples/one-page/index.html`
170170
- Check that both the core library and _all_ examples build: `pnpm run build`.
171+
- Add a [changeset](#changeset) if your PR requires a version change for any of the packages in this repo.
171172
- Everything else included in our [pull request checklist](.github/PULL_REQUEST_TEMPLATE.md).
172173

174+
### Changesets
175+
176+
We use [changesets](https://github.com/changesets/changesets) to create package versions and publish them.
177+
178+
If your work contributes changes that require a change in version to any of the packages, add a changeset by running:
179+
180+
```bash
181+
pnpm changeset
182+
```
183+
184+
which will open an interactive CLI menu. Use this menu to select which packages need versioning, which semantic version changes are needed, and add appropriate messages accordingly.
185+
186+
After this, you'll see a new uncommitted file in `.changesets` that looks something like:
187+
188+
```
189+
$ git status
190+
# ....
191+
Untracked files:
192+
(use "git add <file>..." to include in what will be committed)
193+
.changeset/flimsy-pandas-marry.md
194+
```
195+
196+
Review this file, make any necessary adjustments, and commit the file to source. During the next package release, the changes (and changeset notes) will be automatically incorporated based on these changeset files.
197+
173198
### Releasing a new version to NPM
174199

175200
<details>
176201
<summary>
177202
<i>Only for project administrators</i>
178203
</summary>
179204

180-
```sh
181-
# (1) Update the Changelog, following format from previous versions
182-
# and commit those changes independently of other updates
183-
$ git add CHANGELOG.md && git commit -m "Changes for v<version>"
205+
We use [changesets](https://github.com/changesets/changesets) to create package versions and publish them.
184206

185-
# (2) Run tests, lint, build published dir, update package.json
186-
$ npm version [patch|minor|major|<version>]
207+
Our official release path is to use automation (via GitHub actions) to perform the actual publishing of our packages. The steps are:
187208

188-
# (3) If all is well, publish the new version to the npm registry
189-
$ npm publish
209+
1. Developers add changesets, ideally as part of their PR that have version impacts.
210+
2. On merge of a PR with a changeset file, our automation opens a "Version Packages" PR.
211+
3. On merging the "Version Packages" PR, the automation system publishes the packages.
190212

191-
# (4) Then, update github with the associated tag
192-
$ git push --tags && git push
193-
```
213+
This streamlines releasing to: ensuring PRs have changeset files added as necessary, and approving the "Version Packages" PR generated from GitHub actions to publish a release to all affected packages.
214+
215+
#### Manual Releases
216+
217+
For exceptional circumstances, here is a quick guide to manually publish from a local machine using changesets.
218+
219+
1. Add a changeset with `pnpm changeset`. Generate the changeset file, review it, and commit it.
220+
2. Make a version. Due to our changelog formatting package you will need to create a personal token and pass it to the environment.
221+
```shell
222+
GITHUB_TOKEN=<INSERT TOKEN> pnpm run version
223+
```
224+
Review git changes, tweak, and commit.
225+
3. Publish.
226+
227+
First, build necessary files:
228+
229+
```sh
230+
pnpm run build
231+
```
232+
233+
Then publish:
234+
235+
```sh
236+
# Test things out first
237+
$ pnpm -r publish --dry-run
238+
239+
# The real publish
240+
$ pnpm changeset publish --otp=<insert otp code>
241+
```
242+
243+
Note that publishing multiple pacakges via `changeset` to npm with an OTP code can often fail with `429 Too Many Requests` rate limiting error. Take a 5+ minute coffee break, then come back and try again.
244+
245+
Then issue the following to also push git tags:
194246

195-
Then, go and manually draft a release for your recently pushed tag with notes in
196-
the [Github UI](https://github.com/FormidableLabs/spectacle/releases/new).
247+
```sh
248+
$ git push && git push --tags
249+
```
197250

198251
</details>
199252

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
"start:examples": "pnpm run --parallel --filter \"*example*\" start",
99
"start:cli": "pnpm run --filter spectacle-cli start",
1010
"lint": "eslint --ext .tsx,.ts,.jsx,.js ./examples ./scripts packages/spectacle/src packages/cli/src",
11-
"lint-fix": "pnpm run lint --fix",
11+
"lint:fix": "pnpm run lint --fix",
1212
"prettier": "prettier \"**/*.{js,json,ts,css,md}\"",
13-
"prettier-check": "pnpm run prettier --check",
14-
"prettier-fix": "pnpm prettier --write",
13+
"prettier:check": "pnpm run prettier --check",
14+
"prettier:fix": "pnpm prettier --write",
1515
"typecheck": "pnpm -r typecheck",
1616
"test": "pnpm -r test",
17-
"check": "pnpm run lint && pnpm run prettier-check && pnpm run test && pnpm run typecheck",
17+
"check": "pnpm run lint && pnpm run prettier:check && pnpm run test && pnpm run typecheck",
1818
"check-ci": "pnpm run check",
1919
"clean": "pnpm run -r clean",
20-
"build-examples": "pnpm run --filter spectacle build && pnpm run -r --filter \"*example*\" build",
21-
"build-core": "pnpm run --filter spectacle build",
20+
"build:examples": "pnpm run --filter spectacle build && pnpm run -r --filter \"*example*\" build",
21+
"build:core": "pnpm run --filter spectacle build",
2222
"build": "pnpm run -r build",
23-
"build-one-page": "node ./scripts/one-page.js",
24-
"build:cli": "pnpm run --filter spectacle-cli build"
23+
"build:one-page": "node ./scripts/one-page.js",
24+
"build:cli": "pnpm run --filter spectacle-cli build",
25+
"changeset": "changeset",
26+
"version": "pnpm changeset version && pnpm install --fix-lockfile"
2527
},
2628
"devDependencies": {
2729
"@babel/core": "^7.17.2",
30+
"@changesets/cli": "^2.23.1",
31+
"@types/jest": "^27.0.2",
2832
"@typescript-eslint/eslint-plugin": "^5.4.0",
2933
"@typescript-eslint/parser": "^5.4.0",
3034
"babel-eslint": "^10.1.0",
@@ -36,7 +40,6 @@
3640
"eslint-plugin-react-hooks": "^4.3.0",
3741
"prettier": "^2.4.1",
3842
"pretty": "^2.0.0",
39-
"typescript": "^4.5.2",
40-
"@types/jest": "^27.0.2"
43+
"typescript": "^4.5.2"
4144
}
4245
}

0 commit comments

Comments
 (0)