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

Add changesets & CI release with provenance, replace yarn with pnpm #137

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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)
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/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "release",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/eighty-onions-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@api3/ois": minor
---

Add changesets & CI release with provenance, replace yarn with pnpm
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone @api3/ois
uses: actions/checkout@v2
uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
- name: Test
run: yarn test
cache: 'pnpm'
- run: pnpm install
- run: pnpm lint
- run: pnpm test

required-checks-passed:
name: All required checks passed
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release
on:
push:
branches:
- release

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
packages: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install
env:
HUSKY: 0
- run: pnpm build
- run: pnpm test
- name: Prep commit message
run: |
echo "NEW_VERSION=$(pnpm changeset status --output=release.json > /dev/null && jq -r '.releases[0].newVersion' release.json && rm release.json)" >> "$GITHUB_ENV"
- name: Create PR or publish to npm
id: changesets
uses: changesets/action@v1
with:
version: pnpm changeset:version
publish: pnpm changeset publish
title: 'Release v${{ env.NEW_VERSION }}'
commit: 'Release v${{ env.NEW_VERSION }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Create pull request
if: steps.changesets.outputs.published == 'true'
run: gh pr create -B main -H release --title 'Merge release into main' --body 'Merges release into main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .husky/install.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Skip Husky install in production and CI
if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
process.exit(0)
}
const husky = (await import('husky')).default
console.log(husky())
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn lint && yarn test
pnpm lint && pnpm test && pnpm changeset:check
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ coverage/
.idea
.vscode
.DS_Store

.changeset
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can find the documentation for OIS in the [docs](https://docs.api3.org/refer

To install this package run either:

`yarn add @api3/ois`
`pnpm add @api3/ois`

or if you use npm:

Expand Down Expand Up @@ -59,12 +59,17 @@ An example of a valid OIS can be found [here](https://github.com/api3dao/ois/blo

### Release

To release a new version follow these steps:
Releasing is facilitated by GitHub Actions using [changesets/action](https://github.com/changesets/action). To release a
new version follow these steps:

1. `git checkout main && git pull` - ensure you are on a "main" branch with latest changes
2. `yarn version` - choose "x.y.z" as the version to be released
3. `git show` - verify the changes of the version commit
4. `yarn build` - only build the package after the "yarn version" command so the bundled "package.json" uses the updated
version
5. `yarn publish --access public`
6. `git push --follow-tags` - to push the commits to a "main" branch
1. Assuming desired changes are present on `main` with changesets, create a GitHub PR to the `release` branch from
`main`.
2. Merge the PR to `release` **using a merge commit**.
3. The [publish Action workflow](./.github/workflows/publish.yml) will create a release PR.
4. Review the release PR and merge it to `release` using **squash and merge**.
5. The [publish Action workflow](./.github/workflows/publish.yml) will publish a GitHub release and publish the package
to npm with provenance. It will also create a PR for merging the `release` branch back to `main`.
6. Merge the PR to `main` from `release` **using a merge commit**.

Note that development can continue on `main` during the release process, or in other words, `main` does not need to be
protected.
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@
"private": false,
"main": "dist/src/index",
"types": "dist/src/index",
"repository": {
"type": "git",
"url": "https://github.com/api3dao/ois"
},
"files": [
"dist"
],
"scripts": {
"build": "yarn run clean && yarn run compile",
"build": "pnpm run clean && pnpm run compile",
"changeset": "changeset",
"changeset:check": "changeset status --since=origin/main",
"changeset:empty": "changeset --empty",
"changeset:version": "changeset version && pnpm run version",
"clean": "rimraf -g *.tsbuildinfo ./dist *.tgz",
"compile": "tsc --build tsconfig.json",
"lint:prettier:fix": "yarn prettier --write \"./**/*.{js,ts,md,yml}\"",
"lint:prettier": "yarn prettier --check \"./**/*.{js,ts,md,yml}\"",
"lint:tsc": "yarn compile",
"lint": "yarn lint:prettier && yarn lint:tsc",
"prepare": "husky",
"version": "yarn update-fixtures && yarn test && git add --all",
"lint:prettier:fix": "prettier --write \"./**/*.{js,ts,md,yml}\"",
"lint:prettier": "prettier --check \"./**/*.{js,ts,md,yml}\"",
"lint:tsc": "pnpm run compile",
"lint": "pnpm run lint:prettier && pnpm run lint:tsc",
"prepare": "node .husky/install.mjs",
"version": "pnpm run update-fixtures && pnpm test && git add --all",
"test:watch": "jest --watch",
"test": "jest",
"update-fixtures": "ts-node --transpileOnly ./dev-scripts/update-fixtures.ts"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@types/jest": "^28.1.7",
"@types/lodash": "^4.14.202",
"@types/node": "^18.19.14",
"husky": "^9.0.11",
"jest": "^28.1.3",
"prettier": "^3.2.5",
Expand Down
Loading