ilyalehchylin/educats-xamarin

View on GitHub
.github/workflows/pre-release.yml

Summary

Maintainability
Test Coverage
name: pre-release

on:
  workflow_call:
    outputs:
      app_version_number:
        description: "The application version number"
        value: ${{ jobs.prepare_build.outputs.app_version }}
      app_build_number:
        description: "The application build number"
        value: ${{ jobs.prepare_build.outputs.incremented_build_number }}
  workflow_dispatch:
  push:
    branches:
      - develop

env:
  ARTIFACTS_DIRECTORY: ./artifacts
  RELEASE_BUILD_CONFIGURATION: Release

jobs:
  test:
    runs-on: macos-latest
    environment: github-actions-release
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.7
    
      - name: Unit-Tests
        run: dotnet test $PROJECT_PATH
        env:
          PROJECT_PATH: ./source/EduCATS.UnitTests/EduCATS.UnitTests.csproj
          
  prepare_build:
    runs-on: macos-latest
    environment: github-actions-release
    needs: test
    outputs:
      app_version: ${{ steps.app_version_setup.outputs.app_version }}
      incremented_build_number: ${{ steps.increase_build_number.outputs.app_build_number }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.7
        
      - name: Setup App Version
        id: app_version_setup
        run: |
          APP_VERSION=$(cat ./VERSION)
          echo $APP_VERSION
          echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
        
      - name: Increase Build Number
        id: increase_build_number
        run: |
          APP_BUILD_NUMBER_INCREMENTED=$(($APP_BUILD_NUMBER+1))
          echo $APP_BUILD_NUMBER_INCREMENTED
          echo "APP_BUILD_NUMBER_INCREMENTED=$APP_BUILD_NUMBER_INCREMENTED" >> $GITHUB_ENV
          echo "app_build_number=$APP_BUILD_NUMBER_INCREMENTED" >> $GITHUB_OUTPUT
        env:
          APP_BUILD_NUMBER: ${{ secrets.APP_BUILD_NUMBER }}  
      
      - name: App Build Secret Update
        uses: gliech/create-github-secret-action@v1.4.10
        with:
          pa_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          name: APP_BUILD_NUMBER
          value: ${{ env.APP_BUILD_NUMBER_INCREMENTED }}
          
  build_apk:
    runs-on: macos-13
    environment: github-actions-release
    needs: prepare_build
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.7

      - name: Setup Xamarin
        run: |
          brew install --cask xamarin-ios
          brew install --cask xamarin-android
        
      - name: NuGet Cache
        uses: actions/cache@v4.0.2
        with:
          path: ~/.nuget/packages
          key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
          restore-keys: |
            ${{ runner.os }}-nuget-
        
      - name: NuGet Restore
        run: nuget restore $SOLUTION_PATH
        env:
          SOLUTION_PATH: ./source/EduCATS.sln
      
      - name: Artifacts Directory Setup
        run: mkdir ${{ env.ARTIFACTS_DIRECTORY }}
          
      - name: Android Signing Setup
        run: (echo ${{ secrets.ANDROID_KEYSTORE_FILE }} | base64 --decode) > $KEYSTORE
        env:
          KEYSTORE: ./source/EduCATS.Android/educats-release.keystore
          
      - name: AndroidManifest Version Update
        uses: damienaicheh/update-android-version-manifest-action@v1.1.0
        with:
          android-manifest-path: ./source/EduCATS.Android/Properties/AndroidManifest.xml
          version-name: ${{ needs.prepare_build.outputs.app_version }}
          version-code: ${{ needs.prepare_build.outputs.incremented_build_number }}
      
      - name: Android Build (apk)
        run: |
          MSBuild /t:SignAndroidPackage /p:Configuration=${{ env.RELEASE_BUILD_CONFIGURATION }} /p:AndroidPackageFormat=apk /p:AndroidKeyStore=true /p:AndroidSigningKeyAlias='${{ secrets.ANDROID_KEYSTORE_ALIAS }}' /p:AndroidSigningKeyPass='${{ secrets.ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }}' /p:AndroidSigningKeyStore=$KEYSTORE_FILENAME /p:AndroidSigningStorePass='${{ secrets.ANDROID_KEYSTORE_PASSWORD }}' $PROJECT_PATH
          cp $APK_FILE_PATH $ARTIFACTS_APK_PATH
        env:
          PROJECT_PATH: ./source/EduCATS.Android/EduCATS.Android.csproj
          KEYSTORE_FILENAME: educats-release.keystore
          APK_FILE_PATH: ./source/EduCATS.Android/bin/Release/by.bntu.educats-Signed.apk
          ARTIFACTS_APK_PATH: ${{ env.ARTIFACTS_DIRECTORY }}/by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.apk
          
      - name: Upload APK Artifact
        uses: actions/upload-artifact@v4
        with:
          name: by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.apk
          path: ${{ env.ARTIFACTS_DIRECTORY }}/by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.apk
        
  build_aab:
    runs-on: macos-13
    environment: github-actions-release
    needs: prepare_build
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.7

      - name: Setup Xamarin
        run: |
          brew install --cask xamarin-ios
          brew install --cask xamarin-android
        
      - name: NuGet Cache
        uses: actions/cache@v4.0.2
        with:
          path: ~/.nuget/packages
          key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
          restore-keys: |
            ${{ runner.os }}-nuget-
        
      - name: NuGet Restore
        run: nuget restore $SOLUTION_PATH
        env:
          SOLUTION_PATH: ./source/EduCATS.sln
      
      - name: Artifacts Directory Setup
        run: mkdir ${{ env.ARTIFACTS_DIRECTORY }}
          
      - name: Android Signing Setup
        run: (echo ${{ secrets.ANDROID_KEYSTORE_FILE }} | base64 --decode) > $KEYSTORE
        env:
          KEYSTORE: ./source/EduCATS.Android/educats-release.keystore
          
      - name: AndroidManifest Version Update
        uses: damienaicheh/update-android-version-manifest-action@v1.1.0
        with:
          android-manifest-path: ./source/EduCATS.Android/Properties/AndroidManifest.xml
          version-name: ${{ needs.prepare_build.outputs.app_version }}
          version-code: ${{ needs.prepare_build.outputs.incremented_build_number }}
      
      - name: Android Build (aab)
        run: |
          MSBuild /t:SignAndroidPackage /p:Configuration=${{ env.RELEASE_BUILD_CONFIGURATION }} /p:AndroidPackageFormat=aab /p:AndroidKeyStore=true /p:AndroidSigningKeyAlias='${{ secrets.ANDROID_KEYSTORE_ALIAS }}' /p:AndroidSigningKeyPass='${{ secrets.ANDROID_KEYSTORE_PRIVATE_KEY_PASSWORD }}' /p:AndroidSigningKeyStore=$KEYSTORE_FILENAME /p:AndroidSigningStorePass='${{ secrets.ANDROID_KEYSTORE_PASSWORD }}' $PROJECT_PATH
          cp $AAB_FILE_PATH $ARTIFACTS_AAB_PATH
        env:
          PROJECT_PATH: ./source/EduCATS.Android/EduCATS.Android.csproj
          KEYSTORE_FILENAME: educats-release.keystore
          AAB_FILE_PATH: ./source/EduCATS.Android/bin/Release/by.bntu.educats-Signed.aab
          ARTIFACTS_AAB_PATH: ${{ env.ARTIFACTS_DIRECTORY }}/by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.aab
          
      - name: Upload AAB Artifact
        uses: actions/upload-artifact@v4
        with:
          name: by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.aab
          path: ${{ env.ARTIFACTS_DIRECTORY }}/by.bntu.educats_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.aab
        
  build_ipa:
    runs-on: macos-13
    environment: github-actions-release
    needs: prepare_build
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.7

      - name: Setup Xamarin
        run: |
          brew install --cask xamarin-ios
          brew install --cask xamarin-android
        
      - name: NuGet Cache
        uses: actions/cache@v4.0.2
        with:
          path: ~/.nuget/packages
          key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
          restore-keys: |
            ${{ runner.os }}-nuget-
        
      - name: NuGet Restore
        run: nuget restore $SOLUTION_PATH
        env:
          SOLUTION_PATH: ./source/EduCATS.sln
      
      - name: Artifacts Directory Setup
        run: mkdir ${{ env.ARTIFACTS_DIRECTORY }}
        
      - name: iOS Certificates Install
        uses: apple-actions/import-codesign-certs@v3
        with: 
          p12-file-base64: ${{ secrets.IOS_CERTIFICATE_APPSTORE }}
          p12-password: ${{ secrets.IOS_CERTIFICATE_APPSTORE_PASSWORD }}
          keychain: github-actions-xamarin
          keychain-password: ''
      
      - name: iOS Provisioning Profiles Install
        uses: akiojin/install-provisioning-profile-github-action@v1.0
        with:
          base64: ${{ secrets.IOS_PROVISIONING_PROFILE_APPSTORE }}
      
      - name: Info.plist Version Update
        uses: damienaicheh/update-ios-version-info-plist-action@v1.2.0
        with:
          info-plist-path: ./source/EduCATS.iOS/Info.plist
          bundle-version: ${{ needs.prepare_build.outputs.incremented_build_number }}
          bundle-short-version-string: ${{ needs.prepare_build.outputs.app_version }}
          
      - name: iOS Build (ipa)
        run: |
          MSBuild /t:Build /p:Configuration=${{ env.RELEASE_BUILD_CONFIGURATION }} /p:Platform=$PLATFORM /p:BuildIpa=true $PROJECT_PATH
          cp $IPA_PATH $ARTIFACTS_IPA_PATH
        env:
          PLATFORM: iPhone
          PROJECT_PATH: ./source/EduCATS.iOS/EduCATS.iOS.csproj
          IPA_PATH: ./source/EduCATS.iOS/bin/iPhone/Release/EduCATS.iOS.ipa
          ARTIFACTS_IPA_PATH: ${{ env.ARTIFACTS_DIRECTORY }}/EduCATS_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.ipa
          
      - name: Upload IPA Artifact
        uses: actions/upload-artifact@v4
        with:
          name: EduCATS_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.ipa
          path: ${{ env.ARTIFACTS_DIRECTORY }}/EduCATS_${{ needs.prepare_build.outputs.app_version }}.${{ needs.prepare_build.outputs.incremented_build_number }}.ipa
     
  deploy_google_play:
    runs-on: macos-latest
    environment: github-actions-release
    needs: build_aab
    steps:
      - name: Artifacts Download
        uses: actions/download-artifact@v4
        
      - name: Google Play Deploy
        id: google_play_deploy
        continue-on-error: true
        uses: r0adkll/upload-google-play@v1.1.3
        with:
          serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_API_JSON_PLAIN }}
          packageName: by.bntu.educats
          releaseFiles: ./*.aab/*.aab
          track: beta
          changesNotSentForReview: true
          status: draft
          
      - name: Google Play Deploy On Failure
        uses: r0adkll/upload-google-play@v1.1.3
        if: always() && steps.google_play_deploy.outcome == 'failure'
        with:
          serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_API_JSON_PLAIN }}
          packageName: by.bntu.educats
          releaseFiles: ./*.aab/*.aab
          track: beta
          status: draft
          
  deploy_appstore:
    runs-on: macos-latest
    environment: github-actions-release
    needs: build_ipa
    steps:
      - name: Artifacts Download
        uses: actions/download-artifact@v4
        
      - name: AppStore Deploy
        run: xcrun altool --upload-app -f $IPA_FILE_PATH --type ios -u ${{ secrets.APPLE_ID }} -p ${{ secrets.APPLE_SPECIFIC_PASSWORD }}
        env:
          IPA_FILE_PATH: ./*.ipa/*.ipa