Skip to content

Commit f982a8d

Browse files
authored
Introduce Changesets (#10337)
* Introduce changesets * Add check-prerelease workflow * Add repository check to prevent PR creation on forks
1 parent 7bff5ac commit f982a8d

File tree

10 files changed

+4497
-180
lines changed

10 files changed

+4497
-180
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "apollographql/apollo-client" }
6+
],
7+
"commit": false,
8+
"fixed": [],
9+
"linked": [],
10+
"access": "public",
11+
"baseBranch": "main",
12+
"updateInternalDependencies": "patch",
13+
"ignore": []
14+
}

.circleci/config.yml

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ jobs:
2929
- store_artifacts:
3030
path: reports/junit
3131

32+
# Ensure that any PR that changes packages has a changeset on it (perhaps
33+
# an empty one created with `changeset --empty`).
34+
# We run the Changesets job itself on all branches so that we can require
35+
# it to pass, but we don't run any steps on the "Version Packages" PRs
36+
# themselves.
37+
Changesets:
38+
docker:
39+
- image: circleci/node:16.13.1
40+
steps:
41+
- checkout
42+
- run: npm ci
43+
- unless:
44+
condition:
45+
matches:
46+
pattern: "^changeset-release/.+$"
47+
value: << pipeline.git.branch >>
48+
steps:
49+
- run: npm run changeset-check
50+
3251
workflows:
3352
version: 2
3453
Build and Test:
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: No prerelease file (pre.json) present
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check_prerelease:
10+
name: "Check branch does not have a prerelease file committed"
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: "Check that the file .changeset/pre.json is not present"
15+
run: "! test -f .changeset/pre.json"

.github/workflows/exit-prerelease.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Exit Prerelease Mode
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: "Exit prerelease mode on release branch"
8+
type: string
9+
default: "release-"
10+
required: true
11+
12+
jobs:
13+
exit_prerelease:
14+
name: Changesets Exit Prerelease
15+
runs-on: ubuntu-latest
16+
# Allow GITHUB_TOKEN to have write permissions
17+
permissions:
18+
contents: write
19+
20+
steps:
21+
- name: Checkout repo
22+
uses: actions/checkout@v3
23+
with:
24+
# Checkout release branch entered when workflow was kicked off
25+
ref: ${{ github.event.inputs.branch }}
26+
# Fetch entire git history so Changesets can generate changelogs
27+
# with the correct commits
28+
fetch-depth: 0
29+
30+
- name: Setup Node.js 18.x
31+
uses: actions/setup-node@v2
32+
with:
33+
node-version: 18.x
34+
35+
- name: Get latest tagged version
36+
id: previoustag
37+
uses: WyriHaximus/github-action-get-previous-tag@v1
38+
39+
- name: Remove 'v' prefix from version number (e.g. v1.0.0)
40+
uses: mad9000/actions-find-and-replace-string@1
41+
id: formatversion
42+
with:
43+
source: ${{ steps.previoustag.outputs.tag }}
44+
find: "v"
45+
replace: ""
46+
47+
- name: Write previous version to package.json
48+
uses: jaywcjlove/[email protected]
49+
with:
50+
version: ${{ steps.formatversion.outputs.value }}
51+
52+
- name: Remove pre.json
53+
run: npx rimraf .changeset/pre.json
54+
55+
- uses: stefanzweifel/git-auto-commit-action@v4
56+
with:
57+
commit_message: Exit prerelease mode
58+
# Commit these changes to the branch workflow is running against
59+
branch: ${{ github.event.inputs.branch }}

.github/workflows/prerelease.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Prerelease
2+
3+
on:
4+
push:
5+
branches:
6+
# Target release-x.x branches
7+
- "release-*"
8+
9+
concurrency: ${{ github.workflow }}-${{ github.ref }}
10+
11+
jobs:
12+
prerelease:
13+
name: Changesets Prerelease
14+
# Prevents changesets action from creating a PR on forks
15+
if: github.repository == 'apollographql/apollo-client'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
with:
21+
# Fetch entire git history so Changesets can generate changelogs
22+
# with the correct commits
23+
fetch-depth: 0
24+
25+
- name: Append NPM token to .npmrc
26+
run: |
27+
cat << EOF > "$HOME/.npmrc"
28+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
29+
EOF
30+
env:
31+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
32+
33+
- name: Setup Node.js 18.x
34+
uses: actions/setup-node@v2
35+
with:
36+
node-version: 18.x
37+
38+
- name: Install dependencies with cache
39+
uses: bahmutov/npm-install@v1
40+
41+
- name: Enter prerelease mode
42+
# if .changeset/pre.json does not exist and we did not recently exit
43+
# prerelease mode, enter prerelease mode with tag alpha
44+
run: |
45+
[ ! -f .changeset/pre.json && !contains(github.event.head_commit.message, 'Exit prerelease') ] \
46+
&& npx changeset pre enter alpha \
47+
|| echo 'Already in pre mode or recently exited'
48+
49+
- name: Create release PR
50+
id: changesets
51+
uses: changesets/action@v1
52+
with:
53+
version: npm run changeset-version
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Publish alpha to npm
58+
if: "! test -f .changeset/pre.json"
59+
run: npm run changeset-publish
60+
61+
# - name: Send a Slack notification on Publish
62+
# if: steps.changesets.outputs.published == 'true'
63+
# run: echo "Send message to Slack"

.github/workflows/release.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+
jobs:
11+
release:
12+
name: Changesets Release
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v3
17+
with:
18+
# Fetch entire git history so Changesets can generate changelogs
19+
# with the correct commits
20+
fetch-depth: 0
21+
22+
- name: Append NPM token to .npmrc
23+
run: |
24+
cat << EOF > "$HOME/.npmrc"
25+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
26+
EOF
27+
env:
28+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
29+
30+
- name: Setup Node.js 18.x
31+
uses: actions/setup-node@v2
32+
with:
33+
node-version: 18.x
34+
35+
- name: Install dependencies (with cache)
36+
uses: bahmutov/npm-install@v1
37+
38+
- name: Create release PR or publish to npm + GitHub
39+
id: changesets
40+
uses: changesets/action@v1
41+
with:
42+
version: npm run changeset-version
43+
publish: npm run changeset-publish
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
47+
48+
# - name: Send a Slack notification on Publish
49+
# if: steps.changesets.outputs.published == 'true'
50+
# run: echo "Send message to Slack"

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Here are some ways to contribute to the project, from easiest to most difficult:
1212
- [Reporting bugs](#reporting-bugs)
1313
- [Improving the documentation](#improving-the-documentation)
1414
- [Responding to issues](#responding-to-issues)
15+
- [Changesets](#changesets)
1516
- [Small bug fixes](#small-bug-fixes)
1617
- [Suggesting features](#suggesting-features)
1718
- [Big PRs](#big-prs)
@@ -43,6 +44,12 @@ Improving the documentation, examples, and other open source content can be the
4344

4445
In addition to reporting issues, a great way to contribute to Apollo is to respond to other peoples' issues and try to identify the problem or help them work around it. If you’re interested in taking a more active role in this process, please go ahead and respond to issues. And don't forget to say "Hi" in our [community forums](https://community.apollographql.com)!
4546

47+
### Changesets
48+
49+
Apollo Client uses [changesets](https://github.com/changesets/changesets) to automate its versioning and release process. When contributing to Apollo Client, your PR should contain a "changeset" that can be generated by running `npx changeset` from your branch locally.
50+
51+
The changeset CLI will ask you to enter the corresponding [semver bump type](https://semver.org/) and a description of your changes: feel free to enter a brief description via the command line and continue editing the generated Markdown file found inside of `.changeset` in your editor of choice. When editing your changeset's Markdown file, you can leverage any of the features of GitHub flavored markdown! The description you provide in your changeset will be used to generate an entry in `CHANGELOG.md` and the release notes in a future release, so the more complete and descriptive the better.
52+
4653
### Small bug fixes
4754

4855
For a small bug fix change (less than 20 lines of code changed), feel free to open a pull request. We’ll try to merge it as fast as possible and ideally publish a new release on the same day. The only requirement is, make sure you also add a test that verifies the bug you are trying to fix.

0 commit comments

Comments
 (0)