Skip to content

Commit

Permalink
Added support for version bump github action using fastlane
Browse files Browse the repository at this point in the history
  • Loading branch information
rob729 committed Dec 17, 2023
1 parent 26f2b7d commit 0db311e
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 14 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -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: '2.7'

- 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 '[email protected]'
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 bump_version 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."
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
61 changes: 48 additions & 13 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions fastlane/README.md
Original file line number Diff line number Diff line change
@@ -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).
23 changes: 23 additions & 0 deletions fastlane/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="fastlane.lanes">




<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000192">

</testcase>


<testcase classname="fastlane.lanes" name="1: default_platform" time="8.1e-05">

</testcase>


<testcase classname="fastlane.lanes" name="2: git_commit" time="0.194071">

</testcase>

</testsuite>
</testsuites>

0 comments on commit 0db311e

Please sign in to comment.