Skip to content
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

Feature/semver2 #44

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ env:
APP_VERSION_NAME: ${{ secrets.APP_VERSION_NAME }}
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }}
CI_PIPELINE_ID: ${{ github.run_number }}
CI_COMMIT_BEFORE_SHA: ${{ github.event.before }}
CI_COMMIT_BEFORE_SHA: ${{ github.sha }}
APP_PACKAGE_NAME: ${{ secrets.APP_PACKAGE_NAME }}
CI_ENVIRONMENT_NAME: ${{ github.workflow }}
SEMVER: "true"

jobs:
prod_firebase:
Expand All @@ -33,6 +34,9 @@ jobs:
password: ${{ secrets.github_token }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/cache@v2
with:
path: |
Expand All @@ -45,6 +49,8 @@ jobs:
echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
echo $SA_JSON_KEY | base64 -d -i > key_firebase.json
echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
git config user.name github-actions
git config user.email [email protected]
bundle exec fastlane firebase_distribution
env:
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ env:
APP_VERSION_NAME: ${{ secrets.APP_VERSION_NAME }}
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_STG }}
CI_PIPELINE_ID: ${{ github.run_number }}
CI_COMMIT_BEFORE_SHA: ${{ github.event.before }}
CI_COMMIT_BEFORE_SHA: ${{ github.sha }}
APP_PACKAGE_NAME: ${{ secrets.APP_PACKAGE_NAME }}
BUILD_TASK: "assemble"
BUILD_TYPE: "debug"
CI_ENVIRONMENT_NAME: ${{ github.workflow }}
SEMVER: "true"

jobs:
staging_firebase:
Expand All @@ -36,6 +37,8 @@ jobs:
password: ${{ secrets.github_token }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/cache@v2
with:
path: |
Expand Down
7 changes: 3 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ before_script:
- echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
- echo $SA_JSON_KEY | base64 -d -i > key_firebase.json
- echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
- git config --global user.email $GITLAB_USER_EMAIL
- git config --global user.name $CI_REGISTRY_USER
- git remote set-url origin https://oauth2:[email protected]/$CI_PROJECT_PATH

cache:
key:
Expand Down Expand Up @@ -75,10 +78,6 @@ prod_firebase:
stage: deploy_prod
script:
- bundle exec fastlane firebase_distribution
artifacts:
paths:
- app/build/outputs/bundle/release/app-release.aab
expire_in: 1 day
environment:
name: prod

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV PATH="${PATH}:/android-sdk-linux/platform-tools/"

# Install OS packages
RUN apt-get --quiet update --yes && \
apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 build-essential ruby ruby-dev graphicsmagick
apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 build-essential ruby ruby-dev graphicsmagick git

# Install Android SDK
RUN wget --quiet --output-document=android-sdk.zip "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip" && \
Expand All @@ -29,4 +29,4 @@ RUN wget --quiet --output-document=android-sdk.zip "https://dl.google.com/androi
COPY Gemfile .
RUN gem install bundler && \
bundle install && \
gem install fastlane-plugin-firebase_app_distribution fastlane-plugin-badge
gem install fastlane-plugin-firebase_app_distribution fastlane-plugin-badge fastlane-plugin-semantic_release
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,33 +225,45 @@ GitLab --> Deployments --> Environment --> New Environment

##### Environment variables

| NAME | ENVIRONMENT | DESCRIPTION |
|-----------------------------|:--------------------:|-----------------------------------------------------------------------------------------------------------------------------------------------:|
| KEYSTORE | ALL | Encoded to base64 signing keystore (base64) |
| KEYSTORE_PW | ALL | Password for signing keystore |
| ALIAS | ALL | Keystore alias |
| ALIAS_PW | ALL | Password for keystore alias |
| SA_JSON_KEY | STAGING/PROD | Service Account key for Firebase (base64) |
| SA_JSON_GP_KEY | PROD-GP | Service account key for Google Play Console (base64) |
| GOOGLE_SERVICES_JSON | ALL | Main configuration file for Firebase |
| APP_VERSION_NAME | STAGING/PROD/PROD-GP | Application version |
| FIREBASE_APP_ID | STAGING/PROD | Application ID in Firebase |
| BUILD_TASK | STAGING/PROD/PROD-GP | Task name in gradle (assemble, bundle, test) |
| BUILD_TYPE | STAGING/PROD/PROD-GP | Build type (assemble, release) |
| SLACK_WEBHOOK_URL | ALL | Slack webhook |
| FIREBASE_TESTER_GROUP_NAME | STAGING/PROD | Name of testers group in Firebase |
| APPROVERS | ALL | List of approvers for Google Play release, used only in GitHub Actions |
| CI_PIPELINE_ID | ALL | Pipeline ID used for `versionCode`, by default declared in the GitLab, in the GitHub Actions used github.run_number |
| CI_COMMIT_BEFORE_SHA | ALL | Previous commit, used for build changelog, by default declared in the GitLab, in the GitHub Actions used github.event.before |
| FIREBASE_ARTIFACT_TYPE | STAGING/PROD | Artifact type for Firebase distribution |
| PROJECT_DIR | ALL | If the project is not in the main directory, you can specify the path to the project directory through the `PROJECT_DIR` variable in Fastfile. |
| APP_PACKAGE_NAME | ALL | The default android package name for example we use `com.boiler.android.hello` |
| CI_ENVIRONMENT_NAME | STAGING/PROD | Used in fastlane badge, to display env in icon. |

| NAME | ENVIRONMENT | DESCRIPTION |
|---------------------------|:--------------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------:|
| KEYSTORE | ALL | Encoded to base64 signing keystore (base64) |
| KEYSTORE_PW | ALL | Password for signing keystore |
| ALIAS | ALL | Keystore alias |
| ALIAS_PW | ALL | Password for keystore alias |
| SA_JSON_KEY | STAGING/PROD | Service Account key for Firebase (base64) |
| SA_JSON_GP_KEY | PROD-GP | Service account key for Google Play Console (base64) |
| GOOGLE_SERVICES_JSON | ALL | Main configuration file for Firebase |
| APP_VERSION_NAME | STAGING/PROD/PROD-GP | Application version |
| FIREBASE_APP_ID | STAGING/PROD | Application ID in Firebase |
| BUILD_TASK | STAGING/PROD/PROD-GP | Task name in gradle (assemble, bundle, test) |
| BUILD_TYPE | STAGING/PROD/PROD-GP | Build type (assemble, release) |
| SLACK_WEBHOOK_URL | ALL | Slack webhook |
| FIREBASE_TESTER_GROUP_NAME | STAGING/PROD | Name of testers group in Firebase |
| APPROVERS | ALL | List of approvers for Google Play release, used only in GitHub Actions |
| CI_PIPELINE_ID | ALL | Pipeline ID used for `versionCode`, by default declared in the GitLab, in the GitHub Actions used github.run_number |
| CI_COMMIT_BEFORE_SHA | ALL | Previous commit, used for build changelog, by default declared in the GitLab, in the GitHub Actions used github.event.before |
| FIREBASE_ARTIFACT_TYPE | STAGING/PROD | Artifact type for Firebase distribution |
| PROJECT_DIR | ALL | If the project is not in the main directory, you can specify the path to the project directory through the `PROJECT_DIR` variable in Fastfile. |
| APP_PACKAGE_NAME | ALL | The default android package name for example we use `com.boiler.android.hello` |
| CI_ENVIRONMENT_NAME | STAGING/PROD | Used in fastlane badge, to display env in icon. |
| SEMVER | ALL | if you want to use app versioning . For gilab, you also need to add a variable GITLAB_TOKEN |
| GITLAB_TOKEN | PROD | Used for application versioning |
* When you complete all this preparation, you can start to build and release the application to Firebase

### Additional configuration

#### Configuration plugins for Fastlane

* We have `Pluginfile` in this file we can configure plugins for Fastlane, by default we use `fastlane-plugin-firebase_app_distribution` and `fastlane-plugin-badge`

## Semantic-release
* If you want to use semantic-release to version your application use Conventional Commits more [here](https://www.conventionalcommits.org/en/v1.0.0/)

```terraform
fix: a commit of the type fix patches a bug in your codebase (this correlates with PATCH in Semantic Versioning).
feat: a commit of the type feat introduces a new feature to the codebase (this correlates with MINOR in Semantic Versioning).
BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a breaking API change (correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any type.
types other than fix: and feat: are allowed, for example @commitlint/config-conventional (based on the the Angular convention) recommends build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.
footers other than BREAKING CHANGE: <description> may be provided and follow a convention similar to git trailer format.
```
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def getVersionCode = { ->
println "VersionCode is set to $code"
return code
}
def getVersionName = { ->
def code = project.hasProperty('versionName') ? versionName.toString() : System.env.APP_VERSION_NAME
println "versionName is set to $code"
return code
}

repositories {
mavenCentral()
Expand All @@ -22,7 +27,7 @@ android {
minSdk 24
targetSdk 32
versionCode getVersionCode()
versionName System.env.APP_VERSION_NAME
versionName getVersionName()

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -44,7 +49,7 @@ android {
resValue "string", "app_name", "staging boiler"

applicationIdSuffix ".staging"
versionNameSuffix "-S"
versionNameSuffix "-staging"
}
}

Expand Down
23 changes: 21 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ platform :android do

desc "Build android"
lane :build_release do |options|

semver = ENV["SEMVER"]
if semver
tag_prefix = "v*"
isReleasable = analyze_commits(match: tag_prefix)
puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}"

end

build_android_app(
task: ENV["BUILD_TASK"],
build_type: ENV["BUILD_TYPE"],
Expand All @@ -41,6 +50,7 @@ platform :android do
"android.injected.signing.key.alias" => "#{ENV["ALIAS"]}",
"android.injected.signing.key.password" => "#{ENV["ALIAS_PW"]}",
"versionCode" => ENV["CI_PIPELINE_ID"],
"versionName" => "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}"
}
)
end
Expand Down Expand Up @@ -70,8 +80,6 @@ platform :android do
merge_commit_filtering: "exclude_merges"
)

puts "Uploading new version(#{ENV["CI_PIPELINE_ID"]}) to Firebase"

firebase_app_distribution(
app: ENV["FIREBASE_APP_ID"],
groups: ENV["FIREBASE_TESTER_GROUP_NAME"],
Expand All @@ -80,7 +88,9 @@ platform :android do
release_notes: changes,
debug: true,
)
tag_push(environment: ENV["CI_ENVIRONMENT_NAME"])
success("Firebase")

rescue => exception
on_error(exception)
UI.user_error!(exception)
Expand Down Expand Up @@ -134,3 +144,12 @@ end
)
end
end

private_lane :tag_push do |options|
if options[:environment] == "staging"
elsif options[:environment] =~ /prod/
next_version = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}"
add_git_tag(tag: "v#{next_version}")
push_git_tags()
end
end
1 change: 1 addition & 0 deletions fastlane/Pluginfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Ensure this file is checked in to source control!
gem 'fastlane-plugin-firebase_app_distribution'
gem 'fastlane-plugin-badge'
gem 'fastlane-plugin-semantic_release'