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

Automate release process via Changesets #3915

Merged
merged 84 commits into from Jan 18, 2023

Conversation

ernestognw
Copy link
Member

@ernestognw ernestognw commented Jan 3, 2023

Description

This PR is aiming to automate the release process by adding the following changes:

Tasks

  • Add Changesets Configuration for CHANGELOG.md management
  • Use Changeset Action for automating Release Pull Requests
  • Post-processing for the CHANGELOG.md, so it aligns with our current format (changesets don't fully support customization)
  • A Github Actions Workflow for the release cycle that reacts to the current state of a release branch
  • An Isolated GitHub Action for publishing to NPM
  • A Github Action to detect when a Pull Request doesn't include a Changeset
  • An action to Open a Pull Request back to master and merging changesets history after cherry picks
  • Convert Unreleased changes to Changesets
  • Test complete workflow in a fork of OpenZeppelin Contracts (requires publishing)

Release Cycle

stateDiagram-v2
	a: master
	b1: Unreleased Prerelease
	b2: Ready Prerelease
	c1: Ready Final Release
	c2: Patched Final Release 

	prerelease: Release Candidate
	state prerelease {
	  b1 --> b2: Merge Changesets PR
    b2 --> b1: Cherry pick fix from master
  }

 	release: Final Release
  state release {
    c1 --> c2 : Merge Changesets PR
    c2 --> c1 : Cherry pick patch from master
  }
	
	a --> b1 : Manual Dispatch
	b2 --> c1 : Manual Dispatch

	note left of prerelease
		Publish each ready prerelease as a release candidate
  end note

  note left of release
		Publish each ready release as patch
  end note

Required Changes

In order to implement the automation, it was needed to first adapt some things:

  • Adapt CHANGELOG.md format to use prettier (that's the default for changesets)
  • Add missing dates to CHANGELOG.md so the new format-changelog.js script doesn't override them
  • Update PULL_REQUEST_TEMPLATE.md to use changesets
  • Remove git interactions from npm run version, now the Changesets PR adds them all to a PR

TODO before merging

Since this Pull Request interacts with some GitHub repository settings, it's needed to first configure the following:

  • Add an npm environment
    • Should include NPM_TOKEN variable
    • Should include reviewers
  • Configure changesets bot

Open Questions

  • The Changeset Action doesn't include an input to override description, which is returning the full CHANGELOG.md due to the post-processing we do in format-changelog.js
  • The Release Cycle workflow creates a Github Release but it requires a Changelog section, and I'm not sure how to pick it up

@ernestognw ernestognw changed the title Changesets Add Changesets Jan 3, 2023
@ernestognw ernestognw marked this pull request as draft January 3, 2023 02:12
@ernestognw ernestognw changed the title Add Changesets Automate release process via Changesets Jan 3, 2023
@ernestognw ernestognw force-pushed the changesets branch 2 times, most recently from caa863c to 8a9e2a1 Compare January 3, 2023 18:23
@ernestognw ernestognw marked this pull request as ready for review January 10, 2023 19:54
@ernestognw ernestognw force-pushed the changesets branch 2 times, most recently from 730019d to f5b403d Compare January 13, 2023 15:48
CHANGELOG.md Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
scripts/release/version.sh Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
scripts/release/format-changelog.js Outdated Show resolved Hide resolved
@ernestognw
Copy link
Member Author

@frangio I took your RegExp comments with some small modifications, you can review it again but I wouldn't suggest that since there are a few things to consider:

  1. Each replace line modifies the content of the Changelog, some regex may affect other's inputs
  2. Each replace line MUST NOT modify old content, so we have to be careful on putting expressions that might match previous releases (that's why relying on \[.)
  3. A line of content interacts with more than other lines (eg. matching ^(- .*\n)\n(?=-)/mg doesn't match if a title is below that particular line, also consider minor/major/patch lines should be removed first in that case)

I tested with multiple files I have in the history of this PR and it works fine, but I don't want to focus on hyper optimize this RegEx since it may break discoveries I made in the past while testing.

scripts/release/format-changelog.js Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
scripts/release/workflow/publish.sh Outdated Show resolved Hide resolved
scripts/release/workflow/publish.sh Outdated Show resolved Hide resolved
scripts/release/workflow/publish.sh Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
.github/workflows/release-cycle.yml Outdated Show resolved Hide resolved
scripts/release/workflow/publish.sh Outdated Show resolved Hide resolved
scripts/release/workflow/publish.sh Outdated Show resolved Hide resolved
scripts/release/workflow/prepare-release-merge.sh Outdated Show resolved Hide resolved
scripts/release/workflow/pack.sh Outdated Show resolved Hide resolved
scripts/release/workflow/pack.sh Outdated Show resolved Hide resolved
scripts/release/workflow/pack.sh Outdated Show resolved Hide resolved
scripts/release/workflow/pack.sh Outdated Show resolved Hide resolved
scripts/release/workflow/github-release.js Outdated Show resolved Hide resolved
frangio
frangio previously approved these changes Jan 18, 2023
scripts/release/workflow/prepare-release-merge.sh Outdated Show resolved Hide resolved
scripts/release/workflow/prepare-release-merge.sh Outdated Show resolved Hide resolved
scripts/release/workflow/prepare-release-merge.sh Outdated Show resolved Hide resolved
scripts/release/workflow/pack.sh Outdated Show resolved Hide resolved
@frangio frangio self-requested a review January 18, 2023 21:00
@frangio frangio dismissed their stale review January 18, 2023 21:01

Pending changes


changesets:
needs: state
name: Changesets PR
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: Changesets PR
name: Update PR to release


merge:
needs: state
name: Release PR back to master
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: Release PR back to master
name: Create PR back to master

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Looks good!

@frangio frangio merged commit 0c89a8b into OpenZeppelin:master Jan 18, 2023
@gitpoap-bot
Copy link

gitpoap-bot bot commented Jan 18, 2023

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2023 OpenZeppelin Contracts Contributor:

GitPOAP: 2023 OpenZeppelin Contracts Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@Balmasexy

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants