Skip to content

Commit e2661b7

Browse files
authored
add changesets and documentation (#510)
1 parent 63d1e07 commit e2661b7

File tree

12 files changed

+956
-1612
lines changed

12 files changed

+956
-1612
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,3 @@ steps:
107107
- ssh://git@github.com/segmentio/cache-buildkite-plugin#v2.0.0:
108108
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
109109
paths: [".yarn/cache/"]
110-
111-
# Deploy and NPM publish releases
112-
- label: ":rocket: [Browser] Release Production"
113-
depends_on: [build]
114-
branches: "v*"
115-
agents:
116-
queue: v1
117-
commands:
118-
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
119-
- yarn install --immutable
120-
- yarn workspace @segment/analytics-next exec make build-prod
121-
- NODE_ENV=production RELEASE=true yarn workspace @segment/analytics-next exec bash ./scripts/release.sh
122-
- yarn workspace @segment/analytics-next exec npm publish
123-
plugins:
124-
- ssh://git@github.com/segmentio/cache-buildkite-plugin#v2.0.0:
125-
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
126-
paths: [".yarn/cache/"]

.changeset/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@1.6.0/schema.json",
3+
"ignore": ["standalone-playground", "with-next-js", "with-vite"],
4+
"changelog": [
5+
"@changesets/changelog-github",
6+
{
7+
"repo": "segmentio/analytics-next"
8+
}
9+
],
10+
"commit": false,
11+
"access": "restricted",
12+
"baseBranch": "master",
13+
"linked": []
14+
}

.github/PULL_REQUEST_TEMPLATE

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<!---
22

33
Hello! And thanks for contributing to the Analytics-Next 🎉
4-
5-
Please add a description of your PR, including the what and why
4+
- Please add:
5+
- a description of your PR, including the what and why
6+
- a changeset (if applicable)
67

78
Also make sure to describe how you tested this change, include any gifs or screenshots you find necessary.
8-
99
--->
10+
11+
12+
[] I've included a changeset (psst. run `yarn changeset`. Read about changesets [here](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)).

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v2
17+
18+
- name: Setup Node.js 12.x
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 12.x
22+
cache: "yarn"
23+
24+
- name: Install Dependencies
25+
run: HUSKY=0 yarn install --immutable
26+
27+
- name: Create Release Pull Request or Publish to npm
28+
id: changesets
29+
uses: changesets/action@v1
30+
with:
31+
version: yarn update-versions-and-changelogs
32+
publish: yarn release
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ reports/*
2727
# ignore archives
2828
*.tgz
2929
*.gz
30+
31+
.changelog

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ Thanks for taking the time to contribute to analytics-next!
66

77
This is a list of guidelines to follow to help expedite your pull request so we can get it reviewed/merged more quickly:
88

9+
- Include a changeset by running `yarn changeset` and following the prompts. Read: [An introduction to using changesets](https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md). (*Note: changesets are only for changes that would merit a package bump, not for internal or cosmetic improvements.*)
910
- Make sure existing unit tests and CI are all passing
1011
- Write new unit tests for the code you're contributing
1112
- A major goal of analytics-next is to keep bundle sizes low. Avoid redundancy and use efficient/modern javascript where possible
12-
- Changes must be compatible with major browsers (including IE 11)
13+
- Changes must be compatible with major browsers
1314
- Document your testing process, include screenshots when appropriate
15+

RELEASING.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
11
## Releasing
22

3-
### Feature branches
3+
This repo makes use of the [changesets](https://github.com/changesets/changesets) package to manage changelog generation, and publishing, and pushing appropriate github tags.
4+
## What is a `changeset`?
5+
> "A changeset is an intent to release a set of packages at particular semver bump types with a summary of the changes made."
46
5-
Feature branches are automatically released under:
7+
Read: [An introduction to using changesets](https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md).
68

7-
- `http://cdn.segment.com/analytics-next/br/<branch>/<latest|sha>/standalone.js.gz`
89

9-
### Production
1010

11-
Once you have tested your changes and they have been approved for a new release, merge your pull request and follow the steps:
1211

13-
- `make release`
14-
> creates a release tag that is then compiled and published in CI
12+
13+
To see what changes are going into the next release, run:
14+
```
15+
yarn changeset info
16+
```
17+
To test what the changelog will look like beforehand (locally), you can run:
18+
```bash
19+
export GITHUB_TOKEN="???"
20+
yarn changeset version
21+
```
22+
(see https://github.com/settings/tokens)
23+
24+
Once you have tested your changes and they have been approved for a new release, merge the changeset pull request into master.
25+
26+
27+
28+
## How releasing works
29+
1. As PRs are merged into master, we use a [special GitHub action](https://github.com/changesets/action) to updates the package versions and changelogs, automatically creating a `Versions Packages` PR.
30+
2. Once we're ready to publish a new release, we can look at the `Version Packages` PR. If we like the way the Changelog looks, we can merge it in right there. If we want to edit the generated changelog, we can edit the changelog directly on that PR and then merge. If we aren't ready to merge things in and we want to add more detail to a changeset, we can always edit the changeset in .changesets/* and merge those in. Changesets are just text files, and are meant to be human-editable.
31+
32+
### Releasing is handled for us by the [Release GitHub Action](/.github/workflows/release.yml).
33+
34+
As PRs are opened against `master`, this action will open and update a PR which generates the appropriate `CHANGELOG.md` entries and `package.json` version bumps.
35+
The generated PR has the title "Version Packages"
36+
37+
Once ready for a release, approve the "Version Packages" PR and merge it into `master`.
38+
39+
## FAQ
40+
41+
### How do I publish packages to npm / create a new release?
42+
1. Merge the `Version Packages` PR.
43+
44+
### What does merging in `Version Packages` PR do under the hood?
45+
Information is in the [@changesets automation instructions](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md#how-do-i-run-the-version-and-publish-commands)
46+
47+
### How does the changeset bot and changeset github action work?
48+
[Check out the @changesets automation instructions](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md#automating-changesets)
49+
50+
51+
### I don't want to use automation, how do I manually create a release?
52+
53+
```bash
54+
export GITHUB_TOKEN="???" ## changelog generator requirement (https://github.com/settings/tokens)
55+
56+
yarn update-versions-and-changelogs && ## bump + generate changelog + delete old changesets
57+
git add . && # add generated artifacts
58+
git commit -m "v1.X.X" &&
59+
yarn release && ### run prepublish scripts + publish all packages to npm
60+
git push --follow-tags ### push generated tags to git (e.g @segment/analytics-next@1.X.X)
61+
```
62+
63+
### Feature branches
64+
65+
Feature branches are automatically released under:
66+
67+
- `http://cdn.segment.com/analytics-next/br/<branch>/<latest|sha>/standalone.js.gz`

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414
"lint": "echo 'Linting all workspaces...' && yarn constraints && yarn workspaces foreach -p run lint",
1515
"build:dev": "yarn workspace @segment/analytics-next build:dev",
1616
"dev": "yarn workspace @segment/analytics-next exec make dev",
17-
"postinstall": "husky install"
17+
"postinstall": "husky install",
18+
"changeset": "changeset",
19+
"update-versions-and-changelogs": "changeset version && yarn version-run-all",
20+
"release": "yarn prepublish-run-all && changeset publish && git push --follow-tags",
21+
"prepublish-run-all": "yarn workspaces foreach -pt --no-private run prepublish",
22+
"version-run-all": "yarn workspaces foreach -pt --no-private run version"
1823
},
1924
"packageManager": "yarn@3.2.1",
2025
"devDependencies": {
26+
"@changesets/changelog-github": "^0.4.5",
27+
"@changesets/cli": "^2.23.0",
2128
"@types/jest": "^28.1.1",
2229
"@typescript-eslint/eslint-plugin": "^5.21.0",
2330
"@typescript-eslint/parser": "^5.21.0",
@@ -33,5 +40,9 @@
3340
"ts-jest": "^28.0.4",
3441
"ts-node": "^10.8.0",
3542
"typescript": "^4.6.4"
43+
},
44+
"resolutions": {
45+
"@segment/analytics-next": "workspace:*",
46+
"@segment/analytics-node": "workspace:*"
3647
}
3748
}

packages/browser/Makefile

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ size: ## Verify the final size of Analytics-Next
7373
NODE_ENV=production $(yarn_run) umd > /dev/null && $(yarn_run) size-limit
7474
.PHONY: size
7575

76-
release: ## Releases Analytics Next to stage
77-
$(yarn_run) np --yolo --no-publish --no-release-draft
78-
.PHONY: release
79-
80-
release-manual: ## Releases Analytics Next to production
81-
make build-prod
82-
NODE_ENV=production aws-okta exec plat-write -- ./scripts/release.js
83-
npm publish
84-
.PHONY: release-prod-manual
85-
8676
handshake:
8777
@echo "📡 Establishing Remote connection"
8878
@robo --config ~/dev/src/github.com/segmentio/robofiles/development/robo.yml prod.ssh echo "✅ Connected"

packages/browser/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
"sideEffects": false,
2424
"scripts": {
2525
"build-prep": "sh scripts/build-prep.sh",
26-
"version": "npm run build-prep && git add src/generated/version.ts",
26+
"version": "yarn run build-prep && git add src/generated/version.ts",
2727
"umd": "webpack",
2828
"eslint": "yarn run -T eslint",
2929
"tsc": "yarn run -T tsc",
3030
"jest": "yarn run -T jest",
3131
"concurrently": "yarn run -T concurrently",
3232
"build:dev": "yarn clean && yarn build-prep && yarn concurrently 'yarn umd' 'yarn pkg' 'yarn cjs'",
3333
"build:prod": "NODE_ENV=production yarn clean && yarn build-prep && yarn concurrently 'NODE_ENV=production yarn umd' 'NODE_ENV=production yarn pkg' 'NODE_ENV=production yarn cjs'",
34+
"build": "yarn build:prod",
35+
"prepublish": "echo 'running Prepublish build step...' && yarn build:prod && NODE_ENV=production RELEASE=true bash scripts/release.sh",
3436
"pkg": "yarn tsc -p tsconfig.build.json",
3537
"cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs",
3638
"clean": "rm -rf dist",
@@ -85,7 +87,6 @@
8587
"micro-memoize": "^4.0.9",
8688
"mime": "^2.4.6",
8789
"node-gyp": "^9.0.0",
88-
"np": "^7.6.1",
8990
"playwright": "^1.20.0",
9091
"serve-handler": "^6.1.3",
9192
"size-limit": "^7.0.8",

0 commit comments

Comments
 (0)