From a384257af2db94242514b328c850c5283fd63716 Mon Sep 17 00:00:00 2001 From: JayShortway <29483617+JayShortway@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:03:06 +0200 Subject: [PATCH] Moves publishing logic from the CircleCI config to Fastlane. (#100) --- .circleci/config.yml | 40 +++++++++------------------------------- fastlane/Fastfile | 41 +++++++++++++++++++++++++++++++++++++++++ fastlane/README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ed262985..4a3418f2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,22 +21,6 @@ commands: name: Install Android SDK platform tools command: sdkmanager "platform-tools" - require-snapshot-version: - description: Check that the current version is a SNAPSHOT version - steps: - - run: - name: Check that the current version is a SNAPSHOT version - command: | - set -euo pipefail - file_path="gradle/libs.versions.toml" - version=$(grep 'revenuecat-kmp = ' "$file_path" | awk -F ' = ' '{print $2}' | tr -d '"') - if [[ ! "$version" =~ -SNAPSHOT$ ]]; then - echo "$version is not a SNAPSHOT version. Exiting..." - exit 1 - else - echo "$version is a SNAPSHOT version. Proceeding..." - fi - parameters: action: type: enum @@ -81,7 +65,7 @@ jobs: automatic_release:<< pipeline.parameters.automatic >> publish: - description: "Publishes a release, either SNAPSHOT or final." + description: "Publishes the SDK, either a SNAPSHOT or release version." executor: xcode15 parameters: snapshot: @@ -89,27 +73,21 @@ jobs: type: boolean steps: - checkout - - when: - condition: << parameters.snapshot >> - steps: - - require-snapshot-version - install-android-sdk-on-macos - android/restore-gradle-cache - android/restore-build-cache - - run: - name: Set environment variables for publishing - command: | - echo 'export ORG_GRADLE_PROJECT_mavenCentralUsername="$SONATYPE_NEXUS_TOKEN_USERNAME"' >> "$BASH_ENV" - echo 'export ORG_GRADLE_PROJECT_mavenCentralPassword="$SONATYPE_NEXUS_TOKEN_PASSWORD"' >> "$BASH_ENV" - echo 'export ORG_GRADLE_PROJECT_signingInMemoryKey="$SIGNING_GPG_IN_MEMORY"' >> "$BASH_ENV" - echo 'export ORG_GRADLE_PROJECT_signingInMemoryKeyPassword="$GPG_SIGNING_KEY_PW_NEW"' >> "$BASH_ENV" - # TODO Remove this condition to allow releasing non-SNAPSHOT versions. - when: condition: << parameters.snapshot >> steps: - run: - name: Publish to Maven Central - command: ./gradlew publishAllPublicationsToMavenCentralRepository + name: "Publish snapshot to Sonatype's snapshots repository" + command: bundle exec fastlane publish_if_snapshot + - unless: + condition: << parameters.snapshot >> + steps: + - run: + name: "Publish release to Maven Central" + command: bundle exec fastlane publish_if_release - android/save-gradle-cache - android/save-build-cache diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 6b2d66da..6de5af78 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -105,6 +105,26 @@ lane :tag_current_branch do |options| push_git_tags(tag: version_number) end +desc "Publish the SDK if the current version is a SNAPSHOT version" +lane :publish_if_snapshot do |options| + version = current_version_number + if version.end_with?("-SNAPSHOT") + publish + else + UI.user_error!("The current version '#{version}' is not a SNAPSHOT version.") + end +end + +desc "Publish the SDK if the current version is a release version" +lane :publish_if_release do |options| + version = current_version_number + if version.end_with?("-SNAPSHOT") + UI.user_error!("The current version '#{version}' is a SNAPSHOT version.") + else + publish + end +end + desc "Creates a GitHub release for the current version" lane :github_release_current_version do |options| github_release(version: current_version_number) @@ -155,3 +175,24 @@ def get_phc_version raise "git tag with version #{version_number} already exists!" end end + +# Publishes the SDK. If the current version is a SNAPSHOT version, it will be published +# to Sonatype's snapshots repository, otherwise it will be published to Maven Central. +# +# This requires the following environment variables to be set: +# - SONATYPE_NEXUS_TOKEN_USERNAME +# - SONATYPE_NEXUS_TOKEN_PASSWORD +# - SIGNING_GPG_IN_MEMORY +# - GPG_SIGNING_KEY_PW_NEW +# +# These are set on CircleCI by providing the maven-central-publishing context when +# running the publish job. +def publish + version = current_version_number + UI.verbose("Publishing #{version}") + ENV["ORG_GRADLE_PROJECT_mavenCentralUsername"] = ENV["SONATYPE_NEXUS_TOKEN_USERNAME"] + ENV["ORG_GRADLE_PROJECT_mavenCentralPassword"] = ENV["SONATYPE_NEXUS_TOKEN_PASSWORD"] + ENV["ORG_GRADLE_PROJECT_signingInMemoryKey"] = ENV["SIGNING_GPG_IN_MEMORY"] + ENV["ORG_GRADLE_PROJECT_signingInMemoryKeyPassword"] = ENV["GPG_SIGNING_KEY_PW_NEW"] + gradle(task: "publishAllPublicationsToMavenCentralRepository") +end diff --git a/fastlane/README.md b/fastlane/README.md index d87c1fe3..b2ab6096 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -28,7 +28,7 @@ Bumps version, edits changelog, and creates pull request [bundle exec] fastlane automatic_bump ``` -Automatically bumps version, edits changelog, and creates pull request +Automatically determines next version, bumps it, edits changelog, and creates pull request ### update_hybrid_common @@ -38,6 +38,46 @@ Automatically bumps version, edits changelog, and creates pull request Update purchases-hybrid-common dependency +### tag_current_branch + +```sh +[bundle exec] fastlane tag_current_branch +``` + +Tags the current branch with the current version number + +### publish_if_snapshot + +```sh +[bundle exec] fastlane publish_if_snapshot +``` + +Publish the SDK if the current version is a SNAPSHOT version + +### publish_if_release + +```sh +[bundle exec] fastlane publish_if_release +``` + +Publish the SDK if the current version is a release version + +### github_release_current_version + +```sh +[bundle exec] fastlane github_release_current_version +``` + +Creates a GitHub release for the current version + +### github_release + +```sh +[bundle exec] fastlane github_release +``` + +Creates a GitHub release + ---- This README.md is auto-generated and will be re-generated every time [