Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "OpenZeppelin/openzeppelin-upgrades"
}
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: yarn

- name: Install dependencies
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Changeset

on:
pull_request:
branches:
- master
types:
- opened
- synchronize
- labeled
- unlabeled

concurrency:
group: changeset-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ignore-changeset') }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
with:
fetch-depth: 0 # Include history so Changesets finds merge-base
- name: Set up environment
uses: ./.github/actions/setup
- name: Check changeset
run: npx changeset status --since=origin/${{ github.base_ref }}
44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Packages

on:
workflow_dispatch:

concurrency: version-or-publish-${{ github.ref }}

jobs:
publish:
name: Publish Packages
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
environment: publish
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
with:
fetch-depth: 0 # To get all tags
ref: ${{ github.ref }}
- name: Set up environment
uses: ./.github/actions/setup
- name: Create Prepare Release PR or Publish
id: changesets
uses: changesets/action@001cd79f0a536e733315164543a727bdf2d70aff # v1.5.1
with:
title: Prepare Release
commit: Prepare Release
version: npm run version
publish: npm run publish
commitMode: github-api
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference making comment to enable config provenance when pushing

Copy link
Member Author

@ericglau ericglau May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding link to related comment for tracking: OpenZeppelin/contracts-wizard#528 (comment)

- name: Check changesets status
if: steps.changesets.outputs.hasChangesets == 'true'
run: |
echo "Changesets found. Merge Prepare Release PR before publishing."
exit 1
- name: Check publish status
if: steps.changesets.outputs.published == 'false'
run: |
echo "Publish failed. Check the logs for more details."
exit 1
34 changes: 34 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Version Packages

on:
push:
branches:
- master
paths-ignore:
- 'docs/**'

concurrency: version-or-publish-${{ github.ref }}

jobs:
version:
name: Prepare Release PR
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
with:
fetch-depth: 0 # To get all tags
ref: ${{ github.ref }}
- name: Set up environment
uses: ./.github/actions/setup
- name: Create Prepare Release PR
uses: changesets/action@001cd79f0a536e733315164543a727bdf2d70aff # v1.5.1
with:
title: Prepare Release
commit: Prepare Release
version: npm run version
commitMode: github-api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this specifically for signing commits or any other advantages over cli?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, according to the Changesets changelog,

When used with "github-api" value all tags and commits will be attributed to the user whose GITHUB_TOKEN is used, and also signed using GitHub's internal GPG key.

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ If linting errors or warnings occur, run `yarn lint --fix` to attempt to auto-fi

As a contributor, we ask that you fork this repository, work on your own fork and then submit pull requests. The pull requests will be reviewed and eventually merged into the main repo. See ["Fork-a-Repo"](https://help.github.com/articles/fork-a-repo/) for how this works.

### Adding Changesets
If your PR modifies code under `packages`, you will need to add a changeset to summarize the changes. The PR's `Changeset` GitHub check will give an error if this condition is not satisfied.
- To add a changeset: from the root directory, run `yarn changeset`
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"lint": "yarn lint:path .",
"lint:path": "eslint --ignore-path .gitignore --max-warnings 0",
"test": "wsrun -ms test",
"coverage": "nyc yarn test"
"coverage": "nyc yarn test",
"version": "bash scripts/release/version.sh",
"publish": "bash scripts/release/publish.sh"
},
"devDependencies": {
"@openzeppelin/docs-utils": "^0.1.0",
Expand All @@ -24,7 +26,9 @@
"nyc": "^17.0.0",
"prettier": "^3.0.0",
"typescript": "^5.0.0",
"wsrun": "^5.2.4"
"wsrun": "^5.2.4",
"@changesets/cli": "^2.29.3",
"@changesets/changelog-github": "^0.5.1"
},
"workspaces": {
"packages": [
Expand Down
5 changes: 2 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@openzeppelin/upgrades-core",
"version": "1.44.0",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades",
"license": "MIT",
"main": "dist/index.js",
"files": [
Expand Down Expand Up @@ -38,7 +38,6 @@
"test": "ava",
"test:update-snapshots": "yarn test --update-snapshots",
"test:watch": "hardhat compile --force && yarn copyfiles && fgbg 'ava --watch' 'tsc -b --watch' --",
"version": "node ../../scripts/bump-changelog.js",
"cli": "node ./dist/cli/cli.js"
},
"bin": {
Expand All @@ -52,7 +51,7 @@
"@types/debug": "^4.1.5",
"@types/minimist": "^1.2.5",
"@types/mocha": "^7.0.2",
"@types/node": "^16.11.7",
"@types/node": "^20.0.0",
"@types/proper-lockfile": "^4.1.1",
"@types/sinon": "^17.0.0",
"ava": "^6.0.0",
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@openzeppelin/hardhat-upgrades",
"version": "3.9.0",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/plugin-hardhat",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades",
"license": "MIT",
"main": "dist/index.js",
"files": [
Expand All @@ -15,10 +15,9 @@
"scripts": {
"clean": "rimraf dist *.tsbuildinfo",
"compile": "tsc -b",
"prepare": "yarn clean && yarn compile",
"prepare": "yarn compile",
"test": "tsc -b && bash scripts/test.sh",
"test:watch": "fgbg 'bash scripts/test.sh --watch' 'tsc -b --watch' --",
"version": "node ../../scripts/bump-changelog.js"
"test:watch": "fgbg 'bash scripts/test.sh --watch' 'tsc -b --watch' --"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.5",
Expand Down
19 changes: 0 additions & 19 deletions scripts/bump-changelog.js

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/release/format-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

// Adjusts the format of the changelog that changesets generates.

const { readFileSync, writeFileSync } = require('fs');
const { join } = require('path');

function formatChangelog(dir) {
const changelogPath = join(dir, 'CHANGELOG.md');

const changelog = readFileSync(changelogPath, 'utf8');

// Groups:
// - 1: Pull Request Number and URL
// - 2: Changeset entry
const RELEASE_LINE_REGEX = /^- (\[#.*?\]\(.*?\))?.*?! - (.*)$/gm;

// Captures X.Y.Z or X.Y.Z-rc.W
const VERSION_TITLE_REGEX = /^## (\d+\.\d+\.\d+(-rc\.\d+)?)$/gm;

const formatted = changelog
// Remove titles
.replace(/^### Major Changes\n\n/gm, '')
.replace(/^### Minor Changes\n\n/gm, '')
.replace(/^### Patch Changes\n\n/gm, '')
// Remove extra whitespace between items
.replace(/^(- \[.*\n)\n(?=-)/gm, '$1')
// Format each release line
.replace(RELEASE_LINE_REGEX, (_, pr, entry) => (pr ? `- ${entry} (${pr})` : `- ${entry}`))
// Add date to new version
.replace(VERSION_TITLE_REGEX, `\n## $1 (${new Date().toISOString().split('T')[0]})`);

writeFileSync(changelogPath, formatted);
}

const packageFolders = ['core', 'plugin-hardhat'];
for (const folder of packageFolders) {
console.log(`Formatting changelog for ${folder}...`);
const packageDir = join('./packages', folder);
formatChangelog(packageDir);
}
7 changes: 7 additions & 0 deletions scripts/release/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

yarn install --frozen-lockfile
changeset publish
git push --follow-tags
7 changes: 7 additions & 0 deletions scripts/release/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

changeset version

node scripts/release/format-changelog.js
Loading