Skip to content

Commit 78048eb

Browse files
authored
Use changesets for releases (#106)
1 parent 9715e45 commit 78048eb

File tree

11 files changed

+828
-15
lines changed

11 files changed

+828
-15
lines changed

.changeset/config.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{
6+
"repo": "OpenZeppelin/openzeppelin-foundry-upgrades"
7+
}
8+
],
9+
"commit": false,
10+
"fixed": [],
11+
"linked": [],
12+
"access": "public",
13+
"baseBranch": "main",
14+
"updateInternalDependencies": "patch",
15+
"ignore": []
16+
}

.github/actions/setup/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Setup Node environment
33
runs:
44
using: composite
55
steps:
6-
- uses: actions/setup-node@v4
6+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
77
with:
8-
node-version: 18.x
8+
node-version: 20.x
99
cache: yarn
1010

1111
- name: Install dependencies
1212
run: yarn --frozen-lockfile --prefer-offline
13-
shell: bash
13+
shell: bash

.github/workflows/changeset.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Changeset
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- labeled
11+
- unlabeled
12+
13+
concurrency:
14+
group: changeset-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
check:
19+
runs-on: ubuntu-latest
20+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ignore-changeset') }}
21+
steps:
22+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
23+
with:
24+
fetch-depth: 0 # Include history so Changesets finds merge-base
25+
- name: Set up environment
26+
uses: ./.github/actions/setup
27+
- name: Check changeset
28+
run: npx changeset status --since=origin/${{ github.base_ref }}

.github/workflows/publish.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish Packages
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency: version-or-publish-${{ github.ref }}
7+
8+
jobs:
9+
publish:
10+
name: Publish Packages
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
runs-on: ubuntu-latest
15+
environment: publish
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
fetch-depth: 0 # To get all tags
20+
ref: ${{ github.ref }}
21+
- name: Set up environment
22+
uses: ./.github/actions/setup
23+
- name: Install Foundry
24+
uses: foundry-rs/foundry-toolchain@82dee4ba654bd2146511f85f0d013af94670c4de # v1.4.0
25+
- name: Create Prepare Release PR or Publish
26+
id: changesets
27+
uses: changesets/action@001cd79f0a536e733315164543a727bdf2d70aff # v1.5.1
28+
with:
29+
title: Prepare Release
30+
commit: Prepare Release
31+
version: npm run version-package
32+
publish: npm run publish-package
33+
commitMode: github-api
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
- name: Check changesets status
38+
if: steps.changesets.outputs.hasChangesets == 'true'
39+
run: |
40+
echo "Changesets found. Merge Prepare Release PR before publishing."
41+
exit 1
42+
- name: Check publish status
43+
if: steps.changesets.outputs.published == 'false'
44+
run: |
45+
echo "Publish failed. Check the logs for more details."
46+
exit 1
47+
- name: Publish to Soldeer
48+
if: steps.changesets.outputs.published == 'true'
49+
run: |
50+
mkdir -p ~/.soldeer
51+
echo "$SOLDEER_TOKEN" > ~/.soldeer/.soldeer_login
52+
PACKAGE_VERSION=$(jq -r .version package.json)
53+
echo "Publishing version $PACKAGE_VERSION to Soldeer..."
54+
forge soldeer push openzeppelin-foundry-upgrades~$PACKAGE_VERSION
55+
shell: bash
56+
env:
57+
SOLDEER_TOKEN: ${{ secrets.SOLDEER_TOKEN }}

.github/workflows/version.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Version Packages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'docs/**'
9+
10+
concurrency: version-or-publish-${{ github.ref }}
11+
12+
jobs:
13+
version:
14+
name: Prepare Release PR
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
fetch-depth: 0 # To get all tags
23+
ref: ${{ github.ref }}
24+
- name: Set up environment
25+
uses: ./.github/actions/setup
26+
- name: Create Prepare Release PR
27+
uses: changesets/action@001cd79f0a536e733315164543a727bdf2d70aff # v1.5.1
28+
with:
29+
title: Prepare Release
30+
commit: Prepare Release
31+
version: npm run version-package
32+
commitMode: github-api
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.soldeerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Assumes .gitignore's contents are automatically included
22

3-
.git/
3+
# Ignore hidden files and directories
4+
.*

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"lint": "prettier --log-level warn --ignore-path .gitignore '{src,test}/**/*.sol' --check && solhint 'src/**/*.sol'",
2525
"lint:fix": "prettier --log-level warn --ignore-path .gitignore '{src,test}/**/*.sol' --write",
2626
"docgen": "hardhat clean && hardhat compile && hardhat docgen",
27-
"docgen:test": "yarn docgen && git diff --exit-code docs/modules/api/pages"
27+
"docgen:test": "yarn docgen && git diff --exit-code docs/modules/api/pages",
28+
"version-package": "bash scripts/release/version.sh",
29+
"publish-package": "bash scripts/release/publish.sh"
2830
},
2931
"devDependencies": {
3032
"@nomicfoundation/hardhat-foundry": "^1.1.1",
@@ -39,7 +41,9 @@
3941
"prettier-plugin-solidity": "^1.1.0",
4042
"solhint": "^3.3.6",
4143
"solhint-plugin-openzeppelin": "file:scripts/solhint-custom",
42-
"solidity-docgen": "^0.6.0-beta.36"
44+
"solidity-docgen": "^0.6.0-beta.36",
45+
"@changesets/cli": "^2.29.3",
46+
"@changesets/changelog-github": "^0.5.1"
4347
},
4448
"peerDependencies": {
4549
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.10",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
3+
// Adjusts the format of the changelog that changesets generates.
4+
5+
const { readFileSync, writeFileSync } = require('fs');
6+
const { join } = require('path');
7+
8+
function formatChangelog(dir) {
9+
const changelogPath = join(dir, 'CHANGELOG.md');
10+
11+
const changelog = readFileSync(changelogPath, 'utf8');
12+
13+
// Groups:
14+
// - 1: Pull Request Number and URL
15+
// - 2: Changeset entry
16+
const RELEASE_LINE_REGEX = /^- (\[#.*?\]\(.*?\))?.*?! - (.*)$/gm;
17+
18+
// Captures X.Y.Z or X.Y.Z-rc.W
19+
const VERSION_TITLE_REGEX = /^## (\d+\.\d+\.\d+(-rc\.\d+)?)$/gm;
20+
21+
const formatted = changelog
22+
// Remove titles
23+
.replace(/^### Major Changes\n\n/gm, '')
24+
.replace(/^### Minor Changes\n\n/gm, '')
25+
.replace(/^### Patch Changes\n\n/gm, '')
26+
// Remove extra whitespace between items
27+
.replace(/^(- \[.*\n)\n(?=-)/gm, '$1')
28+
// Format each release line
29+
.replace(RELEASE_LINE_REGEX, (_, pr, entry) => (pr ? `- ${entry} (${pr})` : `- ${entry}`))
30+
// Add date to new version
31+
.replace(VERSION_TITLE_REGEX, `\n## $1 (${new Date().toISOString().split('T')[0]})`);
32+
33+
writeFileSync(changelogPath, formatted);
34+
}
35+
36+
formatChangelog('.');

scripts/release/publish.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
yarn install --frozen-lockfile
6+
changeset publish
7+
git push --follow-tags

scripts/release/version.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
changeset version
6+
7+
node scripts/release/format-changelog.js

0 commit comments

Comments
 (0)