Skip to content

Commit

Permalink
introduce changesets for package build (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Dec 17, 2024
1 parent 979e605 commit 251bec9
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 68 deletions.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [["@apollo/*"]],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["app-dir", "hack-the-supergraph-ssr", "apollo-next-13-demo"]
}
6 changes: 6 additions & 0 deletions .changeset/nine-maps-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@apollo/client-react-streaming": patch
"@apollo/experimental-nextjs-app-support": patch
---

Change package publishing to Changesets
12 changes: 12 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"app-dir": "0.1.0",
"hack-the-supergraph-ssr": "0.1.0",
"apollo-next-13-demo": "0.1.0",
"@apollo/client-react-streaming": "0.11.7",
"@apollo/experimental-nextjs-app-support": "0.11.7"
},
"changesets": []
}
72 changes: 36 additions & 36 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
name: Publish Package to npmjs
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "The version to publish"
required: true
tag:
description: "Tag"
required: true
default: "latest"
type: choice
options:
- latest
- snapshot
- next
push:
branches:
- main
- next

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

jobs:
publish:
if: github.repository == 'apollographql/apollo-client-nextjs'
runs-on: ubuntu-latest
permissions:
id-token: write
Expand All @@ -36,6 +30,9 @@ jobs:
- uses: actions/checkout@v4
with:
token: ${{ steps.github-actions-bot-app-token.outputs.token }}
# Fetch entire git history so Changesets can generate changelogs
# with the correct commits
fetch-depth: 0

- uses: actions/setup-node@v4
with:
Expand All @@ -44,30 +41,33 @@ jobs:
cache: "yarn"
- run: yarn install --immutable --mode=skip-build

- name: "@apollo/client-react-streaming: update version"
- name: Alpha branch - Enter prerelease mode (alpha by default)
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag alpha
if: github.ref_name == 'next' && !contains(github.event.head_commit.message, 'Exit prerelease')
run: |
yarn workspace @apollo/client-react-streaming exec npm pkg set "version=${{ inputs.version }}"
yarn workspace @apollo/client-react-streaming exec jq '{ version: .version, dependencies: .dependencies, peerDependencies: .peerDependencies }' package.json
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
npx changeset pre enter alpha
git add -A
git commit -m 'Enter prerelease mode'
git push
- name: "@apollo/experimental-nextjs-app-support: update version and dependencies"
- name: Append NPM token to .npmrc
run: |
yarn workspace @apollo/experimental-nextjs-app-support exec npm pkg set "dependencies[@apollo/client-react-streaming]=${{ inputs.version }}" "version=${{ inputs.version }}"
yarn workspace @apollo/experimental-nextjs-app-support exec jq '{ version: .version, dependencies: .dependencies, peerDependencies: .peerDependencies }' package.json
- name: Commit changes back
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Release version ${{ inputs.version }}@${{ inputs.tag}} to npm"
push_options: ""
skip_dirty_check: false
tagging_message: "v.${{ inputs.version }}"

- name: "@apollo/client-react-streaming: publish"
run: yarn workspace @apollo/client-react-streaming exec npm publish --access public --tag ${{ inputs.tag }} --provenance
cat << EOF > "$HOME/.npmrc"
provenance=true
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: "@apollo/experimental-nextjs-app-support: publish"
run: yarn workspace @apollo/experimental-nextjs-app-support exec npm publish --access public --tag ${{ inputs.tag }} --provenance
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: yarn changeset version
publish: yarn changeset publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ steps.github-actions-bot-app-token.outputs.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 1 addition & 3 deletions integration-test/shared/build-client-react-streaming.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ the package.
const { execFileSync } = require("node:child_process");
const { join, dirname } = require("node:path");

const monorepoRoot = dirname(
require.resolve("monorepo", { paths: [process.env.INIT_CWD] })
);
const monorepoRoot = join(process.env.PROJECT_CWD, "..");
const pathToArchive = join(execEnv.tempDir, "archive.tgz");

execFileSync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ the package.
const { execFileSync } = require("node:child_process");
const { join, dirname } = require("node:path");

const monorepoRoot = dirname(
require.resolve("monorepo", { paths: [process.env.INIT_CWD] })
);
const monorepoRoot = join(process.env.PROJECT_CWD, "..");
const pathToArchive = join(execEnv.tempDir, "archive.tgz");

setTimeout(() => {
Expand Down
6 changes: 3 additions & 3 deletions integration-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ __metadata:

"@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
version: 0.11.7
resolution: "@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs#./shared/build-client-react-streaming.cjs::hash=48b117&locator=%40integration-test%2Froot%40workspace%3A."
resolution: "@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs#./shared/build-client-react-streaming.cjs::hash=4f1b75&locator=%40integration-test%2Froot%40workspace%3A."
dependencies:
ts-invariant: "npm:^0.10.3"
peerDependencies:
"@apollo/client": ^3.10.4
react: ^18 || >=19.0.0-rc
checksum: 10/8e12155ebcb9672f5b645c364d356018014df750412c61613341121ebb4d4eabb5f42cd9018cc3a81ad988f1b425548d68254ca49ede19c31d0d9e5a9a4f240a
checksum: 10/776f2b39d02b55f0ce93bbbecf1cca82343bedc7e7427869ed060a02eea846cc76a165b9744f625ee7c4a992310522fe768a8bd90f28b52c4b77070929651525
languageName: node
linkType: hard

Expand Down Expand Up @@ -82,7 +82,7 @@ __metadata:

"@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs::locator=%40integration-test%2Froot%40workspace%3A.":
version: 0.11.7
resolution: "@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs#./shared/build-experimental-nextjs-app-support.cjs::hash=fa2496&locator=%40integration-test%2Froot%40workspace%3A."
resolution: "@apollo/experimental-nextjs-app-support@exec:./shared/build-experimental-nextjs-app-support.cjs#./shared/build-experimental-nextjs-app-support.cjs::hash=db9e8a&locator=%40integration-test%2Froot%40workspace%3A."
dependencies:
"@apollo/client-react-streaming": "npm:0.11.7"
peerDependencies:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "monorepo",
"private": true,
"packageManager": "[email protected]",
"workspaces": [
"packages/*",
"examples/*"
],
"main": "package.json",
"dependencies": {
"monorepo": "link:.",
"@changesets/cli": "^2.27.10",
"prettier": "^3.0.0",
"semver": "^7.6.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@internal/test-utils",
"private": true,
"devDependencies": {
"typescript": "*"
},
Expand Down
Loading

0 comments on commit 251bec9

Please sign in to comment.