From ba111686dc09189fc1d0afb06720557b7649d3d9 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 19:52:53 +0700 Subject: [PATCH 01/12] app-deploy.yaml on push branches test --- .github/workflows/app-deploy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/app-deploy.yaml b/.github/workflows/app-deploy.yaml index ea3327f99..0704540d4 100644 --- a/.github/workflows/app-deploy.yaml +++ b/.github/workflows/app-deploy.yaml @@ -3,7 +3,7 @@ name: Deploy app on: push: branches: - - main + - test workflow_dispatch: inputs: deploy_target: @@ -185,7 +185,7 @@ jobs: steps: - name: Reinstall existing fastlane plugin - run: | + run: | sudo gem uninstall fastlane-plugin-firebase_app_distribution gem install fastlane-plugin-firebase_app_distribution --user-install From b4a741c2d0b535517521a85b9f747ec599bb9ba6 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 19:53:15 +0700 Subject: [PATCH 02/12] Add branch-workflow.yaml --- .github/workflows/branch-workflow.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/branch-workflow.yaml diff --git a/.github/workflows/branch-workflow.yaml b/.github/workflows/branch-workflow.yaml new file mode 100644 index 000000000..0add92ec1 --- /dev/null +++ b/.github/workflows/branch-workflow.yaml @@ -0,0 +1,19 @@ +name: Check branch + +on: + pull_request: + branches: + - main + +jobs: + prevent-dev-merge: + runs-on: ubuntu-latest + steps: + - name: Check source branch + run: | + if [[ "${{ github.event.pull_request.head.ref }}" == "dev" ]]; then + echo "Merging from 'dev' to 'main' is not allowed." + exit 1 + else + echo "Merge allowed." + fi From e92506cb2374df6883d2852081cf59b413542eff Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 20:29:47 +0700 Subject: [PATCH 03/12] melos.yaml add deploy_ios, deploy_android, deploy_fad commands --- melos.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/melos.yaml b/melos.yaml index 05038a60c..20ce8d5c0 100644 --- a/melos.yaml +++ b/melos.yaml @@ -109,6 +109,25 @@ scripts: description: Registering new devices already added through devportal run: bash scripts/ios-match-new-devices.sh + deploy_ios: + description: Deploy iOS app to fad + run: | + BUILD_NUMBER=$(bash scripts/get-build-number.sh) + bash scripts/build.sh ios_fad $BUILD_NUMBER + + deploy_android: + description: Deploy Android app to fad + run: | + BUILD_NUMBER=$(bash scripts/get-build-number.sh) + bash scripts/build.sh android_fad $BUILD_NUMBER + + deploy_fad: + description: Deploy app to fad + run: | + BUILD_NUMBER=$(bash scripts/get-build-number.sh) + bash scripts/build.sh ios_fad $BUILD_NUMBER + bash scripts/build.sh android_fad $BUILD_NUMBER + command: clean: hooks: From f54986854fb7d87b982a7a951fbdddd834dea0f1 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 22:32:23 +0700 Subject: [PATCH 04/12] Update README.md --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7c2da42b..4ff2774b3 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,27 @@ All deployment scripts are gathering changelog from git commits and adding it to ### Deploy using GitHub Actions -We already have a workflow for deploying main app to Firebase App Distribution, TestFlight and Google Play closed testing. It's called `app=deploy` and it's triggered by pushing to the main branch or manually from any branch. You can choose the desired deployment when triggering the workflow manually. It will deploy to FAD when its triggered by pushing to the main branch. +We already have a workflow for deploying main app to Firebase App Distribution, TestFlight and Google Play. It's called `Deploy app`. + +Deployment to fab is triggered when the `test` branch is updated, or when manually launched from any branch except main. +Deployment to store is triggered when manually launched from the `main` branch. + +Deployment to FAD is triggered when the `dev` branch is updated. + +Manually running the deploy `melos run deploy_fad` from any branch **except** `main`. +Running `melos run deploy_ios` deploys iOS to FAD. +Running `melos run deploy_android` deploys Android to FAD. + +Deployment to store is triggered when manually launched from the `main` branch. + +#### Available options for deploying in workflow: + +- **ios_fad** - launches iOS deploy to FAD. +- **ios_store** - launches iOS deploy to Test Flight. +- **android_fad** - launches Android deploy to FAD. +- **android_store** - launches Android deploy to Google Play. +- **fad** - launches iOS and Android deploy to FAD. +- **store** - launches iOS and Android deploy to Test Flight and Google Play. We also have a workflow for deploying storybook to GitHub Pages. It's called `storybook-gh-pages-deploy` and it's triggered by pushing to the main branch or manually from any branch. From 7b054363f0f935b871b88e83e68176ca3bc115a4 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 23:07:48 +0700 Subject: [PATCH 05/12] Rename to deploy_fad_ios and deploy_fad_android --- melos.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/melos.yaml b/melos.yaml index 20ce8d5c0..6faf3cf4e 100644 --- a/melos.yaml +++ b/melos.yaml @@ -109,13 +109,13 @@ scripts: description: Registering new devices already added through devportal run: bash scripts/ios-match-new-devices.sh - deploy_ios: + deploy_fad_ios: description: Deploy iOS app to fad run: | BUILD_NUMBER=$(bash scripts/get-build-number.sh) bash scripts/build.sh ios_fad $BUILD_NUMBER - deploy_android: + deploy_fad_android: description: Deploy Android app to fad run: | BUILD_NUMBER=$(bash scripts/get-build-number.sh) From ed5b2200c41e503e6db3bb5e6751530893f565ba Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 23:08:28 +0700 Subject: [PATCH 06/12] Move get SENTRY_DSN to build.sh --- .github/workflows/app-deploy.yaml | 24 ------------------------ scripts/build.sh | 10 ++++++++++ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.github/workflows/app-deploy.yaml b/.github/workflows/app-deploy.yaml index ea3327f99..582d0a2c2 100644 --- a/.github/workflows/app-deploy.yaml +++ b/.github/workflows/app-deploy.yaml @@ -133,16 +133,6 @@ jobs: - name: Generate dart code run: melos codegen --no-select - # Read Sentry DSN - - name: Read Sentry DSN - id: read_sentry_dsn - run: | - if [ -f ./secrets/sentry-dsn.txt ]; then - SENTRY_DSN=$(cat ./secrets/sentry-dsn.txt) - echo "SENTRY_DSN=$SENTRY_DSN" >> $GITHUB_ENV - echo "::add-mask::$SENTRY_DSN" - fi - - name: Display Build Number run: echo "Number is = ${{ needs.setup.outputs.build_number }}" @@ -150,8 +140,6 @@ jobs: - name: Build and deploy run: | bash scripts/build.sh ${{ env.ios_target }} ${{ needs.setup.outputs.build_number }} - env: - SENTRY_DSN: ${{ env.SENTRY_DSN }} - name: Clean Xcode Derived Data run: | @@ -231,16 +219,6 @@ jobs: - name: Generate dart code run: melos codegen --no-select - # Read Sentry DSN - - name: Read Sentry DSN - id: read_sentry_dsn - run: | - if [ -f ./secrets/sentry-dsn.txt ]; then - SENTRY_DSN=$(cat ./secrets/sentry-dsn.txt) - echo "SENTRY_DSN=$SENTRY_DSN" >> $GITHUB_ENV - echo "::add-mask::$SENTRY_DSN" - fi - - name: Display Build Number run: echo "Number is = ${{ needs.setup.outputs.build_number }}" @@ -248,8 +226,6 @@ jobs: - name: Build and deploy run: | bash scripts/build.sh ${{ env.android_target }} ${{ needs.setup.outputs.build_number }} - env: - SENTRY_DSN: ${{ env.SENTRY_DSN }} - name: Remove Flutter run: | diff --git a/scripts/build.sh b/scripts/build.sh index 6e046f9c4..fdf80af08 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,7 +2,17 @@ set -e set -o pipefail +if [ -f ./secrets/sentry-dsn.txt ]; then + SENTRY_DSN=$(cat ./secrets/sentry-dsn.txt) + export SENTRY_DSN + echo "SENTRY_DSN is successfully read" +else + echo "Error: Sentry DSN file not found" + exit 1 +fi + if [ -z "$SENTRY_DSN" ]; then + echo "Error: env SENTRY_DSN is empty" exit 1 fi From 557b745c35071bb9fd8c573467679c11021aa723 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 23:13:59 +0700 Subject: [PATCH 07/12] build.sh deploy to store only from main --- scripts/build.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 6e046f9c4..073162075 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,15 +2,24 @@ set -e set -o pipefail +deploy_target="$1" +build_number="$2" + +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [[ "$deploy_target" == "ios_store" || "$deploy_target" == "android_store" ]]; then + if [ "$CURRENT_BRANCH" != "main" ]; then + echo "🚫 Error: Deployment to the store is only allowed from the 'main' branch." + exit 1 + fi +fi + if [ -z "$SENTRY_DSN" ]; then exit 1 fi export SENTRY_DSN -deploy_target="$1" -build_number="$2" - if [ -z "$build_number" ]; then echo "Error: Build number is not specified." exit 1 From 6c2c2213c7bcde4502b944cfbb1441e22d68a28d Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 23:21:34 +0700 Subject: [PATCH 08/12] app-deploy.yaml store job check branch to deploy to stores --- .github/workflows/app-deploy.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/app-deploy.yaml b/.github/workflows/app-deploy.yaml index 0704540d4..2a9ddc9d8 100644 --- a/.github/workflows/app-deploy.yaml +++ b/.github/workflows/app-deploy.yaml @@ -34,6 +34,16 @@ jobs: with: fetch-depth: 1 + - name: Check deploy target and branch + run: | + if [[ "${{ github.ref }}" != "refs/heads/main" && + ( "${{ inputs.deploy_target }}" == "store" || + "${{ inputs.deploy_target }}" == "ios_store" || + "${{ inputs.deploy_target }}" == "android_store" ) ]]; then + echo "🚫 Error: Deployment to store, ios_store, or android_store is only allowed from the 'main' branch." + exit 1 + fi + - name: Set output for flutter_version id: set_output run: | From 080e27263ae3e0abe7209dd0b4eb06caff788703 Mon Sep 17 00:00:00 2001 From: knightforce Date: Thu, 5 Sep 2024 23:42:12 +0700 Subject: [PATCH 09/12] Hide language item from menu in profile --- lib/feature/profile/view/profile_view.dart | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/feature/profile/view/profile_view.dart b/lib/feature/profile/view/profile_view.dart index a76e0fddc..9ce75b3de 100644 --- a/lib/feature/profile/view/profile_view.dart +++ b/lib/feature/profile/view/profile_view.dart @@ -81,6 +81,7 @@ class ProfileView extends StatelessWidget { backgroundColor: theme.colors.backgroundAlpha, iconColor: theme.colors.content0, ), + // TODO(knightforce): temp // _profileTile( // leadingIcon: Assets.images.currency.path, // title: LocaleKeys.currencyWord.tr(), @@ -90,20 +91,21 @@ class ProfileView extends StatelessWidget { // // ignore: no-empty-block // onPressed: () {}, // ), - _profileTile( - leadingIcon: Assets.images.planetInner.path, - title: LocaleKeys.languageWord.tr(), - trailing: const Icon( - LucideIcons.chevronRight, - size: DimensSizeV2.d20, - ), - // ignore: no-empty-block - onPressed: () => showLocalizationSheet( - context: context, - ), - backgroundColor: theme.colors.backgroundAlpha, - iconColor: theme.colors.content0, - ), + // TODO(knightforce): temp + // _profileTile( + // leadingIcon: Assets.images.planetInner.path, + // title: LocaleKeys.languageWord.tr(), + // trailing: const Icon( + // LucideIcons.chevronRight, + // size: DimensSizeV2.d20, + // ), + // // ignore: no-empty-block + // onPressed: () => showLocalizationSheet( + // context: context, + // ), + // backgroundColor: theme.colors.backgroundAlpha, + // iconColor: theme.colors.content0, + // ), if (isBiometryAvailable) StreamBuilder( stream: service.enabledStream, From 192d47f804d711a8d0e84199ea54214fa904d687 Mon Sep 17 00:00:00 2001 From: knightforce Date: Fri, 6 Sep 2024 01:20:54 +0700 Subject: [PATCH 10/12] Update build flow --- .github/workflows/app-deploy.yaml | 10 ++++-- melos.yaml | 47 +++++++++++++++++++++---- scripts/build.sh | 57 ++++++++++++++++++++++--------- 3 files changed, 90 insertions(+), 24 deletions(-) diff --git a/.github/workflows/app-deploy.yaml b/.github/workflows/app-deploy.yaml index 5627f4d3a..36c819ff8 100644 --- a/.github/workflows/app-deploy.yaml +++ b/.github/workflows/app-deploy.yaml @@ -149,7 +149,10 @@ jobs: - name: Build and deploy run: | - bash scripts/build.sh ${{ env.ios_target }} ${{ needs.setup.outputs.build_number }} + bash scripts/build.sh \ + --deploy-target ${{ env.ios_target }} \ + --build-number ${{ needs.setup.outputs.build_number }} \ + --upload true - name: Clean Xcode Derived Data run: | @@ -235,7 +238,10 @@ jobs: - name: Build and deploy run: | - bash scripts/build.sh ${{ env.android_target }} ${{ needs.setup.outputs.build_number }} + bash scripts/build.sh \ + --deploy-target ${{ env.android_target }} \ + --build-number ${{ needs.setup.outputs.build_number }} \ + --upload true - name: Remove Flutter run: | diff --git a/melos.yaml b/melos.yaml index 6faf3cf4e..72b4bacae 100644 --- a/melos.yaml +++ b/melos.yaml @@ -109,24 +109,59 @@ scripts: description: Registering new devices already added through devportal run: bash scripts/ios-match-new-devices.sh + build_android_store: + description: Build android store + run: | + bash scripts/build.sh \ + --deploy-target android_store \ + --build-number auto \ + --upload false + deploy_fad_ios: description: Deploy iOS app to fad run: | - BUILD_NUMBER=$(bash scripts/get-build-number.sh) - bash scripts/build.sh ios_fad $BUILD_NUMBER + bash scripts/build.sh \ + --deploy-target ios_fad \ + --build-number auto \ + --upload true deploy_fad_android: description: Deploy Android app to fad run: | - BUILD_NUMBER=$(bash scripts/get-build-number.sh) - bash scripts/build.sh android_fad $BUILD_NUMBER + bash scripts/build.sh \ + --deploy-target android_fad \ + --build-number auto \ + --upload true deploy_fad: description: Deploy app to fad run: | BUILD_NUMBER=$(bash scripts/get-build-number.sh) - bash scripts/build.sh ios_fad $BUILD_NUMBER - bash scripts/build.sh android_fad $BUILD_NUMBER + + bash scripts/build.sh \ + --deploy-target ios_fad \ + --build-number $BUILD_NUMBER \ + --upload true + + bash scripts/build.sh \ + --deploy-target android_fad \ + --build-number $BUILD_NUMBER \ + --upload true + + deploy_store: + description: Deploy app to store + run: | + BUILD_NUMBER=$(bash scripts/get-build-number.sh) + + bash scripts/build.sh \ + --deploy-target ios_store \ + --build-number $BUILD_NUMBER \ + --upload true + + bash scripts/build.sh \ + --deploy-target android_store \ + --build-number $BUILD_NUMBER \ + --upload true command: clean: diff --git a/scripts/build.sh b/scripts/build.sh index 2a9d1bc92..1a82fd895 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,16 +2,35 @@ set -e set -o pipefail -deploy_target="$1" -build_number="$2" +deploy_target="" +build_number="" +upload="false" -CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +while [[ "$#" -gt 0 ]]; do + case $1 in + --deploy-target) deploy_target="$2"; shift ;; + --build-number) build_number="$2"; shift ;; + --upload) upload="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done -if [[ "$deploy_target" == "ios_store" || "$deploy_target" == "android_store" ]]; then - if [ "$CURRENT_BRANCH" != "main" ]; then - echo "🚫 Error: Deployment to the store is only allowed from the 'main' branch." - exit 1 +function build() { + source "scripts/build-binary/$1" +} + +function upload() { + if [[ "$upload" == "true" ]]; then + source "scripts/deploy/$1" fi +} + +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [[ "$upload" == "true" && "$CURRENT_BRANCH" != "main" && ("$deploy_target" == "ios_store" || "$deploy_target" == "android_store") ]]; then + echo "🚫 Error: Deployment to the store is only allowed from the 'main' branch." + exit 1 fi if [ -f ./secrets/sentry-dsn.txt ]; then @@ -30,7 +49,13 @@ fi export SENTRY_DSN -if [ -z "$build_number" ]; then +if [[ "$build_number" == "auto" ]]; then + echo "Build number is 'auto', generating one automatically..." + build_number=$(bash scripts/get-build-number.sh) + echo "Generated Build Number: $build_number" +fi + +if [[ -z "$build_number" || "$build_number" == "auto" ]]; then echo "Error: Build number is not specified." exit 1 fi @@ -42,20 +67,20 @@ source scripts/get-changelog.sh case "$deploy_target" in "ios_fad") - source scripts/build-binary/fad-ipa.sh - source scripts/deploy/fad-ipa.sh + build "fad-ipa.sh" + upload "fad-ipa.sh" ;; "ios_store") - source scripts/build-binary/store-ipa.sh - source scripts/deploy/store-ipa.sh + build "store-ipa.sh" + upload "store-ipa.sh" ;; "android_fad") - source scripts/build-binary/fad-apk.sh - source scripts/deploy/fad-apk.sh + build "fad-apk.sh" + upload "fad-apk.sh" ;; "android_store") - source scripts/build-binary/store-aab.sh - source scripts/deploy/store-aab.sh + build "store-aab.sh" + upload "store-aab.sh" ;; *) echo "Unknown deploy target: $deploy_target" From b484a0dcb4feafec2e4d52b4146e1b29bd8eaf2b Mon Sep 17 00:00:00 2001 From: knightforce Date: Fri, 6 Sep 2024 01:32:42 +0700 Subject: [PATCH 11/12] Update Readme Deploy from local machine section --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 4ff2774b3..3876f3da5 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,19 @@ We also have a workflow for deploying storybook to GitHub Pages. It's called `st ### Deploy from local machine +For deployment from a local machine, melos is used. + +- **build_android_store** - build Android `aab` from any branch +- **deploy_fad_ios** - build and send iOS `ipa` from any branch +- **deploy_fad_android** - build and send Android `apk` from any branch +- **deploy_fad** - build and send Android `apk` and iOS `ipa` from any branch +- **deploy_store** - build and send Android `aab` and iOS `ipa` from the main branch + +The `melos deploy_store*` commands only work from the `main` branch, so as not to accidentally upload unnecessary code to production. + +The `melos build_*` commands work from any branch - in case of manual build. +Unlike `deploy_store*` commands, randomly running `build_*` will only build aab and/or ipa locally and will not push anything extra or untested to the store. + ```sh # To deploy to Firebase App Distribution just run the following command: $ melos build:deploy_fad From a77f24a0c61e3f6a94865f968ab17357949ba3f4 Mon Sep 17 00:00:00 2001 From: knightforce Date: Fri, 6 Sep 2024 01:51:42 +0700 Subject: [PATCH 12/12] Fix android-deploy orders --- .github/workflows/app-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/app-deploy.yaml b/.github/workflows/app-deploy.yaml index 36c819ff8..54b8dee25 100644 --- a/.github/workflows/app-deploy.yaml +++ b/.github/workflows/app-deploy.yaml @@ -176,10 +176,10 @@ jobs: # Android deploy android-deploy: needs: setup + runs-on: ubuntu-latest if: ${{ inputs.deploy_target == 'fad' || inputs.deploy_target == 'store' || inputs.deploy_target == 'android_fad' || inputs.deploy_target == 'android_store' }} - runs-on: ubuntu-latest env: SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }} MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}