decidim-maintainers_toolbox 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35c9637b473aa216da01007794b00cd0e78e0b0da6a650459d2c43120a14b7f8
4
- data.tar.gz: 97e639c0b23cb99625b0f433fb1d7251d379db3e1a7be6769830a2c66345112d
3
+ metadata.gz: 43c171108faecc38579f7d0854e502380744ea446074bc23c1e50a51dfc3fc1b
4
+ data.tar.gz: 9d58cc373d319f370cddc0091bd28c7f4ce0d834aa872982463eb04288946407
5
5
  SHA512:
6
- metadata.gz: 943e69599eef14d70effed56fdce8cb33ecac56c220083f67a222e8dea21e995feefec027a386fec776098a3ab73836dbe53f4957d1a0f34bed44f10e4972ee7
7
- data.tar.gz: 3b4825382099f593179ce14eb31379dd640ede7d8f7c82d2157bdf8167f33ecaadd4b59f8f0f6dbdd90875a2771388b50afda5247ec5d9bf7d3ba6c70e628b23
6
+ metadata.gz: e58090d00b14fa68575e707174f9b509ec3b608cfc15ac4e57c76b6118e7bf03a7709a0e800f3d58ec7d40d349ed19be10cf2f7236125de950bcd414253c7f6c
7
+ data.tar.gz: 56eb19a35080737611395e5ffa24401c0d6de18df612138ba73a85393f835d725462c3e8705e3358c815475fed3c54103d773c9c7fcaf52ebc0479f732c33c80
@@ -65,7 +65,7 @@ module Decidim
65
65
 
66
66
  pull_request_metadata[:labels].map do |item|
67
67
  item.match(/release: v(\d+\.\d+)/) { |m| m[1] }
68
- end.compact
68
+ end.compact.reverse
69
69
  end
70
70
 
71
71
  # Asks the metadata for a given issue or pull request on GitHub API
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "base"
4
+ require "active_support/core_ext/object/blank"
4
5
 
5
6
  module Decidim
6
7
  module MaintainersToolbox
@@ -0,0 +1,335 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "changelog_generator"
4
+ require_relative "releaser_utils"
5
+ require_relative "github_manager/poster"
6
+
7
+ module Decidim
8
+ module MaintainersToolbox
9
+ # Creates a release candidate version for this branch
10
+ #
11
+ # If we are in develop (i.e. v0.30.0.dev) it will create the rc1 (i.e. v0.30.0.rc1)
12
+ # If we are in the stable release with an rc (i.e. v0.30.0.rc1) it will create the next rc (i.e. v0.30.0.rc2)
13
+ # If we are in the stable release with a patch (i.e. v0.30.0) it will bail out
14
+ class ReleaseCandidateVersion
15
+ include Decidim::MaintainersToolbox::ReleaserUtils
16
+
17
+ # @param token [String] token for GitHub authentication
18
+ # @param working_dir [String] current working directory. Useful for testing purposes
19
+ def initialize(token:, working_dir: Dir.pwd)
20
+ @token = token
21
+ @working_dir = working_dir
22
+ @old_version_number = old_version_number
23
+ end
24
+
25
+ def call
26
+ check_branch_and_version_sanity
27
+ check_tests
28
+
29
+ prepare_next_development_version
30
+ prepare_next_release_candidate_version
31
+ end
32
+
33
+ # The version number for the release that we are preparing
34
+ #
35
+ # @return [String] the version number
36
+ def version_number
37
+ @version_number ||= next_version_number_for_release_candidate(@old_version_number)
38
+ end
39
+
40
+ private
41
+
42
+ # Returns the next branch that needs to be created for the RC.
43
+ #
44
+ # @return [String]
45
+ def release_branch
46
+ @release_branch ||= begin
47
+ major, minor, _patch = parsed_version_number(version_number)
48
+
49
+ "release/#{major}.#{minor}-stable"
50
+ end
51
+ end
52
+
53
+ def check_branch_and_version_sanity
54
+ return if develop_branch? && dev_version_number?
55
+ return if release_branch? && rc_version_number?
56
+
57
+ error_message = <<-EOERROR
58
+ Check if the branch is valid for a release candidate. It should be:
59
+ - develop with a dev version (i.e. develop branch with 0.30.0.dev decidim version)
60
+ - stable branch with a release candidate version (i.e. release/0.30-stable branch with 0.30.rc1 decidim version)
61
+ EOERROR
62
+ exit_with_errors(error_message)
63
+ end
64
+
65
+ def develop_branch?
66
+ branch == "develop"
67
+ end
68
+
69
+ def dev_version_number?
70
+ @old_version_number.match? /dev$/
71
+ end
72
+
73
+ def release_branch?
74
+ branch.start_with?("release/")
75
+ end
76
+
77
+ def rc_version_number?
78
+ @old_version_number.match? /rc.$/
79
+ end
80
+
81
+ def prepare_next_development_version
82
+ return unless develop_branch? || dev_version_number?
83
+
84
+ run("git pull origin develop")
85
+
86
+ run("git checkout -b #{release_branch}")
87
+ run("git push origin #{release_branch}")
88
+
89
+ puts "*" * 80
90
+ puts "Create the stable branch in Crowdin and exit this shell to continue the release process"
91
+ puts "https://docs.decidim.org/en/develop/develop/maintainers/releases.html#_create_the_stable_branch_in_crowdin"
92
+ puts "*" * 80
93
+ system ENV.fetch("SHELL")
94
+
95
+ run("git checkout develop")
96
+
97
+ next_dev_version = next_version_number_for_dev(@old_version_number)
98
+ prepare_branch = "chore/prepare/#{next_dev_version}"
99
+ run("git checkout -b #{prepare_branch}")
100
+
101
+ bump_decidim_version(next_version_number_for_dev(@old_version_number))
102
+
103
+ run("bin/rake update_versions")
104
+ run("bin/rake patch_generators")
105
+ run("bin/rake bundle")
106
+ run("npm install")
107
+ run("bin/rake webpack") if Dir.exist?("decidim_app-design")
108
+
109
+ generate_empty_changelog
110
+ generate_empty_release_notes
111
+
112
+ run("git add .")
113
+ run("git commit -m 'Bump develop to next release version'")
114
+ run("git push origin #{prepare_branch}")
115
+
116
+ create_develop_pull_request(prepare_branch, next_dev_version)
117
+ end
118
+
119
+ def prepare_next_release_candidate_version
120
+ run("git checkout #{release_branch}")
121
+ run("git checkout -b chore/prepare/#{version_number}")
122
+
123
+ bump_decidim_version(version_number)
124
+
125
+ run("bin/rake update_versions")
126
+ run("bin/rake patch_generators")
127
+ run("bin/rake bundle")
128
+
129
+ run("npm install")
130
+ run("bin/rake webpack") if Dir.exist?("decidim_app-design")
131
+
132
+ generate_changelog
133
+
134
+ run("git add .")
135
+ run("git commit -m 'Bump to #{version_number} version'")
136
+ run("git push origin chore/prepare/#{version_number}")
137
+
138
+ create_pull_request
139
+
140
+ finish_message = <<~EOMESSAGE
141
+ Finished the release process
142
+ Next steps:
143
+
144
+ 1. Wait for the tests to finish and check that everything is passing before releasing the version.
145
+ NOTE: When you bump the version, the generator tests will fail because the gems and NPM packages
146
+ have not been actually published yet (as in sent to rubygems/npm). You may see errors such as
147
+ No matching version found for @decidim/browserslist-config@~0.xx.y in the CI logs. This should
148
+ be fine as long as you have ensured that the generators tests passed in the previous commit.
149
+ 2. Review and merge this PR
150
+ 3. Once that PR is merged, run the following commands to create the tags and push the gems to RubyGems and the packages to NPM:
151
+ > git pull
152
+ > bin/rake release_all
153
+ 4. Usually, at this point, the release branch is deployed to Metadecidim during, at least, one week to validate the stability of the version.
154
+ EOMESSAGE
155
+
156
+ puts "*" * 80
157
+ puts finish_message
158
+ end
159
+
160
+ # Given a version number, returns the next release candidate
161
+ #
162
+ # If the current version number is `dev`, then we return the `rc1` version
163
+ # If the current version number is `rc`, then we return the next `rc` version
164
+ # Else, it means is a `minor` or `patch` version. On those cases we raise an Exception, as releases candidates should
165
+ # be only done from a `dev` or a `rc` version.
166
+ #
167
+ # @raise [InvalidVersionTypeError]
168
+ #
169
+ # @param current_version_number [String] - The version number of the current version
170
+ #
171
+ # @return [String] - the new version number
172
+ def next_version_number_for_release_candidate(current_version_number)
173
+ if current_version_number.include? "dev"
174
+ major, minor, patch = parsed_version_number(current_version_number)
175
+ new_version_number = "#{major}.#{minor}.#{patch}.rc1"
176
+ elsif current_version_number.include? "rc"
177
+ new_rc_number = current_version_number.match(/rc(\d)/)[1].to_i + 1
178
+ new_version_number = current_version_number.gsub(/rc\d/, "rc#{new_rc_number}")
179
+ else
180
+ error_message = <<-EOMESSAGE
181
+ Trying to do a release candidate version from patch release. Bailing out.
182
+ You need to do a release candidate from a `dev` or from another `rc` version
183
+ EOMESSAGE
184
+ raise InvalidVersionTypeError, error_message
185
+ end
186
+
187
+ new_version_number
188
+ end
189
+
190
+ def next_version_number_for_dev(current_version_number)
191
+ major, minor, patch = parsed_version_number(current_version_number)
192
+
193
+ "#{major}.#{minor.to_i + 1}.#{patch}.dev"
194
+ end
195
+
196
+ def generate_empty_changelog
197
+ major, minor, patch = parsed_version_number(@old_version_number)
198
+
199
+ changelog_contents = <<-EOCHANGELOG
200
+ # Changelog
201
+
202
+ ## [Unreleased](https://github.com/decidim/decidim/tree/HEAD)
203
+
204
+ Nothing.
205
+
206
+ ...
207
+
208
+ ## Previous versions
209
+
210
+ Please check [#{major}.#{minor}-stable](https://github.com/decidim/decidim/blob/release/#{major}.#{minor}-stable/CHANGELOG.md) for previous changes.
211
+ EOCHANGELOG
212
+
213
+ File.write("CHANGELOG.md", changelog_contents)
214
+ end
215
+
216
+ def generate_empty_release_notes
217
+ release_notes_contents = <<-EORELEASE
218
+ # Release Notes
219
+
220
+ ## 1. Upgrade notes
221
+
222
+ NOTE: This is the draft for the releases notes. If you are an implementer or someone that is upgrading a Decidim installation, we recommend
223
+ checking out the last version of this document in the [GitHub page for the releases of this branch](https://github.com/decidim/decidim/releases/).
224
+
225
+ As usual, we recommend that you have a full backup, of the database, application code and static files.
226
+
227
+ To update, follow these steps:
228
+
229
+ ### 1.1. Update your ruby version
230
+
231
+ If you're using rbenv, this is done with the following commands:
232
+
233
+ ```console
234
+ rbenv install 3.x.x
235
+ rbenv local 3.x.x
236
+ ```
237
+
238
+ You may need to change your `.ruby-version` file too.
239
+
240
+ If not, you need to adapt it to your environment, for instance by changing the decidim docker image to use ruby:3.x.x.
241
+
242
+ ### 1.2. Update your Gemfile
243
+
244
+ ```ruby
245
+ gem "decidim", github: "decidim/decidim"
246
+ gem "decidim-dev", github: "decidim/decidim"
247
+ ```
248
+
249
+ ### 1.3. Run these commands
250
+
251
+ ```console
252
+ bundle update decidim
253
+ bin/rails decidim:upgrade
254
+ bin/rails db:migrate
255
+ ```
256
+
257
+ ### 1.4. Follow the steps and commands detailed in these notes
258
+
259
+ ## 2. General notes
260
+
261
+ ## 3. One time actions
262
+
263
+ These are one time actions that need to be done after the code is updated in the production database.
264
+
265
+ ### 3.1. [[TITLE OF THE ACTION]]
266
+
267
+ You can read more about this change on PR [#XXXX](https://github.com/decidim/decidim/pull/XXXX).
268
+
269
+ ## 4. Scheduled tasks
270
+
271
+ Implementers need to configure these changes it in your scheduler task system in the production server. We give the examples
272
+ with `crontab`, although alternatively you could use `whenever` gem or the scheduled jobs of your hosting provider.
273
+
274
+ ### 4.1. [[TITLE OF THE TASK]]
275
+
276
+ ```bash
277
+ 4 0 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rails decidim:TASK
278
+ ```
279
+
280
+ You can read more about this change on PR [#XXXX](https://github.com/decidim/decidim/pull/XXXX).
281
+
282
+ ## 5. Changes in APIs
283
+
284
+ ### 5.1. [[TITLE OF THE CHANGE]]
285
+
286
+ In order to [[REASONING (e.g. improve the maintenance of the code base)]] we have changed...
287
+
288
+ If you have used code as such:
289
+
290
+ ```ruby
291
+ # Explain the usage of the API as it was in the previous version
292
+ result = 1 + 1 if before
293
+ ```
294
+
295
+ You need to change it to:
296
+
297
+ ```ruby
298
+ # Explain the usage of the API as it is in the new version
299
+ result = 1 + 1 if after
300
+ ```
301
+ EORELEASE
302
+
303
+ File.write("RELEASE_NOTES.md", release_notes_contents)
304
+ end
305
+
306
+ # Creates the pull request for bumping the develop version
307
+ #
308
+ # @param head_branch [String] the branch that we want to merge to develop
309
+ # @param next_dev_version [String] the name of the next dev version (for instance 0.99.0.dev)
310
+ #
311
+ # @return [void]
312
+ def create_develop_pull_request(head_branch, next_dev_version)
313
+ base_branch = "develop"
314
+
315
+ params = {
316
+ title: "Bump develop to next release version (#{next_dev_version})",
317
+ body: "#### :tophat: What? Why?
318
+
319
+ This PR prepares the next develop version.
320
+
321
+ #### Testing
322
+
323
+ All the tests should pass
324
+
325
+ :hearts: Thank you!
326
+ ",
327
+ labels: ["type: internal"],
328
+ head: head_branch,
329
+ base: base_branch
330
+ }
331
+ Decidim::MaintainersToolbox::GithubManager::Poster.new(token: @token, params: params).call
332
+ end
333
+ end
334
+ end
335
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "releaser_utils"
4
+
5
+ module Decidim
6
+ module MaintainersToolbox
7
+ class ReleasePatchVersion
8
+ include Decidim::MaintainersToolbox::ReleaserUtils
9
+
10
+ # @param token [String] token for GitHub authentication
11
+ # @param working_dir [String] current working directory. Useful for testing purposes
12
+ def initialize(token:, working_dir: Dir.pwd)
13
+ @token = token
14
+ @working_dir = working_dir
15
+ end
16
+
17
+ def call
18
+ exit_unless_release_branch
19
+
20
+ prepare_next_patch_version
21
+ end
22
+
23
+ # The version number for the release that we are preparing
24
+ #
25
+ # @return [String] the version number
26
+ def version_number
27
+ @version_number ||= next_version_number_for_patch_release(old_version_number)
28
+ end
29
+
30
+ private
31
+
32
+ # Raise an error if the branch does not start with the preffix "release/"
33
+ # or returns the branch name
34
+ #
35
+ # @raise [InvalidBranchError]
36
+ #
37
+ # @return [String]
38
+ def release_branch
39
+ @release_branch ||= branch
40
+ end
41
+
42
+ def exit_unless_release_branch
43
+ return if branch.start_with?("release/")
44
+
45
+ error_message = <<-EOERROR
46
+ This is not a release branch, change to the release branch branch to run this script.
47
+ EOERROR
48
+ exit_with_errors(error_message)
49
+ end
50
+
51
+ def prepare_next_patch_version
52
+ run("git checkout #{release_branch}")
53
+ run("git pull origin #{release_branch}")
54
+
55
+ bump_decidim_version(version_number)
56
+ run("bin/rake update_versions")
57
+
58
+ run("bin/rake patch_generators")
59
+
60
+ run("bin/rake bundle")
61
+ run("npm install")
62
+ run("bin/rake webpack") if Dir.exist?("decidim_app-design")
63
+
64
+ check_tests
65
+
66
+ generate_changelog
67
+
68
+ run("git checkout -b chore/prepare/#{version_number}")
69
+ run("git commit -a -m 'Prepare #{version_number} release'")
70
+ run("git push origin chore/prepare/#{version_number}")
71
+
72
+ create_pull_request
73
+ end
74
+
75
+ # Given a version number, returns the next patch release
76
+ #
77
+ # If the current version number is `dev`, then we raise an Exception, as you need to first do a release candidate.
78
+ # If the current version number is `rc`, then we return the `0` patch version
79
+ # Else, it means is a `patch` version, so we return the next patch version
80
+ #
81
+ # @raise [InvalidVersionTypeError]
82
+ #
83
+ # @param current_version_number [String] - The version number of the current version
84
+ #
85
+ # @return [String] - the new version number
86
+ def next_version_number_for_patch_release(current_version_number)
87
+ major, minor, patch = parsed_version_number(current_version_number)
88
+
89
+ if current_version_number.include? "dev"
90
+ error_message = <<-EOMESSAGE
91
+ Trying to do a patch version from dev release. Bailing out.
92
+ You need to do first a release candidate.
93
+ EOMESSAGE
94
+ raise InvalidVersionTypeError, error_message
95
+ elsif current_version_number.include? "rc"
96
+ new_version_number = "#{major}.#{minor}.0"
97
+ else
98
+ new_version_number = "#{major}.#{minor}.#{patch.to_i + 1}"
99
+ end
100
+
101
+ new_version_number
102
+ end
103
+ end
104
+ end
105
+ end
@@ -1,20 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "open3"
4
- require_relative "github_manager/poster"
5
3
  require_relative "github_manager/querier/by_query"
6
- require_relative "changelog_generator"
4
+
5
+ require_relative "releaser_utils"
6
+ require_relative "release_candidate_version"
7
+ require_relative "release_patch_version"
7
8
 
8
9
  module Decidim
9
10
  module MaintainersToolbox
10
11
  class Releaser
11
12
  class InvalidMetadataError < StandardError; end
12
13
 
13
- class InvalidBranchError < StandardError; end
14
-
15
- class InvalidVersionTypeError < StandardError; end
16
-
17
- DECIDIM_VERSION_FILE = ".decidim-version"
14
+ include Decidim::MaintainersToolbox::ReleaserUtils
18
15
 
19
16
  # @param token [String] token for GitHub authentication
20
17
  # @param version_type [String] The kind of release that you want to prepare. Supported values: rc, minor, patch
@@ -32,223 +29,35 @@ module Decidim
32
29
  exit_if_unstaged_changes if @exit_with_unstaged_changes
33
30
  exit_if_pending_crowdin_pull_request
34
31
 
35
- puts "Starting the release process for #{version_number} in 10 seconds"
32
+ case @version_type
33
+ when "rc"
34
+ release = ReleaseCandidateVersion.new(token: @token, working_dir: @working_dir)
35
+ # Minor release process is the same as the Patch release process
36
+ when "minor"
37
+ release = ReleasePatchVersion.new(token: @token, working_dir: @working_dir)
38
+ when "patch"
39
+ release = ReleasePatchVersion.new(token: @token, working_dir: @working_dir)
40
+ else
41
+ raise InvalidVersionTypeError, "This is not a valid version type"
42
+ end
43
+
44
+ puts "Starting the release process for #{release.version_number} in 10 seconds"
36
45
  sleep 10
37
46
 
38
- run("git checkout #{release_branch}")
39
- run("git pull origin #{release_branch}")
40
-
41
- bump_decidim_version
42
- run("bin/rake update_versions")
43
-
44
- run("bin/rake patch_generators")
45
-
46
- run("bin/rake bundle")
47
- run("npm install")
48
- run("bin/rake webpack") if Dir.exist?("decidim_app-design")
49
-
50
- check_tests
51
-
52
- generate_changelog
53
-
54
- run("git checkout -b chore/prepare/#{version_number}")
55
- run("git commit -a -m 'Prepare #{version_number} release'")
56
- run("git push origin chore/prepare/#{version_number}")
57
-
58
- create_pull_request
47
+ release.call
59
48
  end
60
49
  end
61
50
 
62
51
  private
63
52
 
64
- # The git branch
65
- #
66
- # @return [String]
67
- def branch
68
- @branch ||= capture("git rev-parse --abbrev-ref HEAD")[0].strip
69
- end
70
-
71
- # Raise an error if the branch does not start with the preffix "release/"
72
- # or returns the branch name
73
- #
74
- # @raise [InvalidBranchError]
75
- #
76
- # @return [String]
77
- def release_branch
78
- raise InvalidBranchError, "This is not a release branch, aborting" unless branch.start_with?("release/")
79
-
80
- branch
81
- end
82
-
83
- # Changes the decidim version in the file
84
- #
85
- # @return [void]
86
- def bump_decidim_version
87
- File.write(DECIDIM_VERSION_FILE, version_number)
88
- end
89
-
90
- # The version number for the release that we are preparing
91
- #
92
- # @todo support the "minor" type version
93
- #
94
- # @return [String] the version number
95
- def version_number
96
- @version_number ||= case @version_type
97
- when "rc"
98
- next_version_number_for_release_candidate(old_version_number)
99
- when "patch"
100
- next_version_number_for_patch_release(old_version_number)
101
- else
102
- raise InvalidVersionTypeError, "This is not a supported version type"
103
- end
104
- end
105
-
106
- def parsed_version_number(version_number)
107
- /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/ =~ version_number
108
-
109
- [major.to_i, minor.to_i, patch.to_i]
110
- end
111
-
112
- # Given a version number, returns the next release candidate
113
- #
114
- # If the current version number is `dev`, then we return the `rc1` version
115
- # If the current version number is `rc`, then we return the next `rc` version
116
- # Else, it means is a `minor` or `patch` version. On those cases we raise an Exception, as releases candidates should
117
- # be only done from a `dev` or a `rc` version.
118
- #
119
- # @raise [InvalidVersionTypeError]
120
- #
121
- # @param current_version_number [String] - The version number of the current version
122
- #
123
- # @return [String] - the new version number
124
- def next_version_number_for_release_candidate(current_version_number)
125
- if current_version_number.include? "dev"
126
- major, minor, patch = parsed_version_number(current_version_number)
127
- new_version_number = "#{major}.#{minor}.#{patch}.rc1"
128
- elsif current_version_number.include? "rc"
129
- new_rc_number = current_version_number.match(/rc(\d)/)[1].to_i + 1
130
- new_version_number = current_version_number.gsub(/rc\d/, "rc#{new_rc_number}")
131
- else
132
- error_message = <<-EOMESSAGE
133
- Trying to do a release candidate version from patch release. Bailing out.
134
- You need to do a release candidate from a `dev` or from another `rc` version
135
- EOMESSAGE
136
- raise InvalidVersionTypeError, error_message
137
- end
138
-
139
- new_version_number
140
- end
141
-
142
- # Given a version number, returns the next patch release
143
- #
144
- # If the current version number is `dev`, then we raise an Exception, as you need to first do a release candidate.
145
- # If the current version number is `rc`, then we return the `0` patch version
146
- # Else, it means is a `patch` version, so we return the next patch version
147
- #
148
- # @raise [InvalidVersionTypeError]
149
- #
150
- # @param current_version_number [String] - The version number of the current version
151
- #
152
- # @return [String] - the new version number
153
- def next_version_number_for_patch_release(current_version_number)
154
- major, minor, patch = parsed_version_number(current_version_number)
155
-
156
- if current_version_number.include? "dev"
157
- error_message = <<-EOMESSAGE
158
- Trying to do a patch version from dev release. Bailing out.
159
- You need to do first a release candidate.
160
- EOMESSAGE
161
- raise InvalidVersionTypeError, error_message
162
- elsif current_version_number.include? "rc"
163
- new_version_number = "#{major}.#{minor}.0"
164
- else
165
- new_version_number = "#{major}.#{minor}.#{patch.to_i + 1}"
166
- end
167
-
168
- new_version_number
169
- end
170
-
171
- # The version number from the file
172
- #
173
- # @return [String] the version number
174
- def old_version_number
175
- File.read(DECIDIM_VERSION_FILE).strip
176
- end
177
-
178
- # Run the tests and if fails restore the changes using git and exit with an error
179
- #
180
- # @return [void]
181
- def check_tests
182
- puts "Running specs"
183
- output, status = capture("bundle exec rspec", env: { "ENFORCED_LOCALES" => "en,ca,es", "SKIP_NORMALIZATION" => "true" })
184
-
185
- unless status.success?
186
- run("git restore .")
187
- puts output
188
- exit_with_errors("Tests execution failed. Fix the errors and run again.")
189
- end
190
- end
191
-
192
- # Generates the changelog taking into account the last time the version changed
193
- #
194
- # @return [void]
195
- def generate_changelog
196
- sha_version = capture("git log -n 1 --pretty=format:%h -- .decidim-version")[0]
197
- ChangeLogGenerator.new(token: @token, since_sha: sha_version).call
198
- temporary_changelog = File.read("./temporary_changelog.md")
199
- legacy_changelog = File.read("./CHANGELOG.md")
200
- version_changelog = "## [#{version_number}](https://github.com/decidim/decidim/tree/#{version_number})\n\n#{temporary_changelog}\n"
201
- changelog = legacy_changelog.gsub("# Changelog\n\n", "# Changelog\n\n#{version_changelog}")
202
- File.write("./CHANGELOG.md", changelog)
203
- end
204
-
205
- # Creates the pull request for bumping the version
206
- #
207
- # @return [void]
208
- def create_pull_request
209
- base_branch = release_branch
210
- head_branch = "chore/prepare/#{version_number}"
211
-
212
- params = {
213
- title: "Bump to v#{version_number} version",
214
- body: "#### :tophat: What? Why?
215
-
216
- This PR changes the version of the #{release_branch} branch, so we can publish the release once this is approved and merged.
217
-
218
- #### Testing
219
-
220
- All the tests should pass, except for some generators tests, that will fail because the gems and NPM packages have not
221
- been actually published yet (as in sent to rubygems/npm).
222
- You will see errors such as `No matching version found for @decidim/browserslist-config@~0.xx.y` in the CI logs.
223
-
224
- :hearts: Thank you!
225
- ",
226
- labels: ["type: internal"],
227
- head: head_branch,
228
- base: base_branch
229
- }
230
- Decidim::MaintainersToolbox::GithubManager::Poster.new(token: @token, params: params).call
231
- end
232
-
233
- # Captures to output of a command
234
- #
235
- # @return [Array<String, Process::Status>] The stdout and stderr of the command and its status (aka error code)
236
- def capture(cmd, env: {})
237
- Open3.capture2e(env, cmd)
238
- end
239
-
240
- # Runs a command
241
- #
242
- # @return [void]
243
- def run(cmd, out: $stdout)
244
- system(cmd, out: out)
245
- end
246
-
247
53
  # Check if there is any open pull request from Crowdin in GitHub
248
54
  #
249
55
  # @return [Boolean] - true if there is any open PR
250
56
  def pending_crowdin_pull_requests?
251
- pull_requests = Decidim::MaintainersToolbox::GithubManager::Querier::ByQuery.new(token: @token, query: { title: "New Crowdin updates", creator: "decidim-bot" }).call
57
+ pull_requests = Decidim::MaintainersToolbox::GithubManager::Querier::ByQuery.new(
58
+ token: @token,
59
+ query: { title: "New Crowdin updates", creator: "decidim-bot" }
60
+ ).call
252
61
  pull_requests.any?
253
62
  end
254
63
 
@@ -278,14 +87,6 @@ You will see errors such as `No matching version found for @decidim/browserslist
278
87
  EOERROR
279
88
  exit_with_errors(error_message)
280
89
  end
281
-
282
- # Exit the script execution with a message
283
- #
284
- # @return [void]
285
- def exit_with_errors(message)
286
- puts message
287
- exit 1
288
- end
289
90
  end
290
91
  end
291
92
  end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require_relative "changelog_generator"
5
+ require_relative "github_manager/poster"
6
+
7
+ module Decidim
8
+ module MaintainersToolbox
9
+ module ReleaserUtils
10
+ class InvalidVersionTypeError < StandardError; end
11
+
12
+ DECIDIM_VERSION_FILE = ".decidim-version".freeze
13
+
14
+ # Exit the script execution with a message
15
+ #
16
+ # @return [void]
17
+ def exit_with_errors(message)
18
+ puts message
19
+ exit 1
20
+ end
21
+
22
+ # Captures to output of a command
23
+ #
24
+ # @return [Array<String, Process::Status>] The stdout and stderr of the command and its status (aka error code)
25
+ def capture(cmd, env: {})
26
+ Open3.capture2e(env, cmd)
27
+ end
28
+
29
+ # Runs a command
30
+ #
31
+ # @return [void]
32
+ def run(cmd, out: $stdout)
33
+ system(cmd, out: out, exception: true)
34
+ end
35
+
36
+ # The git branch
37
+ #
38
+ # @return [String]
39
+ def branch
40
+ @branch ||= capture("git rev-parse --abbrev-ref HEAD")[0].strip
41
+ end
42
+
43
+ # The version number from the file
44
+ #
45
+ # @return [String] the version number
46
+ def old_version_number
47
+ File.read(DECIDIM_VERSION_FILE).strip
48
+ end
49
+
50
+ def parsed_version_number(version_number)
51
+ /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/ =~ version_number
52
+
53
+ [major.to_i, minor.to_i, patch.to_i]
54
+ end
55
+
56
+ # Run the tests and if fails restore the changes using git and exit with an error
57
+ #
58
+ # @return [void]
59
+ def check_tests
60
+ puts "Running specs"
61
+ output, status = capture("bin/rspec", env: { "ENFORCED_LOCALES" => "en,ca,es", "SKIP_NORMALIZATION" => "true" })
62
+
63
+ unless status.success?
64
+ run("git restore .")
65
+ puts output
66
+ exit_with_errors("Tests execution failed. Fix the errors and run again.")
67
+ end
68
+ end
69
+
70
+ # Generates the changelog taking into account the last time the version changed
71
+ #
72
+ # @return [void]
73
+ def generate_changelog
74
+ sha_version = capture("git log -n 1 --pretty=format:%h -- .decidim-version")[0]
75
+ ChangeLogGenerator.new(token: @token, since_sha: sha_version).call
76
+ temporary_changelog = File.read("./temporary_changelog.md")
77
+ legacy_changelog = File.read("./CHANGELOG.md")
78
+ version_changelog = "## [#{version_number}](https://github.com/decidim/decidim/tree/#{version_number})\n\n#{temporary_changelog}\n"
79
+ changelog = legacy_changelog.gsub("# Changelog\n\n", "# Changelog\n\n#{version_changelog}")
80
+ File.write("./CHANGELOG.md", changelog)
81
+ end
82
+
83
+ # Creates the pull request for bumping the version
84
+ #
85
+ # @return [void]
86
+ def create_pull_request
87
+ base_branch = release_branch
88
+ head_branch = "chore/prepare/#{version_number}"
89
+
90
+ params = {
91
+ title: "Bump to v#{version_number} version",
92
+ body: "#### :tophat: What? Why?
93
+
94
+ This PR prepares version of the #{release_branch} branch, so we can publish the release once this is approved and merged.
95
+
96
+ #### Testing
97
+
98
+ All the tests should pass, except for some generators tests, that will fail because the gems and NPM packages have not
99
+ been actually published yet (as in sent to rubygems/npm).
100
+ You will see errors such as `No matching version found for @decidim/browserslist-config@~0.xx.y` in the CI logs.
101
+
102
+ :hearts: Thank you!
103
+ ",
104
+ labels: ["type: internal"],
105
+ head: head_branch,
106
+ base: base_branch
107
+ }
108
+ Decidim::MaintainersToolbox::GithubManager::Poster.new(token: @token, params: params).call
109
+ end
110
+
111
+ # Changes the decidim version in the file
112
+ #
113
+ # @return [void]
114
+ def bump_decidim_version(new_version_number)
115
+ File.write(DECIDIM_VERSION_FILE, new_version_number)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module MaintainersToolbox
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-maintainers_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Pereira de Lucena
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
10
  date: 1980-01-01 00:00:00.000000000 Z
@@ -130,7 +129,10 @@ files:
130
129
  - lib/decidim/maintainers_toolbox/github_manager/querier/by_label.rb
131
130
  - lib/decidim/maintainers_toolbox/github_manager/querier/by_query.rb
132
131
  - lib/decidim/maintainers_toolbox/github_manager/querier/related_issues.rb
132
+ - lib/decidim/maintainers_toolbox/release_candidate_version.rb
133
+ - lib/decidim/maintainers_toolbox/release_patch_version.rb
133
134
  - lib/decidim/maintainers_toolbox/releaser.rb
135
+ - lib/decidim/maintainers_toolbox/releaser_utils.rb
134
136
  - lib/decidim/maintainers_toolbox/version.rb
135
137
  homepage: https://decidim.org
136
138
  licenses:
@@ -141,7 +143,6 @@ metadata:
141
143
  funding_uri: https://opencollective.com/decidim
142
144
  homepage_uri: https://decidim.org
143
145
  source_code_uri: https://github.com/decidim/decidim
144
- post_install_message:
145
146
  rdoc_options: []
146
147
  require_paths:
147
148
  - lib
@@ -156,8 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  - !ruby/object:Gem::Version
157
158
  version: '0'
158
159
  requirements: []
159
- rubygems_version: 3.2.22
160
- signing_key:
160
+ rubygems_version: 3.6.6
161
161
  specification_version: 4
162
162
  summary: Release related tools for the Decidim project
163
163
  test_files: []