From 4bd229687f7e0ec3a949a53bc3a35acbc13fac25 Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Thu, 28 Jul 2022 21:57:53 +0600 Subject: [PATCH 1/9] testing semver --- .github/workflows/base-image.yaml | 1 + .github/workflows/lint-and-tests.yaml | 1 + .github/workflows/staging.yaml | 12 +++++++++++- Dockerfile | 2 +- fastlane/Fastfile | 28 +++++++++++++++++++++++++++ fastlane/Pluginfile | 2 ++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index 15ca4e3..b4cbcde 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/semver2 paths: - 'Dockerfile' diff --git a/.github/workflows/lint-and-tests.yaml b/.github/workflows/lint-and-tests.yaml index 2fd18aa..0c036b6 100644 --- a/.github/workflows/lint-and-tests.yaml +++ b/.github/workflows/lint-and-tests.yaml @@ -8,6 +8,7 @@ on: push: branches: - main + - feature/semver2 env: GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index 3948d86..2c7996f 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -3,7 +3,7 @@ name: 'staging' on: workflow_run: workflows: ['lint and tests'] - branches: [main] + branches: [main,feature/semver2] types: - completed workflow_dispatch: @@ -24,6 +24,9 @@ env: BUILD_TASK: "assemble" BUILD_TYPE: "debug" CI_ENVIRONMENT_NAME: ${{ github.workflow }} + SEMVER: "true" + FLAVOR_TYPE: "beta" + GIT_REMOTE: "https://${{ secrets.BASEAUTH }}@github.com:maddevsio/android-ci-cd.git" jobs: staging_firebase: @@ -44,6 +47,13 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- + + - uses: dawidd6/action-get-tag@v1 + with: + # Optionally strip `v` prefix + strip_v: true + - run: echo ${{steps.tag.outputs.tag}} + - run: | echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore echo $SA_JSON_KEY | base64 -d -i > key_firebase.json diff --git a/Dockerfile b/Dockerfile index 44de1ad..fa45c9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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-versioning_android fastlane-plugin-semantic_release diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 2bc647f..edd961a 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -28,8 +28,33 @@ platform :android do ) end + desc "Generates release notes for slack and create the next tag" + lane :post_deploy do + next_version = lane_context[SharedValues::RELEASE_NEXT_VERSION] + + # Create tag to recognize future "last version" (the current version) + add_git_tag(tag: "v#{next_version}-#{ENV["FLAVOR_TYPE"]}") + push_git_tags(remote: "#{ENV["GIT_REMOTE"]}") + end + desc "Build android" lane :build_release do |options| + + semver = ENV["SEMVER"] + if semver + isReleasable = analyze_commits(match: '*-\"#{ENV["FLAVOR_TYPE"]}\"') + tag = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" + puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" + + android_set_version_code( + gradle_file: "./app/build.gradle" + ) + android_set_version_name( + version_name: tag, + gradle_file: "./app/build.gradle" + ) + end + build_android_app( task: ENV["BUILD_TASK"], build_type: ENV["BUILD_TYPE"], @@ -81,6 +106,9 @@ platform :android do debug: true, ) success("Firebase") + + post_deploy() + rescue => exception on_error(exception) UI.user_error!(exception) diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile index 14266a6..b726bfb 100644 --- a/fastlane/Pluginfile +++ b/fastlane/Pluginfile @@ -3,3 +3,5 @@ # Ensure this file is checked in to source control! gem 'fastlane-plugin-firebase_app_distribution' gem 'fastlane-plugin-badge' +gem 'fastlane-plugin-versioning_android' +gem 'fastlane-plugin-semantic_release' From 7ab8dc0e686053b5df646103c20477b12dae42a3 Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Thu, 28 Jul 2022 22:35:52 +0600 Subject: [PATCH 2/9] testing semver tags --- .github/workflows/base-image.yaml | 1 - .github/workflows/lint-and-tests.yaml | 1 - fastlane/Fastfile | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index b4cbcde..15ca4e3 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -4,7 +4,6 @@ on: push: branches: - main - - feature/semver2 paths: - 'Dockerfile' diff --git a/.github/workflows/lint-and-tests.yaml b/.github/workflows/lint-and-tests.yaml index 0c036b6..2fd18aa 100644 --- a/.github/workflows/lint-and-tests.yaml +++ b/.github/workflows/lint-and-tests.yaml @@ -8,7 +8,6 @@ on: push: branches: - main - - feature/semver2 env: GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} diff --git a/fastlane/Fastfile b/fastlane/Fastfile index edd961a..837088e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -42,7 +42,7 @@ platform :android do semver = ENV["SEMVER"] if semver - isReleasable = analyze_commits(match: '*-\"#{ENV["FLAVOR_TYPE"]}\"') + isReleasable = analyze_commits(match: 'v*') tag = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" From 7a733e8d8f6322eb6e1a0980a3c961505de924bb Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Thu, 28 Jul 2022 23:09:04 +0600 Subject: [PATCH 3/9] add git command --- .github/workflows/staging.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index 2c7996f..a2c1e99 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -55,6 +55,8 @@ jobs: - run: echo ${{steps.tag.outputs.tag}} - run: | + git describe --tags + git describe --tags --match='v*' 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 From 931de8b6c2a7db8de4ee38ae5235783bbf97b1f1 Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Thu, 28 Jul 2022 23:14:37 +0600 Subject: [PATCH 4/9] Change dockerfile --- .github/workflows/base-image.yaml | 1 + Dockerfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index 15ca4e3..b4cbcde 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/semver2 paths: - 'Dockerfile' diff --git a/Dockerfile b/Dockerfile index fa45c9f..d1235f1 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" && \ From b3903a6fd2ee6f6730d7f003307e7e0da2224810 Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Fri, 29 Jul 2022 10:37:58 +0600 Subject: [PATCH 5/9] add tag prefix --- .github/workflows/staging.yaml | 1 - fastlane/Fastfile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index a2c1e99..db092a7 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -55,7 +55,6 @@ jobs: - run: echo ${{steps.tag.outputs.tag}} - run: | - git describe --tags git describe --tags --match='v*' echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore echo $SA_JSON_KEY | base64 -d -i > key_firebase.json diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 837088e..70d9494 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -3,6 +3,7 @@ platform :android do before_all do |lane, options| ENV["APP_FLAVOR"] = options[:flavor] ENV["PROJECT_DIR"] = "./" + tag_prefix = 'v*' puts "Flavor environment #{options[:flavor]}" end def on_error(exception) @@ -42,7 +43,7 @@ platform :android do semver = ENV["SEMVER"] if semver - isReleasable = analyze_commits(match: 'v*') + isReleasable = analyze_commits(match: tag_prefix) tag = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" From 4b29fc6e8234118b9c683b7faaf58d6e67fb546c Mon Sep 17 00:00:00 2001 From: Kirill Kulikov Date: Fri, 29 Jul 2022 10:42:11 +0600 Subject: [PATCH 6/9] change tag prefix --- fastlane/Fastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 70d9494..70f9e9e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -3,7 +3,6 @@ platform :android do before_all do |lane, options| ENV["APP_FLAVOR"] = options[:flavor] ENV["PROJECT_DIR"] = "./" - tag_prefix = 'v*' puts "Flavor environment #{options[:flavor]}" end def on_error(exception) @@ -43,6 +42,7 @@ platform :android do semver = ENV["SEMVER"] if semver + tag_prefix = 'v*' isReleasable = analyze_commits(match: tag_prefix) tag = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" From 45e306aebe059c78e6bd57401d72e13a8081e9e7 Mon Sep 17 00:00:00 2001 From: "vitalii.v2" Date: Fri, 12 Aug 2022 12:41:46 +0600 Subject: [PATCH 7/9] fix: versioning for gitlab and github --- .github/workflows/production.yaml | 33 ++++-------------- .github/workflows/staging.yaml | 20 +++-------- .gitlab-ci.yml | 7 ++-- Dockerfile | 2 +- README.md | 58 +++++++++++++++++++------------ app/build.gradle | 9 +++-- fastlane/Fastfile | 36 +++++++------------ fastlane/Pluginfile | 1 - 8 files changed, 71 insertions(+), 95 deletions(-) diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index 00630da..bd2d7ca 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,33 +49,10 @@ 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 }} BUILD_TASK: "assemble" # Change to bundle if you need aab application BUILD_TYPE: "release" - - google_play: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - needs: [prod_firebase] - runs-on: ubuntu-latest - container: - image: ghcr.io/${{ github.repository }}:latest - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - uses: trstringer/manual-approval@v1 - with: - secret: ${{ github.TOKEN }} - approvers: ${{ secrets.APPROVERS }} - - uses: actions/checkout@v3 - - run: | - echo $SA_JSON_GP_KEY | base64 -d -i > /tmp/key_gp.json - echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore - echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json - bundle exec fastlane google_beta - env: - BUILD_TASK: "bundle" - BUILD_TYPE: "release" - SA_JSON_GP_KEY: ${{ secrets.SA_JSON_GP_KEY }} diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index db092a7..ad8da95 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -3,7 +3,7 @@ name: 'staging' on: workflow_run: workflows: ['lint and tests'] - branches: [main,feature/semver2] + branches: [main] types: - completed workflow_dispatch: @@ -19,18 +19,16 @@ 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" FLAVOR_TYPE: "beta" - GIT_REMOTE: "https://${{ secrets.BASEAUTH }}@github.com:maddevsio/android-ci-cd.git" jobs: staging_firebase: - if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch' && github.event.workflow_run.conclusion != 'success') }} runs-on: ubuntu-latest container: image: ghcr.io/${{ github.repository }}:latest @@ -39,23 +37,15 @@ jobs: password: ${{ secrets.github_token }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - uses: actions/cache@v2 with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper + path: ${{ github.workspace }}/caches/.gradle key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- - - - uses: dawidd6/action-get-tag@v1 - with: - # Optionally strip `v` prefix - strip_v: true - - run: echo ${{steps.tag.outputs.tag}} - - run: | - git describe --tags --match='v*' 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 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 d1235f1..40d2fa9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 fastlane-plugin-versioning_android fastlane-plugin-semantic_release + 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 70f9e9e..92c95c1 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -28,32 +28,15 @@ platform :android do ) end - desc "Generates release notes for slack and create the next tag" - lane :post_deploy do - next_version = lane_context[SharedValues::RELEASE_NEXT_VERSION] - - # Create tag to recognize future "last version" (the current version) - add_git_tag(tag: "v#{next_version}-#{ENV["FLAVOR_TYPE"]}") - push_git_tags(remote: "#{ENV["GIT_REMOTE"]}") - end - desc "Build android" lane :build_release do |options| semver = ENV["SEMVER"] if semver - tag_prefix = 'v*' + tag_prefix = "v*" isReleasable = analyze_commits(match: tag_prefix) - tag = "#{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" - puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}-#{ENV["FLAVOR_TYPE"]}" + puts "RELEASE_NEXT_VERSION #{lane_context[SharedValues::RELEASE_NEXT_VERSION]}" - android_set_version_code( - gradle_file: "./app/build.gradle" - ) - android_set_version_name( - version_name: tag, - gradle_file: "./app/build.gradle" - ) end build_android_app( @@ -67,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 @@ -96,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"], @@ -106,10 +88,9 @@ platform :android do release_notes: changes, debug: true, ) + tag_push(environment: ENV["CI_ENVIRONMENT_NAME"]) success("Firebase") - post_deploy() - rescue => exception on_error(exception) UI.user_error!(exception) @@ -163,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 b726bfb..4c411f8 100644 --- a/fastlane/Pluginfile +++ b/fastlane/Pluginfile @@ -3,5 +3,4 @@ # Ensure this file is checked in to source control! gem 'fastlane-plugin-firebase_app_distribution' gem 'fastlane-plugin-badge' -gem 'fastlane-plugin-versioning_android' gem 'fastlane-plugin-semantic_release' From 0c683d25582b298790fdb4b036f7c2a9df0c6cd5 Mon Sep 17 00:00:00 2001 From: "vitalii.v2" Date: Fri, 12 Aug 2022 13:12:54 +0600 Subject: [PATCH 8/9] clean test branch --- .github/workflows/base-image.yaml | 1 - .github/workflows/production.yaml | 25 +++++++++++++++++++++++++ .github/workflows/staging.yaml | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/base-image.yaml b/.github/workflows/base-image.yaml index b4cbcde..15ca4e3 100644 --- a/.github/workflows/base-image.yaml +++ b/.github/workflows/base-image.yaml @@ -4,7 +4,6 @@ on: push: branches: - main - - feature/semver2 paths: - 'Dockerfile' diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index bd2d7ca..69de827 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -56,3 +56,28 @@ jobs: FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }} BUILD_TASK: "assemble" # Change to bundle if you need aab application BUILD_TYPE: "release" + + google_play: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: [prod_firebase] + runs-on: ubuntu-latest + container: + image: ghcr.io/${{ github.repository }}:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.github_token }} + steps: + - uses: trstringer/manual-approval@v1 + with: + secret: ${{ github.TOKEN }} + approvers: ${{ secrets.APPROVERS }} + - uses: actions/checkout@v3 + - run: | + echo $SA_JSON_GP_KEY | base64 -d -i > /tmp/key_gp.json + echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore + echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json + bundle exec fastlane google_beta + env: + BUILD_TASK: "bundle" + BUILD_TYPE: "release" + SA_JSON_GP_KEY: ${{ secrets.SA_JSON_GP_KEY }} diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index ad8da95..3e5bb7e 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -29,6 +29,7 @@ env: jobs: staging_firebase: + if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch' && github.event.workflow_run.conclusion != 'success') }} runs-on: ubuntu-latest container: image: ghcr.io/${{ github.repository }}:latest From 1c8bfdfd4ac887dcf3bb856aeba84762625dbdc8 Mon Sep 17 00:00:00 2001 From: "vitalii.v2" Date: Fri, 12 Aug 2022 14:00:35 +0600 Subject: [PATCH 9/9] edit cache --- .github/workflows/staging.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index 3e5bb7e..f59c49f 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -25,7 +25,6 @@ env: BUILD_TYPE: "debug" CI_ENVIRONMENT_NAME: ${{ github.workflow }} SEMVER: "true" - FLAVOR_TYPE: "beta" jobs: staging_firebase: @@ -42,7 +41,9 @@ jobs: fetch-depth: 0 - uses: actions/cache@v2 with: - path: ${{ github.workspace }}/caches/.gradle + path: | + ~/.gradle/caches + ~/.gradle/wrapper key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle-