-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add workflow to prepare a release PR #1816
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||
| name: Prepare release | ||||||
|
|
||||||
| on: | ||||||
| workflow_dispatch: | ||||||
| inputs: | ||||||
| bump: | ||||||
| description: Version bump type | ||||||
| required: true | ||||||
| type: choice | ||||||
| options: | ||||||
| - patch | ||||||
| - minor | ||||||
| - major | ||||||
|
|
||||||
| jobs: | ||||||
| prepare: | ||||||
| name: Bump version and open release PR | ||||||
| runs-on: ubuntu-latest | ||||||
| permissions: | ||||||
| contents: write # push release branch | ||||||
| pull-requests: write # open draft PR | ||||||
| steps: | ||||||
| - uses: actions/checkout@v6 | ||||||
| with: | ||||||
| fetch-depth: 0 # required to reach tag history | ||||||
|
|
||||||
| - uses: ruby/setup-ruby@v1 | ||||||
| with: | ||||||
| ruby-version: "3.3" | ||||||
|
|
||||||
| - name: Bump version | ||||||
| id: version | ||||||
| run: | | ||||||
| gem install gem-release --no-document | ||||||
| gem bump --version ${{ inputs.bump }} --no-commit | ||||||
| NEW=$(ruby -e "require_relative 'lib/factory_bot/version'; puts FactoryBot::VERSION") | ||||||
| echo "new=$NEW" >> "$GITHUB_OUTPUT" | ||||||
|
|
||||||
| - name: Update NEWS.md | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: bundle exec rake "release:update_changelog[${{ steps.version.outputs.new }}]" | ||||||
|
|
||||||
| - name: Push branch and open draft PR | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| NEW_VERSION: ${{ steps.version.outputs.new }} | ||||||
| run: | | ||||||
| BRANCH="release/v$NEW_VERSION" | ||||||
|
||||||
| BRANCH="release/v$NEW_VERSION" | |
| BRANCH="release-$NEW_VERSION" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require "date" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require "json" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace :release do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| desc "Update NEWS.md with merged PRs since the last release tag. Usage: rake release:update_changelog[VERSION]" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task :update_changelog, [:version] do |_, args| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| version = args.fetch(:version) { abort "Usage: rake release:update_changelog[VERSION]" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Find the last release tag and when it was made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| last_tag = `git tag --sort=-version:refname`.split.grep(/^v?[0-9]/).first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| since_date = `git log -1 --format=%as #{last_tag}`.strip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+12
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| desc "Update NEWS.md with merged PRs since the last release tag. Usage: rake release:update_changelog[VERSION]" | |
| task :update_changelog, [:version] do |_, args| | |
| version = args.fetch(:version) { abort "Usage: rake release:update_changelog[VERSION]" } | |
| # Find the last release tag and when it was made | |
| last_tag = `git tag --sort=-version:refname`.split.grep(/^v?[0-9]/).first | |
| since_date = `git log -1 --format=%as #{last_tag}`.strip | |
| desc "Update NEWS.md with merged PRs since the last release tag. Usage: rake release:update_changelog[VERSION[,TAG[,SINCE]]]" | |
| task :update_changelog, [:version, :tag, :since] do |_, args| | |
| version = args.fetch(:version) { abort "Usage: rake release:update_changelog[VERSION[,TAG[,SINCE]]]" } | |
| # Determine the changelog start date from an explicit date, an explicit tag, or the last release tag | |
| since_date = | |
| if args[:since] && !args[:since].strip.empty? | |
| args[:since].strip | |
| else | |
| last_tag = if args[:tag] && !args[:tag].strip.empty? | |
| args[:tag].strip | |
| else | |
| `git tag --sort=-version:refname`.split.grep(/^v?[0-9]/).first | |
| end | |
| abort "No release tag found matching ^v?[0-9]. Provide TAG or SINCE explicitly: rake release:update_changelog[VERSION[,TAG[,SINCE]]]" unless last_tag | |
| `git log -1 --format=%as #{last_tag}`.strip | |
| end |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ## Unreleased extraction/removal regex only matches when another ## ... header follows. If ## Unreleased is the last section in NEWS.md, it won’t be merged/removed. Consider extending the regex to also match end-of-file so this works regardless of section ordering.
| if news =~ /^## Unreleased\n(.*?)(?=^## )/m | |
| unreleased = $1.strip | |
| news = news.sub(/^## Unreleased\n.*?(?=^## )/m, "") | |
| if news =~ /^## Unreleased\n(.*?)(?=^## |\z)/m | |
| unreleased = $1.strip | |
| news = news.sub(/^## Unreleased\n.*?(?=^## |\z)/m, "") |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sub! will return nil if the # News header pattern isn’t found, but the task will still write the file and print success. Consider checking the return value and aborting with a helpful error when the expected header isn’t present, to avoid silently producing no changelog update.
| news.sub!(/^(# News\n+)/, "\\1#{new_section}\n") | |
| unless news.sub!(/^(# News\n+)/, "\\1#{new_section}\n") | |
| abort 'Expected NEWS.md to contain a "# News" header so the changelog entry could be inserted.' | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow runs
bundle exec rake ...but never installs the bundle. Unlike.github/workflows/build.yml, there’s nobundle install(orbundler-cache: true), so this step will fail on a fresh runner. Add a dependency install step before invokingbundle exec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a
bundle installstep betweenruby/setup-rubyand thebundle exec rakecall, matching the pattern used inbuild.yml. Fixed in 5d61d82.