Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Archive the mobile app & save it in GitHub release (#7)
Browse files Browse the repository at this point in the history
* Attempt to generate archive

* cd

* Add -allowProvisioningUpdates

* Add keychain stuff

* Messed up the file naming

Archive succeeded on previous build

* Attempt to store ipa in release

* Change dot to dash in time

* Clean up archiving & GitHub release
  • Loading branch information
ljhaywar authored May 18, 2021
1 parent 7a64bfe commit b9a7547
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ jobs:
steps:
- uses: actions/checkout@v2
# Setting env vars based on https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
- name: "Get current time to use later"
run: echo "CURRENT_TIME=$(date +'%Y-%m-%d_%s')" >> $GITHUB_ENV
- name: "Are we pushing to the Main branch?"
if: ${{ github.ref == 'refs/heads/main' }}
run: |
echo "REALM_APP_ID=inventorysync-ctnnu" >> $GITHUB_ENV
# echo "IS_DYNAMICALLY_GENERATED_APP=false" >> $GITHUB_ENV
- name: "Are we pushing to the Staging branch?"
if: ${{ github.ref == 'refs/heads/staging' }}
run: |
echo "REALM_APP_ID=inventorydemo-staging-zahjj" >> $GITHUB_ENV
# echo "IS_DYNAMICALLY_GENERATED_APP=false" >> $GITHUB_ENV
# For Pull Requests, update the database name to be a unique name based on the current date and time
# Also, set the environment to be the Testing envrionment
- name: "Set environment variables for all other runs"
if: ${{ !env.REALM_APP_ID }}
run: |
cd inventory/export/sync/environments
time=$(date +%s%N)
printf '{\n "values": {"databaseName": "InventoryDemo-%s"}\n}' "$time" > testing.json
printf '{\n "values": {"databaseName": "InventoryDemo-%s"}\n}' "${{ env.CURRENT_TIME }}" > testing.json
cd ..
sed -i txt 's/{/{ "environment": "testing",/' realm_config.json
echo "IS_DYNAMICALLY_GENERATED_APP=true" >> $GITHUB_ENV
Expand Down Expand Up @@ -58,18 +57,68 @@ jobs:
output=$(realm-cli app describe)
app_id=$(echo $output | sed 's/^.*client_app_id": "\([^"]*\).*/\1/')
echo "REALM_APP_ID=$app_id" >> $GITHUB_ENV
- name: "Build mobile app & run tests"
run: |
echo "the realm app id is: $REALM_APP_ID"
cd inventory/clients/ios-swiftui/InventoryDemo
xcodebuild -project InventoryDemo.xcodeproj -scheme "ci" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12 Pro Max,OS=14.4' -derivedDataPath './output' REALM_APP_ID='${{ env.REALM_APP_ID }}' test
# This step taken from https://docs.github.com/en/actions/guides/installing-an-apple-certificate-on-macos-runners-for-xcode-development
- name: "Install the Apple certificate and provisioning profile (so we can create the archive)"
if: ${{ github.ref == 'refs/heads/main' }}
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output $CERTIFICATE_PATH
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode --output $PP_PATH
# create temporary keychain
security create-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P $P12_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# apply provisioning profile
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
- name: "Archive the mobile app"
if: ${{ github.ref == 'refs/heads/main' }}
run: |
cd inventory/clients/ios-swiftui/InventoryDemo
echo ${{ env.REALM_APP_ID }}
xcodebuild -workspace InventoryDemo.xcodeproj/project.xcworkspace/ -scheme ci archive REALM_APP_ID=${{ env.REALM_APP_ID }} -archivePath $PWD/build/ci.xcarchive -allowProvisioningUpdates
xcodebuild -exportArchive -archivePath $PWD/build/ci.xcarchive -exportPath $PWD/build -exportOptionsPlist $PWD/build/ci.xcarchive/Info.plist
# This step stores the archive in a GitHub release.
# Alternatively, you could upload the app directly for beta testing and/or release
- name: "Store the Archive in a GitHub Release"
uses: softprops/action-gh-release@v1
if: ${{ github.ref == 'refs/heads/main' }}
with:
files: |
inventory/clients/ios-swiftui/InventoryDemo/build/InventoryDemo.ipa
tag_name: ${{ env.CURRENT_TIME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: "Build mobile app & run tests"
# run: |
# echo "the realm app id is: $REALM_APP_ID"
# cd inventory/clients/ios-swiftui/InventoryDemo
# xcodebuild -project InventoryDemo.xcodeproj -scheme "ci" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12 Pro Max,OS=14.4' -derivedDataPath './output' REALM_APP_ID='${{ env.REALM_APP_ID }}' test

# Could choose to skip deleting apps where tests fail so you could manually investigate
# Not currently working due to a bug in the realm-cli
# Not currently working due to a bug in the realm-cli. Also need to delete mobile database
# - name: "Delete dynamically generated Realm app"
# if: ${{ env.IS_DYNAMICALLY_GENERATED_APP }}
# run: realm-cli app delete -a $REALM_APP_ID

# After the tests pass, push commits from the staging branch to the main branch
pushToProdBranch:
runs-on: macos-latest
needs: build
Expand All @@ -84,3 +133,4 @@ jobs:
run: |
git merge origin/staging
git push

0 comments on commit b9a7547

Please sign in to comment.