Skip to content

Fix version calculation in update_protected_branches

Steve Abrams requested to merge fix-update-protected-branches into master

What does this MR do and why?

This fixes the logic that determines the branches to protect and unprotect in the UpdateProtectedBranches class that was implemented in !2547 (merged).

I noticed in testing a subsequent MR that the branches were not getting calculated correctly. You can see in this job: https://ops.gitlab.net/gitlab-org/release/tools/-/jobs/10897685 the same branch 16-2-stable is being listed for being protected and being unprotected:

2023-08-14 19:44:25.456262 I ReleaseTools::Monthly::Finalize::UpdateProtectedBranches -- Unprotecting previous stable branch -- {:branch=>"16-2-stable-ee", :project=>gitlab-org/gitlab}
2023-08-14 19:44:25.487648 I ReleaseTools::Monthly::Finalize::UpdateProtectedBranches -- Protecting new stable branch -- {:branch=>"16-2-stable-ee", :project=>gitlab-org/gitlab}
2023-08-14 19:44:25.525228 I ReleaseTools::Monthly::Finalize::UpdateProtectedBranches -- Unprotecting previous stable branch -- {:branch=>"16-2-stable", :project=>gitlab-org/omnibus-gitlab}
2023-08-14 19:44:25.560309 I ReleaseTools::Monthly::Finalize::UpdateProtectedBranches -- Protecting new stable branch -- {:branch=>"16-2-stable", :project=>gitlab-org/omnibus-gitlab}

That is because the logic calculating #new_branch and #old_branch will always return the same version.

To fix this, we think about when this is going to run. We are going to run it after the new stable branch has been created, but before we've created the version on version.gitlab.com.

So for example, right now, we are getting ready to release the 16.3 version. After we have published, this service will run before we have added that version to versions.gitlab.com. So when this service runs, ReleaseTools::Versions.current.first will return 16.2.0 (for reference ReleaseTools::Versions.next_versions.first would return 16.2.X). That means, we want that version to be the source of our old_branch.

To get 16.3, we need to calculate the next minor version after that one, which can be done with ReleaseTools::Version.new(ReleaseTools::Versions.current.first).next_minor. That is what we do in this MR.

Here it is working in the ruby console:

[17] pry(main)> current_version = ReleaseTools::Version.new(ReleaseTools::Versions.current.first)
=> "16.2.4"
[18] pry(main)> old_branch = current_version.stable_branch(ee: true)
=> "16-2-stable-ee"
[19] pry(main)> new_branch = ReleaseTools::Version.new(current_version.next_minor).stable_branch(ee: true)
=> "16-3-stable-ee"

Related to gitlab-com/gl-infra/delivery#19546 (closed)

Author Check-list

  • [-] Has documentation been updated?
Edited by Steve Abrams

Merge request reports