From 1b28df1991706d421b2474972959a4429e1ba0ff Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Tue, 23 Apr 2024 17:26:53 +0200 Subject: [PATCH] chore: Add Github Action to build iOS app --- .github/workflows/build.yml | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..0f238786 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,123 @@ +--- +name: Build + +on: + workflow_dispatch: + pull_request: + +jobs: + ios: + name: Apple iOS + runs-on: macos-12 + steps: + - name: Setup NuGet + uses: nuget/setup-nuget@296fd3ccf8528660c91106efefe2364482f86d6f # v1.2.0 + with: + nuget-version: 5.9.0 + + - name: Print environment + run: | + nuget help | grep Version + msbuild -version + dotnet --info + echo "GitHub ref: $GITHUB_REF" + echo "GitHub event: $GITHUB_EVENT" + + - name: Checkout repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + submodules: 'true' + + - name: Set up Keychain + env: + KEYCHAIN_PASSWORD: ${{ secrets.IOS_KEYCHAIN_PASSWORD }} + DIST_CERT_PASSWORD: ${{ secrets.IOS_DIST_CERT_P12_PASSWORD }} + run: | + mkdir -p $HOME/secrets + echo ${{ secrets.IOS_DIST_CERT_P12_BASE64 }} | base64 --decode > $HOME/secrets/iphone-distribution-cert.p12 + echo ${{ secrets.IOS_AUTOFILL_PROFILE_BASE_64 }}" | base64 --decode > $HOME/secrets/Cozy_Pass_Autofill_Distribution_Profile.mobileprovision + echo ${{ secrets.IOS_APP_PROFILE_BASE_64 }}" | base64 --decode > $HOME/secrets/Cozy_Pass_Distribution_Profile.mobileprovision + echo ${{ secrets.IOS_EXTENSION_PROFILE_BASE_64 }}" | base64 --decode > $HOME/secrets/Cozy_Pass_Find_Login_Action_Distribution_Profile.mobileprovision + echo ${{ secrets.IOS_SHARE_EXTENSION_PROFILE_BASE_64 }}" | base64 --decode > $HOME/secrets/Cozy_Pass_Share_Extension_Distribution_Profile.mobileprovision + ls $HOME/secrets/ + security create-keychain -p $KEYCHAIN_PASSWORD build.keychain + security default-keychain -s build.keychain + security unlock-keychain -p $KEYCHAIN_PASSWORD build.keychain + security set-keychain-settings -lut 1200 build.keychain + security import ~/secrets/iphone-distribution-cert.p12 -k build.keychain -P $DIST_CERT_PASSWORD \ + -T /usr/bin/codesign -T /usr/bin/security + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $KEYCHAIN_PASSWORD build.keychain + + - name: Set up provisioning profiles + run: | + AUTOFILL_PROFILE_PATH=$HOME/secrets/Cozy_Pass_Autofill_Distribution_Profile.mobileprovision + BITWARDEN_PROFILE_PATH=$HOME/secrets/Cozy_Pass_Distribution_Profile.mobileprovision + EXTENSION_PROFILE_PATH=$HOME/secrets/Cozy_Pass_Find_Login_Action_Distribution_Profile.mobileprovision + SHARE_EXTENSION_PROFILE_PATH=$HOME/secrets/Cozy_Pass_Share_Extension_Distribution_Profile.mobileprovision + PROFILES_DIR_PATH=$HOME/Library/MobileDevice/Provisioning\ Profiles + + mkdir -p "$PROFILES_DIR_PATH" + ls $HOME/secrets/ + + AUTOFILL_UUID=$(grep UUID -A1 -a $AUTOFILL_PROFILE_PATH | grep -io "[-A-F0-9]\{36\}") + cp $AUTOFILL_PROFILE_PATH "$PROFILES_DIR_PATH/$AUTOFILL_UUID.mobileprovision" + + BITWARDEN_UUID=$(grep UUID -A1 -a $BITWARDEN_PROFILE_PATH | grep -io "[-A-F0-9]\{36\}") + cp $BITWARDEN_PROFILE_PATH "$PROFILES_DIR_PATH/$BITWARDEN_UUID.mobileprovision" + + EXTENSION_UUID=$(grep UUID -A1 -a $EXTENSION_PROFILE_PATH | grep -io "[-A-F0-9]\{36\}") + cp $EXTENSION_PROFILE_PATH "$PROFILES_DIR_PATH/$EXTENSION_UUID.mobileprovision" + + SHARE_EXTENSION_UUID=$(grep UUID -A1 -a $SHARE_EXTENSION_PROFILE_PATH | grep -io "[-A-F0-9]\{36\}") + cp $SHARE_EXTENSION_PROFILE_PATH "$PROFILES_DIR_PATH/$SHARE_EXTENSION_UUID.mobileprovision" + + - name: Restore packages + run: nuget restore + + - name: Archive Build for App Store + run: | + $configuration = "AppStore"; + $platform = "iPhone"; + + Write-Output "########################################" + Write-Output "##### Archive $configuration Configuration for $platform Platform" + Write-Output "########################################" + msbuild "$($env:GITHUB_WORKSPACE + "/src/iOS/iOS.csproj")" "/p:Platform=$platform" ` + "/p:Configuration=$configuration" "/p:ArchiveOnBuild=true" "/t:`"Build`"" + + Write-Output "########################################" + Write-Output "##### Done" + Write-Output "########################################" + shell: pwsh + + - name: Export .ipa for App Store + run: | + EXPORT_OPTIONS_PATH="./.github/resources/export-options-app-store.plist" + ARCHIVE_PATH="$HOME/Library/Developer/Xcode/Archives/*/*.xcarchive" + EXPORT_PATH="./bitwarden-export" + + xcodebuild -exportArchive -archivePath $ARCHIVE_PATH -exportPath $EXPORT_PATH \ + -exportOptionsPlist $EXPORT_OPTIONS_PATH + + - name: Upload App Store .ipa + uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 + with: + name: Bitwarden iOS + path: | + ./bitwarden-export/Bitwarden.ipa + if-no-files-found: error + + # - name: Deploy to App Store + # if: | + # (github.ref == 'refs/heads/main' + # && needs.setup.outputs.rc_branch_exists == 0 + # && needs.setup.outputs.hotfix_branch_exists == 0) + # || (github.ref == 'refs/heads/rc' && needs.setup.outputs.hotfix_branch_exists == 0) + # || github.ref == 'refs/heads/hotfix-rc' + # env: + # APPLE_ID_USERNAME: ${{ secrets.APPLE_ID_USERNAME }} + # APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} + # run: | + # xcrun altool --upload-app --type ios --file "./bitwarden-export/Bitwarden.ipa" \ + # --username "$APPLE_ID_USERNAME" --password "$APPLE_ID_PASSWORD" +