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 24, 2023
1 parent 26f2b7d commit dde60e7
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 14 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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: fastlane-updated-task
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 '[email protected]'
new_branch="version-bump-${{ github.run_id }}"
git checkout -b $new_branch
git push origin $new_branch -u ${{ secrets.ACTION_NEWS_FEED_V2 }}
- name: Run Fastlane lane for version bump
env:
GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }}
run: fastlane android 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_NEWS_FEED_V2 }}
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
69 changes: 56 additions & 13 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,66 @@
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_code_regex = /versionCode (\d+)/

version_name = gradle_file[version_name_regex, 1]
version_code = gradle_file[version_code_regex, 1].to_i

# 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}"
new_version_code = version_code + 1

# Replace the versionName and versionCode in the file
new_gradle_file = gradle_file.sub(version_name_regex, "versionName \"#{new_version_name}\"")
new_gradle_file = new_gradle_file.sub(version_code_regex, "versionCode #{new_version_code}")

File.open(gradle_file_path, 'w') { |file| file.puts new_gradle_file }

UI.message("Version name incremented to #{new_version_name}")
UI.message("Version code incremented to #{new_version_code}")


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).
18 changes: 18 additions & 0 deletions fastlane/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="fastlane.lanes">




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

</testcase>


<testcase classname="fastlane.lanes" name="1: git_commit" time="6.529921">

</testcase>

</testsuite>
</testsuites>

0 comments on commit dde60e7

Please sign in to comment.