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

build: use release-it to generate release data #817

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Nov 14, 2024

Current way of generating release info at build time to be included in the app has several issues:

  • Error prone: recurrent errors about local branch being behind of remote one. That's a hard-coded check in Semantic Release that can't be disabled right now. It happens many times. For instance, if two commits are pushed to main at same time, then the first one will report this error. As when building, will run semantic release to generate the release data to embed in the app. And the error will appear. A workaround could be to only allow 1 build process at a time in main branch. However, it may also happen on PRs. Like when pushing two commits within a very short interval of time. For same reason. Or if a PR is opened whose base is not the latest commit on main. It's a nice check when performing the release, but should be nice to be able to disable it when just generating release data (version to release / changelog) at build time.
  • Slow: due to some hard-coded git checks that can't be disabled right now, every run of semantic release takes 20s locally. A run of semantic release is done before building the app in order to generate the release data to embed into the app. Indeed, two may be needed if detecting that no release is needed: to generate a fake patch one to embed that (fake) release data. So 20s or 40s for a build just for running semantic release.
  • Fake releases: Semantic Release does not allow to just know if a release will happen or not based on the last commits. So a full release process needs to be done to know that. Then, if no release is happening, there's no way to get unreleased changes. Or to get the last release changelog. So the workaround for now is to generate a patch release to see what would happen on next release. And use that as release information to embed into the app.
  • Can't run on commit with tag. If running the script to generate the release information on an already-released/tagged commit, nothing can be done with Semantic Release to replicate what happened at that point in time. So version is grabbed from git, commit too and notes are be empty.
  • Typescript definitions: are not very exhaustive so there is lots of code regarding those. Could be nice to open a PR so those do not live here.

In order to solve limitations of Semantic Release, release-it is introduced for the same task. Though for now, only generates a JSON file with release information that is embedded into the app. It's quite fast compared to Semantic Release, 1-2s for the dry-run release process.

Also, it allows (with some options and a bit of hacky tricks) to generate the CHANGELOG.md for the latest release. So the process can be simplified to:

  • If a release will happen, embed that release info: commit SHA, version and CHANGELOG
  • If no release will happen, embed last release info and a list of unreleased changes.

It's not perfect, though:

  • Requires custom logic for version bumping. Not every commit will generate a release. Like style or refactor or docs ones. But a release is always generated by default. So needs custom logic to know which next version to bump (which is actually the main purpose of the conventional changelog plugin). But that's an issue in the upstream Conventional Changelog tooling repository. Where a patch version is always released if no features or breaking changes are found.
  • Some Typescript definitions are missing/incorrect. Could issue a PR for that though.
  • CHANGELOG files generated need some hacking:
    • For unreleased changes, requires tweaking header name and compare link
    • For last release CHANGELOG, requires removing the unreleased changes and fixing the compare link

Script to generate release file is reduced from 280+ lines to barely 100! Yay 🎉

Tested it can also generate release info when a tag exists for current commit

Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @davidlj95 and the rest of your teammates on Graphite Graphite

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.63%. Comparing base (a43f4ea) to head (f0b026c).
Report is 1 commits behind head on main.

Current head f0b026c differs from pull request most recent head a38c57e

Please upload reports for the commit a38c57e to get more accurate results.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #817   +/-   ##
=======================================
  Coverage   95.63%   95.63%           
=======================================
  Files         124      124           
  Lines         642      642           
  Branches       81       81           
=======================================
  Hits          614      614           
  Misses         20       20           
  Partials        8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidlj95 davidlj95 force-pushed the stacked/release-refactor branch 4 times, most recently from aa7a9a6 to 35cf094 Compare November 14, 2024 02:04
@davidlj95 davidlj95 force-pushed the stacked/release-refactor branch from 35cf094 to f0b026c Compare November 14, 2024 02:23
@davidlj95 davidlj95 force-pushed the stacked/release-refactor branch from f0b026c to a38c57e Compare November 14, 2024 02:28
@davidlj95 davidlj95 merged commit c9cd9f5 into main Nov 14, 2024
16 checks passed
@davidlj95 davidlj95 deleted the stacked/release-refactor branch November 14, 2024 02:32
Copy link

🚀 This pull request is included in v2.62.2. See v2.62.2 for release notes.

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.

1 participant