fastlane-plugin-wpmreleasetoolkit 14.11.1 → 14.11.2

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: 264531e5928d22e6bf9b73c4857885a01344392511225591d4dae8bd1cc3480a
4
- data.tar.gz: f831520911a045538a4c0557eaf65a92c00794a5763ca8db66e33942d53f4a12
3
+ metadata.gz: 0a1f1e623158a6faef2f63c3376a61d70cdcee25c70ebf91802d0cebdacef0a2
4
+ data.tar.gz: af2b3f68f2cc761f05a88c676bad63b12b55b44944052e11fe04b210c3421102
5
5
  SHA512:
6
- metadata.gz: 3dfad31148be24c6265580f275a77551a461b65fba0e89f190505aa24c496f7d95783615e3cb044dab23ec930949a7177c8a4fbffc8b2060a13b70331b15b717
7
- data.tar.gz: 9321312c16fa81f7dde696e665863f24211dcbae173049b3d65aa87a4aa57372b1d43a54c0f241393ac6906a99fd14349bf3cb3145f12c35258a2ee7bee8c5e7
6
+ metadata.gz: daf03a722ae1f03c8b9883a7552ca75d575ff059233eed51cb9368686bf4007a816ac193f89a4892f9d1d36ab3fe0d51ad8e09dd2ad2d0301144db006b478258
7
+ data.tar.gz: 9c0edbfe34703dbf6dace3a805dc22f639cbd861d8d8f3615129eca857000ce9d516e159bff6413f45c92e2cff5dfd43c9c35a6fedcaef6369f6158e856d2f38
@@ -35,7 +35,14 @@ module Fastlane
35
35
  end
36
36
 
37
37
  def self.details
38
- 'Publish an existing GitHub Release still in draft mode'
38
+ <<~DETAILS
39
+ Publish an existing draft GitHub Release.
40
+
41
+ If several GitHub Releases share the same `name`, the most recently created one is published,
42
+ as it is the one targeting the latest commit of the release branch.
43
+ (Multiple releases can exist with the same `name` when the release finalization automation
44
+ is run more than once for the same version, each run creating its own draft.)
45
+ DETAILS
39
46
  end
40
47
 
41
48
  def self.available_options
@@ -244,8 +244,36 @@ module Fastlane
244
244
  release.html_url
245
245
  end
246
246
 
247
+ # Returns all the GitHub Releases of a repository matching a given criteria, sorted from the oldest to the most recent one.
248
+ #
249
+ # @param [String] repository The repository to fetch the GitHub Releases from. Typically a repo slug (<org>/<repo>).
250
+ # @yield [Sawyer::Resource] Each GitHub Release of the repository, to decide whether it matches the criteria.
251
+ # @yieldreturn [TrueClass|FalseClass] `true` to include that GitHub Release in the returned list.
252
+ # @return [Array<Sawyer::Resource>] The matching GitHub Releases, sorted from the oldest to the most recently created one.
253
+ #
254
+ # @note A repository can legitimately host several GitHub Releases sharing the same name or tag—e.g. when `finalize_release`
255
+ # is run more than once for the same version, creating one draft per run—and the GitHub API makes no promise about the
256
+ # order in which it returns them. Callers must thus pick explicitly amongst the matches instead of relying on that order.
257
+ # @note The sort key is the release `id`, not `created_at`: once a GitHub Release is published, GitHub rewrites its `created_at`
258
+ # to the date of the commit it targets, so `created_at` is not a reliable creation timestamp. Release `id`s, on the other
259
+ # hand, are assigned by GitHub in increasing order as releases are created, including for drafts.
260
+ #
261
+ def matching_releases(repository:, &matcher)
262
+ client.releases(repository).select(&matcher).sort_by { |release| release[:id] }
263
+ end
264
+
265
+ # Returns the GitHub Release associated with a given tag, if any, including draft ones.
266
+ #
267
+ # @note Unlike a lookup by name, "the most recently created match" is not the right answer here: a git tag can
268
+ # only ever back a single *published* release, so if one of the matches is not a draft then it is the
269
+ # release owning that tag, and a more recent draft sharing the same `tag_name` is a leftover—typically
270
+ # from a re-run of the release finalization—rather than a successor. Only when no published release
271
+ # claims the tag yet do we fall back to the most recent draft, which is the case when uploading assets
272
+ # to a release that has not been published yet.
273
+ #
247
274
  def find_release(repository:, version:)
248
- release = client.releases(repository).find { |candidate| candidate.tag_name == version }
275
+ matches = matching_releases(repository: repository) { |candidate| candidate.tag_name == version }
276
+ release = matches.reject { |candidate| candidate[:draft] }.last || matches.last
249
277
  return release unless release.nil?
250
278
 
251
279
  release_for_tag(repository: repository, version: version)
@@ -259,6 +287,7 @@ module Fastlane
259
287
  nil
260
288
  end
261
289
 
290
+ private :matching_releases
262
291
  private :find_release
263
292
  private :release_for_tag
264
293
 
@@ -306,12 +335,19 @@ module Fastlane
306
335
  # @param [Boolean] prerelease Indicates if this should be created as a pre-release (i.e. for alpha/beta)
307
336
  #
308
337
  # @return [String] URL of the corresponding GitHub Release
338
+ # @raise [Fastlane::UI::Error] UI.user_error! if no GitHub Release with that name exists.
339
+ #
340
+ # @note If several GitHub Releases share that same `name`—which happens when `finalize_release` is run more than once
341
+ # for the same version, each run creating its own draft—the most recently created one is the one being published,
342
+ # as it is the one targeting the latest commit of the release branch. The other, staler ones are left untouched.
309
343
  #
310
344
  def publish_release(repository:, name:, prerelease: nil)
311
- releases = client.releases(repository)
312
- release = releases.find { |r| r.name == name }
345
+ releases = matching_releases(repository: repository) { |release| release.name == name }
346
+ UI.user_error!("No release found with name #{name}") if releases.empty?
313
347
 
314
- UI.user_error!("No release found with name #{name}") unless release
348
+ release = releases.last
349
+ UI.important("Found #{releases.count} GitHub Releases named `#{name}`. Publishing the most recently created one, targeting #{release.target_commitish}, and leaving the #{releases.count - 1} older one(s) untouched.") if releases.count > 1
350
+ UI.important("The most recent GitHub Release named `#{name}` (#{release.html_url}) has already been published. Updating it nonetheless.") unless release.draft
315
351
 
316
352
  client.update_release(
317
353
  release.url,
@@ -3,6 +3,6 @@
3
3
  module Fastlane
4
4
  module Wpmreleasetoolkit
5
5
  NAME = 'fastlane-plugin-wpmreleasetoolkit'
6
- VERSION = '14.11.1'
6
+ VERSION = '14.11.2'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-wpmreleasetoolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.11.1
4
+ version: 14.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic