diff --git a/.github/actions/build_android/action.yml b/.github/actions/build_android/action.yml index 4e06c7077..68ab7f90b 100644 --- a/.github/actions/build_android/action.yml +++ b/.github/actions/build_android/action.yml @@ -10,12 +10,6 @@ inputs: store_artifacts: required: false description: "Store artifact" - build_type: - required: false - default: "dev" - options: - - dev - - prod signingKeyBase64: required: true description: "Android signing key b64" @@ -28,10 +22,23 @@ inputs: keyPassword: required: true description: "Android key password" + build_type: + required: true + description: > + Whether to build a development or production version of the app. + A 'development' build connects to the development backend for testing, + while a 'production' build connects to the production backend. + It is an error to specify a build type other than + 'development' or 'production'. runs: using: "composite" steps: + - name: Validate build_type + uses: ./.github/actions/verify_build_type + with: + build_type: ${{ inputs.build_type }} + - name: Setup Java uses: actions/setup-java@v3.13.0 with: @@ -41,17 +48,17 @@ runs: - name: Setup Flutter environment uses: ./.github/actions/setup_flutter_environment with: - prod_release: ${{ inputs.prod_release }} + build_type: ${{ inputs.build_type }} - - name: Build apk (dev) - if: ${{ inputs.build_type == 'dev' }} + - name: "[dev] Build Android app (apk)" + if: ${{ inputs.build_type == 'development' }} run: | flutter build apk --flavor development --release --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_development.dart mv build/app/outputs/flutter-apk/app-development-release.apk android.apk shell: bash - - name: Build appbundle (prod) - if: ${{ inputs.build_type == 'prod' }} + - name: "[prod] Build Android app (app bundle)" + if: ${{ inputs.build_type == 'production' }} run: | flutter build appbundle --flavor production --release --build-name ${{ inputs.version }} --build-number ${{ inputs.build_version }} --target lib/main_production.dart mv build/app/outputs/bundle/productionRelease/app-production-release.aab android.aab @@ -68,8 +75,8 @@ runs: keyStorePassword: ${{ inputs.keyStorePassword }} keyPassword: ${{ inputs.keyPassword }} - - name: Upload appbundle - if: ${{ !!inputs.store_artifacts && inputs.build_type == 'prod'}} + - name: "[prod] Upload app bundle" + if: ${{ !!inputs.store_artifacts && inputs.build_type == 'production'}} uses: actions/upload-artifact@v3.1.3 with: name: android @@ -77,17 +84,17 @@ runs: retention-days: 1 if-no-files-found: error - - name: Move apk - if: ${{ !!inputs.store_artifacts && inputs.build_type != 'prod'}} + - name: "[dev] Move apk file" + if: ${{ !!inputs.store_artifacts && inputs.build_type == 'development'}} run: | mv ${{steps.sign_app.outputs.signedReleaseFile}} android.apk shell: bash - - name: Upload apk - if: ${{ !!inputs.store_artifacts && inputs.build_type != 'prod'}} + - name: "[dev] Upload apk" + if: ${{ !!inputs.store_artifacts && inputs.build_type == 'development'}} uses: actions/upload-artifact@v3.1.3 with: name: android path: android.apk retention-days: 1 - if-no-files-found: error \ No newline at end of file + if-no-files-found: error diff --git a/.github/actions/build_ios/action.yml b/.github/actions/build_ios/action.yml index 58094b16f..2ed6ea791 100644 --- a/.github/actions/build_ios/action.yml +++ b/.github/actions/build_ios/action.yml @@ -23,17 +23,24 @@ inputs: required: true description: "Store artifact" build_type: - required: false - default: "dev" - options: - - dev - - prod + required: true + description: > + Whether to build a development or production version of the app. + A 'development' build connects to the development backend for testing, + while a 'production' build connects to the production backend. + It is an error to specify a build type other than + 'development' or 'production'. runs: using: "composite" steps: - - name: Install Apple certificate and provisioning profile - if: ${{ inputs.prod_release != 'true' }} + - name: Validate build_type + uses: ./.github/actions/verify_build_type + with: + build_type: ${{ inputs.build_type }} + + - name: "[dev] Install Apple certificate and provisioning profile" + if: ${{ inputs.build_type == 'development' }} run: .github/scripts/setup_certs.sh env: APPLE_IOS_SIGNING_CERT: ${{ inputs.apple_ios_signing_cert }} @@ -45,15 +52,15 @@ runs: - name: Setup Flutter environment uses: ./.github/actions/setup_flutter_environment with: - prod_release: ${{ inputs.build_type == 'prod' }} + build_type: ${{ inputs.build_type }} - - name: Build iOS (dev) - if: ${{ inputs.build_type != 'prod' }} + - name: "[dev] Build iOS app" + if: ${{ inputs.build_type == 'development' }} run: .github/scripts/build_ios_dev.sh ${{ inputs.version }} ${{ inputs.build_version }} shell: bash - - name: Build iOS (prod) - if: ${{ inputs.build_type == 'prod' }} + - name: "[prod] Build iOS app" + if: ${{ inputs.build_type == 'production' }} run: .github/scripts/build_ios_prod.sh ${{ inputs.version }} ${{ inputs.build_version }} shell: bash @@ -64,4 +71,4 @@ runs: name: ios path: build-output/ios retention-days: 1 - if-no-files-found: error \ No newline at end of file + if-no-files-found: error diff --git a/.github/actions/setup_flutter_environment/action.yml b/.github/actions/setup_flutter_environment/action.yml index 93fdfa4df..20ec2f6d1 100644 --- a/.github/actions/setup_flutter_environment/action.yml +++ b/.github/actions/setup_flutter_environment/action.yml @@ -1,32 +1,38 @@ name: Setup Flutter environment description: Setup the Flutter environment inputs: - prod_release: - required: false - default: 'false' - description: "Is prod release" - -env: - FLUTTER_VERSION: 3.13.7 + build_type: + required: true + description: > + Whether to build a development or production version of the app. + A 'development' build connects to the development backend for testing, + while a 'production' build connects to the production backend. + It is an error to specify a build type other than + 'development' or 'production'. runs: using: "composite" steps: + - name: Validate build_type + uses: ./.github/actions/verify_build_type + with: + build_type: ${{ inputs.build_type }} + - name: Setup Flutter environment uses: subosito/flutter-action@v2.11.0 with: - flutter-version: ${{ env.FLUTTER_VERSION }} + flutter-version: 3.16.0 channel: "stable" - name: Download dependencies run: flutter pub get shell: bash - - name: Replace target URI in Production - if: ${{ inputs.prod_release == 'true' }} + - name: "[prod] Change target backend to production" + if: ${{ inputs.build_type == 'production' }} run: sed -i'' -e 's/.env.develop/.env.production/' lib/env/env.dart shell: bash - name: Generate code run: dart run build_runner build - shell: bash \ No newline at end of file + shell: bash diff --git a/.github/actions/verify_build_type/action.yml b/.github/actions/verify_build_type/action.yml new file mode 100644 index 000000000..911a958f2 --- /dev/null +++ b/.github/actions/verify_build_type/action.yml @@ -0,0 +1,24 @@ +name: Verify build type +description: Verify that the build type is either 'development' or 'production' + +inputs: + build_type: + required: true + description: > + Whether to build a development or production version of the app. + A 'development' build connects to the development backend for testing, + while a 'production' build connects to the production backend. + It is an error to specify a build type other than + 'development' or 'production'. + +runs: + using: "composite" + steps: + - name: Validate build_type + run: | + if [[ "${{ inputs.build_type }}" != "development" && "${{ inputs.build_type }}" != "production" ]]; then + echo "Error: build_type must be 'development' or 'production'" + exit 1 + fi + echo "Build type: ${{ inputs.build_type }}" + shell: bash diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b8fce2f8..c350386e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,8 +14,13 @@ on: required: true build_type: type: string - required: false - default: "dev" + required: true + description: > + Whether to build a development or production version of the app. + A 'development' build connects to the development backend for testing, + while a 'production' build connects to the production backend. + It is an error to specify a build type other than + 'development' or 'production'. jobs: version: @@ -23,6 +28,14 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v4.1.0 + + - name: Validate build_type + uses: ./.github/actions/verify_build_type + with: + build_type: ${{ inputs.build_type }} + - name: Determine build version id: build_version run: | @@ -51,8 +64,8 @@ jobs: - name: Checkout code uses: actions/checkout@v4.1.0 - - name: Build iOS app (dev) - if: ${{ inputs.build_type != 'prod' }} + - name: "[dev] Build iOS app" + if: ${{ inputs.build_type == 'development' }} uses: ./.github/actions/build_ios with: version: ${{ needs.version.outputs.version }} @@ -64,8 +77,8 @@ jobs: store_artifacts: ${{ inputs.store_artifacts }} build_type: ${{ inputs.build_type }} - - name: Build iOS app (prod) - if: ${{ inputs.build_type == 'prod' }} + - name: "[prod] Build iOS app" + if: ${{ inputs.build_type == 'production' }} uses: ./.github/actions/build_ios with: version: ${{ needs.version.outputs.version }} diff --git a/.github/workflows/release-dev.yml b/.github/workflows/release-dev.yml index e79275147..98651a30e 100644 --- a/.github/workflows/release-dev.yml +++ b/.github/workflows/release-dev.yml @@ -9,7 +9,7 @@ jobs: uses: ./.github/workflows/build.yml with: store_artifacts: true - build_type: "dev" + build_type: development tag_name: ${{ github.head_ref }} secrets: inherit diff --git a/.github/workflows/release-prod.yml b/.github/workflows/release-prod.yml index 4a8f24829..871e82270 100644 --- a/.github/workflows/release-prod.yml +++ b/.github/workflows/release-prod.yml @@ -9,7 +9,7 @@ jobs: uses: ./.github/workflows/build.yml with: store_artifacts: true - build_type: "prod" + build_type: production tag_name: ${{ github.event.release.tag_name }} secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34e3cfa08..7ea0da804 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,8 @@ jobs: - name: Setup Flutter environment uses: ./.github/actions/setup_flutter_environment + with: + build_type: development - name: Check formatting run: dart format --set-exit-if-changed lib/