Skip to content

Commit

Permalink
Introduce Changesets (#10337)
Browse files Browse the repository at this point in the history
* Introduce changesets

* Add check-prerelease workflow

* Add repository check to prevent PR creation on forks
  • Loading branch information
alessbell committed Dec 8, 2022
1 parent 7bff5ac commit f982a8d
Show file tree
Hide file tree
Showing 10 changed files with 4,497 additions and 180 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
@@ -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)
14 changes: 14 additions & 0 deletions .changeset/config.json
@@ -0,0 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "apollographql/apollo-client" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
19 changes: 19 additions & 0 deletions .circleci/config.yml
Expand Up @@ -29,6 +29,25 @@ jobs:
- store_artifacts:
path: reports/junit

# Ensure that any PR that changes packages has a changeset on it (perhaps
# an empty one created with `changeset --empty`).
# We run the Changesets job itself on all branches so that we can require
# it to pass, but we don't run any steps on the "Version Packages" PRs
# themselves.
Changesets:
docker:
- image: circleci/node:16.13.1
steps:
- checkout
- run: npm ci
- unless:
condition:
matches:
pattern: "^changeset-release/.+$"
value: << pipeline.git.branch >>
steps:
- run: npm run changeset-check

workflows:
version: 2
Build and Test:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/check-prerelease.yml
@@ -0,0 +1,15 @@
name: No prerelease file (pre.json) present

on:
pull_request:
branches:
- main

jobs:
check_prerelease:
name: "Check branch does not have a prerelease file committed"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Check that the file .changeset/pre.json is not present"
run: "! test -f .changeset/pre.json"
59 changes: 59 additions & 0 deletions .github/workflows/exit-prerelease.yml
@@ -0,0 +1,59 @@
name: Exit Prerelease Mode

on:
workflow_dispatch:
inputs:
branch:
description: "Exit prerelease mode on release branch"
type: string
default: "release-"
required: true

jobs:
exit_prerelease:
name: Changesets Exit Prerelease
runs-on: ubuntu-latest
# Allow GITHUB_TOKEN to have write permissions
permissions:
contents: write

steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
# Checkout release branch entered when workflow was kicked off
ref: ${{ github.event.inputs.branch }}
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0

- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 18.x

- name: Get latest tagged version
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1

- name: Remove 'v' prefix from version number (e.g. v1.0.0)
uses: mad9000/actions-find-and-replace-string@1
id: formatversion
with:
source: ${{ steps.previoustag.outputs.tag }}
find: "v"
replace: ""

- name: Write previous version to package.json
uses: jaywcjlove/github-action-package@v1.3.0
with:
version: ${{ steps.formatversion.outputs.value }}

- name: Remove pre.json
run: npx rimraf .changeset/pre.json

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Exit prerelease mode
# Commit these changes to the branch workflow is running against
branch: ${{ github.event.inputs.branch }}
63 changes: 63 additions & 0 deletions .github/workflows/prerelease.yml
@@ -0,0 +1,63 @@
name: Prerelease

on:
push:
branches:
# Target release-x.x branches
- "release-*"

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

jobs:
prerelease:
name: Changesets Prerelease
# Prevents changesets action from creating a PR on forks
if: github.repository == 'apollographql/apollo-client'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0

- name: Append NPM token to .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 18.x

- name: Install dependencies with cache
uses: bahmutov/npm-install@v1

- name: Enter prerelease mode
# if .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag alpha
run: |
[ ! -f .changeset/pre.json && !contains(github.event.head_commit.message, 'Exit prerelease') ] \
&& npx changeset pre enter alpha \
|| echo 'Already in pre mode or recently exited'
- name: Create release PR
id: changesets
uses: changesets/action@v1
with:
version: npm run changeset-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish alpha to npm
if: "! test -f .changeset/pre.json"
run: npm run changeset-publish

# - name: Send a Slack notification on Publish
# if: steps.changesets.outputs.published == 'true'
# run: echo "Send message to Slack"
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,50 @@
name: Release

on:
push:
branches:
- main

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

jobs:
release:
name: Changesets Release
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0

- name: Append NPM token to .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 18.x

- name: Install dependencies (with cache)
uses: bahmutov/npm-install@v1

- name: Create release PR or publish to npm + GitHub
id: changesets
uses: changesets/action@v1
with:
version: npm run changeset-version
publish: npm run changeset-publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Send a Slack notification on Publish
# if: steps.changesets.outputs.published == 'true'
# run: echo "Send message to Slack"
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -12,6 +12,7 @@ Here are some ways to contribute to the project, from easiest to most difficult:
- [Reporting bugs](#reporting-bugs)
- [Improving the documentation](#improving-the-documentation)
- [Responding to issues](#responding-to-issues)
- [Changesets](#changesets)
- [Small bug fixes](#small-bug-fixes)
- [Suggesting features](#suggesting-features)
- [Big PRs](#big-prs)
Expand Down Expand Up @@ -43,6 +44,12 @@ Improving the documentation, examples, and other open source content can be the

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)!

### Changesets

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.

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.

### Small bug fixes

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.
Expand Down

0 comments on commit f982a8d

Please sign in to comment.