-
Notifications
You must be signed in to change notification settings - Fork 0
Add validate_version_not_in_maven_central lane
#101
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...stlane/plugin/revenuecat_internal/actions/validate_version_not_in_maven_central_action.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| require 'fastlane/action' | ||
| require 'fastlane_core/configuration/config_item' | ||
| require 'fastlane_core/ui/ui' | ||
| require_relative '../helper/maven_central_helper' | ||
|
|
||
| module Fastlane | ||
| module Actions | ||
| class ValidateVersionNotInMavenCentralAction < Action | ||
| def self.run(params) | ||
| group_id = params[:group_id] | ||
| artifact_ids = params[:artifact_ids] | ||
| version = params[:version] | ||
| auth_token = params[:auth_token] || ENV.fetch("FETCH_PUBLICATIONS_USER_TOKEN_MAVEN_CENTRAL", nil) | ||
|
|
||
| UI.message("Checking if version #{version} already exists in Maven Central...") | ||
|
|
||
| if artifact_ids.empty? | ||
| UI.user_error!("No artifacts provided. Please provide at least one artifact ID to check") | ||
| else | ||
| UI.message("Found #{artifact_ids.length} artifacts to check: #{artifact_ids.join(', ')}") | ||
| Helper::MavenCentralHelper.check_version_not_published(version, group_id, artifact_ids, auth_token) | ||
| UI.success("Version #{version} does not exist in Maven Central. Proceeding with deployment.") | ||
| end | ||
| end | ||
|
|
||
| def self.description | ||
| "Checks if a specific version of Maven artifacts already exists in Maven Central before deployment" | ||
| end | ||
|
|
||
| def self.authors | ||
| ["RevenueCat"] | ||
| end | ||
|
|
||
| def self.available_options | ||
| [ | ||
| FastlaneCore::ConfigItem.new(key: :group_id, | ||
| description: "Maven group ID (e.g., 'com.revenuecat.purchases')", | ||
| optional: false, | ||
| type: String), | ||
| FastlaneCore::ConfigItem.new(key: :artifact_ids, | ||
| description: "Array of artifact IDs to check (e.g., ['purchases', 'purchases-ui'])", | ||
| optional: false, | ||
| type: Array), | ||
| FastlaneCore::ConfigItem.new(key: :version, | ||
| description: "Version to check (e.g., '7.0.0')", | ||
| optional: false, | ||
| type: String), | ||
| FastlaneCore::ConfigItem.new(key: :auth_token, | ||
| description: "Authentication token for Maven Central API (defaults to FETCH_PUBLICATIONS_USER_TOKEN_MAVEN_CENTRAL env var)", | ||
| optional: true, | ||
| type: String) | ||
| ] | ||
| end | ||
|
|
||
| def self.is_supported?(platform) | ||
| true | ||
| end | ||
| end | ||
| end | ||
| end | ||
62 changes: 62 additions & 0 deletions
62
lib/fastlane/plugin/revenuecat_internal/helper/maven_central_helper.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| require 'fastlane_core/ui/ui' | ||
| require 'fastlane/action' | ||
| require 'rest-client' | ||
| require 'json' | ||
| require 'uri' | ||
|
|
||
| module Fastlane | ||
| UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI) | ||
|
|
||
| module Helper | ||
| class MavenCentralHelper | ||
| def self.check_version_not_published(version, group_id, artifact_ids, auth_token) | ||
| if auth_token.nil? || auth_token.empty? | ||
| UI.user_error!("FETCH_PUBLICATIONS_USER_TOKEN_MAVEN_CENTRAL environment variable is not set. Please provide a valid token to check Maven Central publications.") | ||
| end | ||
|
|
||
| base_url = "https://central.sonatype.com/api/v1/publisher/published" | ||
| existing_artifacts = [] | ||
|
|
||
| artifact_ids.each do |artifact_id| | ||
| # Build query parameters for the API endpoint with proper URI encoding | ||
| # The API uses 'name' parameter which corresponds to the artifact_id | ||
| api_url = "#{base_url}?namespace=#{URI.encode_www_form_component(group_id)}&name=#{URI.encode_www_form_component(artifact_id)}&version=#{URI.encode_www_form_component(version)}" | ||
|
|
||
| UI.verbose("Checking Sonatype API for publication status: #{group_id}:#{artifact_id}:#{version}") | ||
|
|
||
| begin | ||
| response = RestClient.get( | ||
| api_url, | ||
| { | ||
| 'Authorization' => "Bearer #{auth_token}", | ||
| 'accept' => 'application/json' | ||
| } | ||
| ) | ||
|
|
||
| # Parse JSON response | ||
| response_data = JSON.parse(response.body) | ||
|
|
||
| # Check if published field is true | ||
| if response_data["published"] == true | ||
| existing_artifacts << artifact_id | ||
| UI.important("Artifact #{group_id}:#{artifact_id}:#{version} already exists in Maven Central") | ||
| end | ||
| rescue StandardError => e | ||
| UI.user_error!("Failed to check #{group_id}:#{artifact_id}:#{version}: #{e.message}") | ||
| end | ||
| end | ||
|
|
||
| unless existing_artifacts.empty? | ||
| error_message = "Version #{version} already exists in Maven Central for the following artifacts:\n" | ||
| existing_artifacts.each do |artifact_id| | ||
| error_message += " - #{group_id}:#{artifact_id}:#{version}\n" | ||
| end | ||
| error_message += "\nDeployment cancelled to prevent duplicate releases." | ||
| UI.user_error!(error_message) | ||
| end | ||
|
|
||
| true | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note this doesn't move the logic to calculate what artifacts to check for from the android repo since that's mostly in gradle, with a small bit of logic in fastlane. We might want to consider creating a gradle plugin we can share with that part of the logic, but for now, this felt like the simpler approach.