Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: filter by range with semver#1445

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
cchanche wants to merge9 commits intorelease-drafter:master
base:master
Choose a base branch
Loading
fromcchanche:feat/filter-by-range

Conversation

@cchanche
Copy link

@cchanchecchanche commentedJun 5, 2025
edited
Loading

Filter by range (semver)

Checklist

Content

👉 Filter releases that satisfies a semver range.

When looking for previous releases in the repository,release-drafter currently offers two filtering options :

  • filter-by-commitish
    • consider releases that have a particulartarget-commitish (ex:main orrefs/heads/main)
  • tag-prefix
    • consider releases that have a particular prefix in theirtag-name (ex:sub-package/*)
    • more than a filter : also strips the prefix when parsing and computing versions for the upcoming tag

✨ This pull request adds another filter :

  • filter-by-range
    • consider releases based on theirtag-name, which should satisfy a given semver range

How does it work

When deciding whether to update an existing release or creating a new one, thefindReleases function oflib/releases.js is responsible for returning the latest release as well as a potentially already-existing one (drafted).

This is done by :

  1. fetching every existing releases
  2. filtering those we want to consider for the currentrelease-drafter run
  3. Finding-out which are draft-releases, and which is the latest.

This PR introduces a new filter in step 2. :

releases.filter((r)=>{constparsedRange=semver.validRange(filterByRange)// Already validated in schema.jsconstparsedVersion=semver.coerce(r.tag_name).version// coerce() strips prefixesreturnsemver.satisfies(parsedVersion,parsedRange)})

Motivations

My use-case is to be able to implement strictTrunk Based Development, in particular the proposal aboutrelease branches.

When publishing a release on themain branch (thetrunk), for instancev1.2.0. The target-commitish would bemain (orrefs/heads/main, ormaster etc...).

Based-off that tag, arelease/v1.2 branch would be created, such as hotfixes for that particular produciton release might be easily pushed and deployed. A hotfix-deployment would be triggerd through another published release on the release-branch (ex:v1.2.1), with a target-commitish ofrelease/v1.2.

Since we want every release to be drafted before-hand, an automation such asrealease-drafter comes very handy ! However, it currently cannot create draft-releases for bothmain andrelease/vx.x branchessimultaneously. Filtering withfilter-by-commitish fails to retrievev1.2.0 onmain when drafting forv1.2.1 onrelease/v1.2.

Using this PR's feature, one would just have to specifyfilter-by-range: ~1.2.0 on draft-releases for hotfixes (on the 1.2 release branch).

For releases to contain relevant informations in the context ofTrunk Based Development,release-drafter should also be able to add individual commits it's release body. (see#1409) This is because the method encourages devs to all work on the same branch, especially for hotfixes onrelease/ branches.

A simple empty draft (when no PR were pushed), however, is already a big leap towardsrelease-drafter being usable with release branches.

Example

Input is :filter-by-range: ~1.1.0

Release drafter correctly identifies I want to publish a hotfix onrelease/v1.1 by filtering out whatever is not in the~1.1.0 range (1.2.x,1.0.x and0.0.x etc...).

It correctly identifiesv1.1.2 as thelatest release, and published a new draft (forv1.1.3 mot likely), even though a draft might already exist for the upcomingv2.1.0 release.

my-repo/test: Found 14 releases##[debug]Parsing raw range "~1.1.0" as ">=1.1.0 <1.2.0-0"##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "2.0.0"##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "1.2.1"##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "1.2.0" ##[debug]Range ">=1.1.0 <1.2.0-0" satisfies version "1.1.2" ##[debug]Range ">=1.1.0 <1.2.0-0" satisfies version "1.1.1" ##[debug]Range ">=1.1.0 <1.2.0-0" satisfies version "1.1.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "1.0.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.6.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.5.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.4.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.3.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.2.1" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.2.0" ##[debug]Range ">=1.1.0 <1.2.0-0" does not satisfy version "0.1.0" my-repo/test: No draft release foundmy-repo/test: Last release: v1.1.2

Integrating the whole thing in your trunk-based repo is as simple as :

# .github/workflows/release-drafter.hotfix.ymlname:Draft a release for hotfix (release/** branches)on:push:branches:      -"release/**"# ...steps:      -name:Get current tag# For release/v2.9.0, outputs number=2.9.0id:tagrun:|          branch_name="${{ github.ref_name }}"          tag_number="${branch_name/release\/v/""}"          echo "number=$tag_number" >> $GITHUB_OUTPUT          -name:Release drafteruses:cchanche/release-drafter@f72495a3e1d4b4bae78779e99a84052334b6654bwith:filter-by-range:~${{ steps.tag.outputs.number }}# "~2.9.0" translates to ">=2.9.0 <2.10.0-0"commitish:${{ github.ref_name }}

commitish: ${{ github.ref_name }} was added for clarity, but is not needed since the workflow already runs on the correspondingrelease/** branch.

pierrot-lc and Nico2046 reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@cchanche

[8]ページ先頭

©2009-2025 Movatter.jp