diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index 00630da..69de827 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -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: @@ -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: | @@ -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 github-actions@github.com bundle exec fastlane firebase_distribution env: FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }} diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index 3948d86..f59c49f 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -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: @@ -36,6 +37,8 @@ jobs: password: ${{ secrets.github_token }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - uses: actions/cache@v2 with: path: | diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 981e79f..dcaf28b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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:$GITLAB_TOKEN@gitlab.com/$CI_PROJECT_PATH cache: key: @@ -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 diff --git a/Dockerfile b/Dockerfile index 44de1ad..40d2fa9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" && \ @@ -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 diff --git a/README.md b/README.md index 5c3aa36..00ea116 100644 --- a/README.md +++ b/README.md @@ -225,29 +225,30 @@ 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 @@ -255,3 +256,14 @@ GitLab --> Deployments --> Environment --> New Environment #### 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: may be provided and follow a convention similar to git trailer format. +``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index fa41cda..6eb350a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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() @@ -22,7 +27,7 @@ android { minSdk 24 targetSdk 32 versionCode getVersionCode() - versionName System.env.APP_VERSION_NAME + versionName getVersionName() testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -44,7 +49,7 @@ android { resValue "string", "app_name", "staging boiler" applicationIdSuffix ".staging" - versionNameSuffix "-S" + versionNameSuffix "-staging" } } diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 2bc647f..92c95c1 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -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"], @@ -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 @@ -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"], @@ -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) @@ -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 diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile index 14266a6..4c411f8 100644 --- a/fastlane/Pluginfile +++ b/fastlane/Pluginfile @@ -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'