From e54d53549af6cf21fac1a23efe1d344c3abb8ef3 Mon Sep 17 00:00:00 2001 From: rob729 Date: Sun, 17 Dec 2023 02:33:30 +0530 Subject: [PATCH] Added support for version bump github action using fastlane --- .github/workflows/bump_version.yml | 58 ++++++++++++++++++++++++++++ app/build.gradle | 2 +- fastlane/Fastfile | 61 +++++++++++++++++++++++------- fastlane/README.md | 48 +++++++++++++++++++++++ fastlane/report.xml | 18 +++++++++ 5 files changed, 173 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/bump_version.yml create mode 100644 fastlane/README.md create mode 100644 fastlane/report.xml diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml new file mode 100644 index 0000000..6ee7b39 --- /dev/null +++ b/.github/workflows/bump_version.yml @@ -0,0 +1,58 @@ +name: Bump Version and Create PR + +on: + push: + branches: [ fastlane-updated-task ] + pull_request: + branches: [ fastlane-updated-task ] + workflow_dispatch: + inputs: + bump_type: + description: 'Version Bump Type (patch/minor/major)' + required: true + default: 'patch' + +jobs: + version-bump: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2.2' + + - name: Install Fastlane + run: gem install fastlane + + - name: Create new branch for version bump + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + new_branch="version-bump-${{ github.run_id }}" + git checkout -b $new_branch + + - name: Run Fastlane lane for version bump + env: + GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }} + run: fastlane version_bump type:${{ github.event.inputs.bump_type }} + + - name: Get the latest commit message + id: latest-commit + run: | + commit_message=$(git log -1 --pretty=%B) + echo "commit_message=$commit_message" >> $GITHUB_ENV + + - name: Create Pull Request + uses: repo-sync/pull-request@v2 + with: + github_token: ${{ secrets.ACTION_GITHUB_TOKEN }} + source_branch: "version-bump-${{ github.run_id }}" + destination_branch: "main" + pr_title: "${{ env.commit_message }}" + pr_body: "This PR is auto-generated by GitHub Actions to bump the version." diff --git a/app/build.gradle b/app/build.gradle index 23d07f7..16789a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,7 +36,7 @@ android { minSdk 24 targetSdk 34 versionCode 1 - versionName "1.0" + versionName "1.0.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 19c557c..a0fddb7 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -16,23 +16,58 @@ default_platform(:android) platform :android do - desc "Runs all the tests" - lane :test do - gradle(task: "test") - end - desc "Submit a new Beta Build to Crashlytics Beta" + desc "Deploy a internal testing version to the Google Play" lane :beta do - gradle(task: "clean assembleRelease") - crashlytics - - # sh "your_script.sh" - # You can also use other beta testing services here + gradle(task: "clean bundleRelease") + upload_to_play_store(track: 'internal', release_status: 'draft') + end + + desc "Version bump" + lane :version_bump do |options| + require 'fileutils' + + fastfile_directory = __dir__ + gradle_file_path = File.join(fastfile_directory, '../app/build.gradle') + UI.message("xyz #{fastfile_directory}") + gradle_file = File.read(gradle_file_path) + + type = options[:type] + + # Regex to find the versionName + version_name_regex = /versionName "(\d+\.\d+\.\d+)"/ + version_name = gradle_file[version_name_regex, 1] + + # Increment the versionName + major, minor, patch = version_name.split('.').map(&:to_i) + if type == "major" + major += 1 + minor = 0 + patch = 0 + elsif type == "minor" + minor += 1 + patch = 0 + elsif type == "patch" + patch += 1 + end + + new_version_name = "#{major}.#{minor}.#{patch}" + + # Replace the versionName in the file + new_gradle_file = gradle_file.sub(version_name_regex, "versionName \"#{new_version_name}\"") + File.open(gradle_file_path, 'w') { |file| file.puts new_gradle_file } + + UI.message("Version name incremented to #{new_version_name}") + + git_commit( + path: "./app/build.gradle", + message: "Version bumped from #{version_name} to #{new_version_name}" + ) end desc "Deploy a new version to the Google Play" - lane :deploy do - gradle(task: "clean assembleRelease") - upload_to_play_store + lane :production do + gradle(task: "clean bundleRelease") + upload_to_play_store(release_status: 'draft') end end diff --git a/fastlane/README.md b/fastlane/README.md new file mode 100644 index 0000000..ddc1c12 --- /dev/null +++ b/fastlane/README.md @@ -0,0 +1,48 @@ +fastlane documentation +---- + +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +```sh +xcode-select --install +``` + +For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) + +# Available Actions + +## Android + +### android beta + +```sh +[bundle exec] fastlane android beta +``` + +Deploy a internal testing version to the Google Play + +### android version_bump + +```sh +[bundle exec] fastlane android version_bump +``` + +Version bump + +### android production + +```sh +[bundle exec] fastlane android production +``` + +Deploy a new version to the Google Play + +---- + +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. + +More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). + +The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools). diff --git a/fastlane/report.xml b/fastlane/report.xml new file mode 100644 index 0000000..4b74b84 --- /dev/null +++ b/fastlane/report.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +