Skip to content

Commit

Permalink
Changesets implementation (#66)
Browse files Browse the repository at this point in the history
* ci: consolidate "install dependencies" into an action

* ci: implement changesets

* Update contributor docs

* ci: first deployment via changesets

* fixups

* fix typo
  • Loading branch information
petebacondarwin authored Oct 7, 2024
1 parent 57c450e commit ce8a281
Show file tree
Hide file tree
Showing 14 changed files with 812 additions and 109 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/[email protected]/schema.json",
"changelog": ["@changesets/cli/changelog", { "repo": "opennextjs/opennextjs-cloudflare" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"privatePackages": false
}
5 changes: 5 additions & 0 deletions .changeset/perfect-eyes-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

ci: first deployment via changesets
21 changes: 21 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Install Dependencies"
description: "Install dependencies, fetching from cache when possible"

runs:
using: "composite"
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.18.0
cache: "pnpm"
registry-url: "https://registry.npmjs.org"

- name: Install NPM Dependencies
shell: bash
run: pnpm install --frozen-lockfile
12 changes: 12 additions & 0 deletions .github/utils/custom-changeset-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { execSync } from "node:child_process";

// This script is used by the `changesets.yml` workflow to update the version of the packages being released.
// The standard step is only to run `changeset version` but this does not update the package-lock.json file.
// So we also run `pnpm install`, which does this update.
// This is a workaround until this is handled automatically by `changeset version`.
// See https://github.com/changesets/changesets/issues/421.

// Run standard `changeset version` command to apply changesets, bump versions, and update changelogs
execSync("pnpm exec changeset version", { stdio: "inherit" });
// Update the lockfile with the new versions of the packages
execSync("pnpm install --no-frozen-lockfile", { stdio: "inherit" });
36 changes: 0 additions & 36 deletions .github/utils/update-version.cjs

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Handle Changesets

on:
push:
branches:
- main

jobs:
release:
if: ${{ github.repository_owner == 'opennextjs' }}
name: Handle Changesets
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
# See https://github.com/changesets/action/issues/187
token: ${{ secrets.GH_ACCESS_TOKEN }}
fetch-depth: 0

- name: Install Dependencies
uses: ./.github/actions/install-dependencies

- name: Build Cloudflare package
run: pnpm run build

- name: Create Version PR or Publish to NPM
id: changesets
uses: changesets/action@v1
with:
version: node .github/utils/custom-changeset-version.mjs
publish: pnpm exec changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
NODE_ENV: "production"
15 changes: 2 additions & 13 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,8 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Dependencies
uses: ./.github/actions/install-dependencies

- name: ${{ matrix.script }}
run: pnpm run ${{ matrix.script }}
23 changes: 8 additions & 15 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: |
pnpm install --frozen-lockfile
pnpm run install-playwright
- name: Install Dependencies
uses: ./.github/actions/install-dependencies

- name: Install Playwright
run: pnpm run install-playwright

- name: Build the tool
run: pnpm build

- name: Build all workers
run: pnpm -r build:worker
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/prereleases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ jobs:
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.10.0

- name: Install Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: pnpm i --frozen-lockfile
uses: ./.github/actions/install-dependencies

- name: Build
run: pnpm -F cloudflare run build
Expand Down
182 changes: 182 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Getting started

## Set up your environment

- Install [Node.js v20](https://nodejs.dev/) - we recommend using a Node version manager like [nvm](https://github.com/nvm-sh/nvm) or [volta](https://volta.sh/).
- Install a code editor - we recommend using [VS Code](https://code.visualstudio.com/).
- Install the [git](https://git-scm.com/) version control tool.
- Install the [pnpm](https://pnpm.io/installation) package manager tool.

## Fork and clone this repository

Any contributions you make will be via [Pull Requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) on [GitHub](https://github.com/) developed in a local git repository and pushed to your own fork of the repository.

- Ensure you have [created an account](https://docs.github.com/en/get-started/onboarding/getting-started-with-your-github-account) on GitHub.
- [Create your own fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) of [this repository](https://github.com/opennextjs/opennextjs-cloudflare).
- Clone your fork to your local machine

```sh
> git clone https://github.com/<your-github-username>/opennextjs-cloudflare
> cd opennextjs-cloudflare
```

You can see that your fork is setup as the `origin` remote repository.
Any changes you wish to make should be in a local branch that is then pushed to this origin remote.

```sh
> git remote -v
origin https://github.com/<your-github-username>/opennextjs-cloudflare (fetch)
origin https://github.com/<your-github-username>/opennextjs-cloudflare (push)
```

- Add `opennextjs/opennextjs-cloudflare` as the `upstream` remote repository.

```sh
> git remote add upstream https://github.com/opennextjs/opennextjs-cloudflare
> git remote -v
origin https://github.com/<your-github-username>/opennextjs-cloudflare (fetch)
origin https://github.com/<your-github-username>/opennextjs-cloudflare (push)
upstream https://github.com/opennextjs/opennextjs-cloudflare (fetch)
upstream https://github.com/opennextjs/opennextjs-cloudflare (push)
```

- You should regularly pull from the `main` branch of the `upstream` repository to keep up to date with the latest changes to the project.

```sh
> git switch main
> git pull upstream main
From https://github.com/opennextjs/opennextjs-cloudflare
* branch main -> FETCH_HEAD
Already up to date.
```

## Install dependencies

The Node.js dependencies of the project are managed by the [`pnpm`](https://pnpm.io/) tool.

This repository is setup as a [mono-repo](https://pnpm.io/workspaces) of workspaces. The workspaces are stored in the [`packages`](https://github.com/opennextjs/opennextjs-cloudflare/tree/main/packages) directory.

While each workspace has its own dependencies, you install the dependencies using `pnpm` at the root of the project.

- Install all the dependencies

```sh
> cd opennextjs-cloudflare
> pnpm install
```

## Building and running

Build the cloudflare adaptor tool with:

```sh
pnpm --filter cloudflare build
```

or in watch mode with:

```sh
pnpm --filter cloudflare build:watch
```

Build and preview a Next.js sample application. For example, the `api` application:

```sh
pnpm --filter api preview:worker
```

You can skip building the Next.js app when it has not been modified, and only run the Cloudflare adaptor tool:

```sh
SKIP_NEXT_APP_BUILD=true pnpm --filter api preview:worker
```

## Checking the code

Run the format, lint and type checks on the code:

```sh
pnpm run code:checks
```

Attempt to auto-fix any issues with the format, lint and type checks:

```sh
pnpm run code:fixes
```

## Testing the code

Run all the unit tests, via Vitest:

```sh
pnpm run test
```

Run all the e2e tests, via Playwright:

```sh
pnpm run e2e
```

## Changesets

Every non-trivial change to the project - those that should appear in the changelog - must be captured in a "changeset".
We use the [`changesets`](https://github.com/changesets/changesets/blob/main/README.md) tool for creating changesets, publishing versions and updating the changelog.

- Create a changeset for the current change.

```sh
> pnpm changeset
```

- Select which workspaces are affected by the change and whether the version requires a major, minor or patch release.
- Update the generated changeset with a description of the change.
- Include the generate changeset in the current commit.

```sh
> git add ./changeset/*.md
```

### Changeset message format

Each changeset is a file that describes the change being merged. This file is used to generate the changelog when the changes are released.

To help maintain consistency in the changelog, changesets should have the following format:

```text
<TYPE>: <TITLE>
<BODY>
[BREAKING CHANGES <BREAKING_CHANGE_NOTES>]
```

- `TYPE` should be a single word describing the "type" of the change. For example, one of `feature`, `fix`, `refactor`, `docs` or `chore`.
- `TITLE` should be a single sentence containing an imperative description of the change.
- `BODY` should be one or more paragraphs that go into more detail about the reason for the change and anything notable about the approach taken.
- `BREAKING_CHANGE_NOTES` (optional) should be one or more paragraphs describing how this change breaks current usage and how to migrate to the new usage.

### Changeset file example

The generated changeset file will contain the package name and type of change (eg. `patch`, `minor`, or `major`), followed by our changeset format described above.

Here's an example of a `patch` to the `@opennextjs/cloudflare` package, which provides a `fix`:

```md
---
"@opennextjs/cloudflare": patch
---

fix: replace the word "publish" with "deploy" everywhere.

We should be consistent with the word that describes how we get a worker to the edge. The command is `deploy`, so let's use that everywhere.
```

### Types of changes

We use the following guidelines to determine the kind of change for a PR:

- Bugfixes and experimental features are considered to be 'patch' changes. Be sure to log warnings when experimental features are used.
- New stable features and new deprecation warnings for future breaking changes are considered 'minor' changes. These changes shouldn't break existing code, but the deprecation warnings should suggest alternate solutions to not trigger the warning.
- Breaking changes are considered to be 'major' changes. These are usually when deprecations take effect, or functional breaking behaviour is added with relevant logs (either as errors or warnings.)
Loading

0 comments on commit ce8a281

Please sign in to comment.