Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Changesets usage to automate releases #174

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"changelog": [
"@changesets/changelog-github",
{ "repo": "TBD54566975/tbdex-js" }
],
"commit": false,
"fixed": [["@tbdex/protocol", "@tbdex/http-client", "@tbdex/http-server"]],
"linked": [],
"access": "restricted",
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
Expand Down
38 changes: 0 additions & 38 deletions .github/workflows/changeset-version.yml

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/create-gh-release.yml

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
name: Publish Docs to GH Pages

on:
workflow_run:
workflows: ["Create GH Release"]
types:
- completed
# Manual trigger
workflow_dispatch:
# Call from the release workflow
workflow_call:

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
Expand All @@ -25,7 +24,7 @@ jobs:
- name: Checkout source
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
submodules: 'true'
submodules: "true"

- name: install pnpm
uses: pnpm/action-setup@v2
Expand Down
95 changes: 0 additions & 95 deletions .github/workflows/npm-publish.yml

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Release

on:
push:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

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

jobs:
release:
# prevents this action from running on forks
if: github.repository == 'TBD54566975/tbdex-js'
permissions:
contents: write # to create release (changesets/action)
pull-requests: write # to create pull request (changesets/action)
id-token: write # necessary for NPM provenance

name: Release
runs-on: ubuntu-latest

outputs:
published: ${{ steps.changesets.outputs.published }}

steps:
- name: Checkout source
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
submodules: "true"

- name: install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Set up Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Verify NPM token is authenticated with NPMjs.com
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm whoami

- name: Install dependencies
run: pnpm install

- name: Build all workspace packages
run: pnpm build

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
id: changesets
with:
publish: pnpm changeset publish
version: pnpm changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish `next` preview
Copy link
Contributor

@KendallWeihe KendallWeihe Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what does this do exactly? it publishes a package with version equal to next?

what is this checking for (line below) steps.changesets.outputs.pullRequestNumber != ''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, didn't read the full description, my bad

"Also, if there are any present changesets on main we are automatically publishing a preview release using the next tag."

excellent!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Leaving this unresolved for awareness!

if: steps.changesets.outputs.published != 'true' && steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.hasChangesets == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git checkout main
SHORT_SHA=$(git rev-parse --short HEAD)
pnpm changeset version --snapshot next-$SHORT_SHA
pnpm changeset publish --no-git-tag --tag next
publish-docs:
needs: release
name: Publish Docs
if: ${{ needs.release.outputs.published == 'true' }}
uses: ./.github/workflows/docs-publish.yml
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@ Prior to merging your branch into main, and given you have relevant semantic ver

**You can stop here!** It is recommended to merge your branch into main with the `.changeset/*.md` files, at which point, the Changeset GitHub Action will automatically pick up those changes and open a PR to automate the `pnpm changeset version` execution. For example, [see this PR](https://github.com/TBD54566975/tbdex-js/pull/36). This command will do two things: update the version numbers in the relevant `package.json` files & also aggregate Summary notes into the relevant `CHANGELOG.md` files. In keeping with the staged commit analogy, this is akin to the actual commit.

## Cutting Releases
## Publishing Releases

When a changeset PR is merged to main we will automatically create a GitHub release using the workflow [Create GH Release](./.github/workflows/create-gh-release.yml).
Just merge the [Version Packages PR](https://github.com/TBD54566975/tbdex-js/pulls?q=is%3Apr+author%3Aapp%2Fgithub-actions+%22Version+Packages%22+) when you are ready to publish the new versions!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this language is much better!


When these PRs are merged to main we will automatically publish to NPM and create corresponding git tags with the changelog notes, and mirror each tag to a GitHub release per package.

> [!NOTE]
>
> This is done by detecting the merged PR branch name: `changeset-release/main`.
Also, by creating the GH release, the packages will be automatically published to npm. So this way the engineer can simply just merge the changeset PR and the new GH Release and packages version will be automagically published to npm!
> This is all achieved by the Changesets GitHub action being used in the [Release Workflow](./.github/workflows/release.yml).
## Steps for a new release publish
## Recapping the steps for a new release publish

Recap of the above changesets, plus the release process:

1. Open a PR
2. `changeset-bot` will automatically [comment on the PR](https://github.com/TBD54566975/tbdex-js/pull/30#issuecomment-1732721942) with a reminder & recommendations for semver
3. Run `pnpm changeset` locally and push changes (`.changet/*.md`)
4. Merge PR into `main`
5. Profit from the release automation:
- [Create GH Release Workflow](./.github/workflows/create-gh-release.yml) will automatically create a new [GitHub Release](https://github.com/TBD54566975/tbdex-js/releases)
- [NPM Publish Workflow](./.github/workflows/npm-publish.yml) will automatically publish a [new version to NPM](https://www.npmjs.com/package/@tbdex/protocol?activeTab=versions)
5. Profit from the automated release pipeline:
- [Release Workflow](./.github/workflows/release.yml) will create a new Version Package PR, or update the existing one
- When maintainers are ready to publish the new changes, they will merge that PR and the very same [Release Workflow](./.github/workflows/release.yml) will automatically publish a [new version to NPM](https://www.npmjs.com/package/@tbdex/protocol?activeTab=versions), and publish the docs to https://tbd54566975.github.io/tbdex-js/

## Working with the `tbdex` submodule

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.26.2",
"@npmcli/package-json": "5.0.0",
"@types/chai": "4.3.5",
"@types/eslint": "8.44.2",
"@types/mocha": "10.0.1",
"typescript": "5.2.2",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"c8": "^9.1.0",
"eslint": "8.49.0",
"mocha": "10.2.0",
"mocha-junit-reporter": "2.2.1",
"npkill": "0.11.3",
"semver": "7.5.4"
"semver": "7.5.4",
"typescript": "5.2.2"
},
"pnpm": {
"overrides": {
Expand Down
Loading
Loading