Skip to content

Commit

Permalink
add changesets and documentation (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Jun 30, 2022
1 parent 63d1e07 commit e2661b7
Show file tree
Hide file tree
Showing 12 changed files with 956 additions and 1,612 deletions.
17 changes: 0 additions & 17 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,3 @@ steps:
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
paths: [".yarn/cache/"]

# Deploy and NPM publish releases
- label: ":rocket: [Browser] Release Production"
depends_on: [build]
branches: "v*"
agents:
queue: v1
commands:
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
- yarn install --immutable
- yarn workspace @segment/analytics-next exec make build-prod
- NODE_ENV=production RELEASE=true yarn workspace @segment/analytics-next exec bash ./scripts/release.sh
- yarn workspace @segment/analytics-next exec npm publish
plugins:
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
paths: [".yarn/cache/"]
14 changes: 14 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"ignore": ["standalone-playground", "with-next-js", "with-vite"],
"changelog": [
"@changesets/changelog-github",
{
"repo": "segmentio/analytics-next"
}
],
"commit": false,
"access": "restricted",
"baseBranch": "master",
"linked": []
}
9 changes: 6 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!---

Hello! And thanks for contributing to the Analytics-Next 🎉

Please add a description of your PR, including the what and why
- Please add:
- a description of your PR, including the what and why
- a changeset (if applicable)

Also make sure to describe how you tested this change, include any gifs or screenshots you find necessary.

--->


[] 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)).
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
branches:
- master

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2

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

- name: Install Dependencies
run: HUSKY=0 yarn install --immutable

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: yarn update-versions-and-changelogs
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ reports/*
# ignore archives
*.tgz
*.gz

.changelog
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Thanks for taking the time to contribute to analytics-next!

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

- 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.*)
- Make sure existing unit tests and CI are all passing
- Write new unit tests for the code you're contributing
- A major goal of analytics-next is to keep bundle sizes low. Avoid redundancy and use efficient/modern javascript where possible
- Changes must be compatible with major browsers (including IE 11)
- Changes must be compatible with major browsers
- Document your testing process, include screenshots when appropriate

67 changes: 60 additions & 7 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,67 @@
## Releasing

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

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

### Production

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

- `make release`
> creates a release tag that is then compiled and published in CI

To see what changes are going into the next release, run:
```
yarn changeset info
```
To test what the changelog will look like beforehand (locally), you can run:
```bash
export GITHUB_TOKEN="???"
yarn changeset version
```
(see https://github.com/settings/tokens)

Once you have tested your changes and they have been approved for a new release, merge the changeset pull request into master.



## How releasing works
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.
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.

### Releasing is handled for us by the [Release GitHub Action](/.github/workflows/release.yml).

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.
The generated PR has the title "Version Packages"

Once ready for a release, approve the "Version Packages" PR and merge it into `master`.

## FAQ

### How do I publish packages to npm / create a new release?
1. Merge the `Version Packages` PR.

### What does merging in `Version Packages` PR do under the hood?
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)

### How does the changeset bot and changeset github action work?
[Check out the @changesets automation instructions](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md#automating-changesets)


### I don't want to use automation, how do I manually create a release?

```bash
export GITHUB_TOKEN="???" ## changelog generator requirement (https://github.com/settings/tokens)

yarn update-versions-and-changelogs && ## bump + generate changelog + delete old changesets
git add . && # add generated artifacts
git commit -m "v1.X.X" &&
yarn release && ### run prepublish scripts + publish all packages to npm
git push --follow-tags ### push generated tags to git (e.g @segment/[email protected])
```

### Feature branches

Feature branches are automatically released under:

- `http://cdn.segment.com/analytics-next/br/<branch>/<latest|sha>/standalone.js.gz`
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
"lint": "echo 'Linting all workspaces...' && yarn constraints && yarn workspaces foreach -p run lint",
"build:dev": "yarn workspace @segment/analytics-next build:dev",
"dev": "yarn workspace @segment/analytics-next exec make dev",
"postinstall": "husky install"
"postinstall": "husky install",
"changeset": "changeset",
"update-versions-and-changelogs": "changeset version && yarn version-run-all",
"release": "yarn prepublish-run-all && changeset publish && git push --follow-tags",
"prepublish-run-all": "yarn workspaces foreach -pt --no-private run prepublish",
"version-run-all": "yarn workspaces foreach -pt --no-private run version"
},
"packageManager": "[email protected]",
"devDependencies": {
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.0",
"@types/jest": "^28.1.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
Expand All @@ -33,5 +40,9 @@
"ts-jest": "^28.0.4",
"ts-node": "^10.8.0",
"typescript": "^4.6.4"
},
"resolutions": {
"@segment/analytics-next": "workspace:*",
"@segment/analytics-node": "workspace:*"
}
}
10 changes: 0 additions & 10 deletions packages/browser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ size: ## Verify the final size of Analytics-Next
NODE_ENV=production $(yarn_run) umd > /dev/null && $(yarn_run) size-limit
.PHONY: size

release: ## Releases Analytics Next to stage
$(yarn_run) np --yolo --no-publish --no-release-draft
.PHONY: release

release-manual: ## Releases Analytics Next to production
make build-prod
NODE_ENV=production aws-okta exec plat-write -- ./scripts/release.js
npm publish
.PHONY: release-prod-manual

handshake:
@echo "📡 Establishing Remote connection"
@robo --config ~/dev/src/github.com/segmentio/robofiles/development/robo.yml prod.ssh echo "✅ Connected"
Expand Down
5 changes: 3 additions & 2 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
"sideEffects": false,
"scripts": {
"build-prep": "sh scripts/build-prep.sh",
"version": "npm run build-prep && git add src/generated/version.ts",
"version": "yarn run build-prep && git add src/generated/version.ts",
"umd": "webpack",
"eslint": "yarn run -T eslint",
"tsc": "yarn run -T tsc",
"jest": "yarn run -T jest",
"concurrently": "yarn run -T concurrently",
"build:dev": "yarn clean && yarn build-prep && yarn concurrently 'yarn umd' 'yarn pkg' 'yarn cjs'",
"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'",
"build": "yarn build:prod",
"prepublish": "echo 'running Prepublish build step...' && yarn build:prod && NODE_ENV=production RELEASE=true bash scripts/release.sh",
"pkg": "yarn tsc -p tsconfig.build.json",
"cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs",
"clean": "rm -rf dist",
Expand Down Expand Up @@ -85,7 +87,6 @@
"micro-memoize": "^4.0.9",
"mime": "^2.4.6",
"node-gyp": "^9.0.0",
"np": "^7.6.1",
"playwright": "^1.20.0",
"serve-handler": "^6.1.3",
"size-limit": "^7.0.8",
Expand Down
1 change: 1 addition & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build:esm": "yarn tsc -p tsconfig.build.json --outDir ./dist/esm --module esnext",
"watch:build": "yarn concurrently 'yarn:build:cjs --watch --sourceMap' 'yarn:build:esm --watch --sourceMap'",
"watch:test": "yarn test --watch",
"prepublish": "echo 'Prepublish script...\n' && yarn build",
"tsc": "yarn run -T tsc",
"eslint": "yarn run -T eslint",
"concurrently": "yarn run -T concurrently",
Expand Down
Loading

0 comments on commit e2661b7

Please sign in to comment.