Skip to content

Instantly share code, notes, and snippets.

@nilsreichardt
Last active February 11, 2022 14:55
Show Gist options
  • Save nilsreichardt/a21644024ff1cb24b7470706246f23a3 to your computer and use it in GitHub Desktop.
Save nilsreichardt/a21644024ff1cb24b7470706246f23a3 to your computer and use it in GitHub Desktop.
App preview for every pull request commit
# Note: iOS app previews are only available with Codemagic teams.
# IPA needs to be signed. Docs for signing: https://docs.codemagic.io/yaml-code-signing/signing-ios/
#
# You need to add your GitHub PAT as environment variable to Codemaigc.
# Docs to create PAT: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
workflows:
app-preview:
name: App Preview
instance_type: mac_pro
max_build_duration: 75
environment:
groups:
- github
- ios-publishing
- certificate_credentials
vars:
BUNDLE_ID: com.example.flutter
flutter: v2.8.1
triggering:
events:
- pull_request
scripts:
- name: Install dependencies
script: flutter pub get
- name: Build APK
script: flutter build apk --profile
- name: iOS Code signing
script: |
keychain initialize
app-store-connect fetch-signing-files "$BUNDLE_ID" --type IOS_APP_ADHOC --create
keychain add-certificates
xcode-project use-profiles
- name: Build IPA
script: flutter build ipa --release --export-options-plist=/Users/builder/export_options.plist
artifacts:
- build/**/outputs/apk/**/*.apk
- build/ios/ipa/*.ipa
publishing:
scripts:
- name: Authenticate GitHub CLI
script: |
echo $GITHUB_PAT > gh_credentials.txt
gh auth login --with-token < gh_credentials.txt
rm gh_credentials.txt
- name: Post builds to GitHub PR
script: |
export APK_LINK=$(echo $FCI_ARTIFACT_LINKS | jq '.[1] | .url')
export IPA_LINK=$(echo $FCI_ARTIFACT_LINKS | jq '.[0] | .url')
export ENCODED_APK_LINK=$(jq -rn --arg x $APK_LINK '$x|@uri')
export ENCODED_IPA_LINK=$(jq -rn --arg x $IPA_LINK '$x|@uri')
read -r -d '' COMMENT << EOM
⬇️ Generated builds by [Codemagic](https://codemagic.io/app/$FCI_PROJECT_ID/build/$FCI_BUILD_ID) for commit \`$FCI_COMMIT\` ⬇️
| Android | iOS |
|:-:|:-:|
| ![image](https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=$ENCODED_APK_LINK) <br /> [Download-Link]($(echo "$APK_LINK" | tr -d '"')) | ![image](https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=$ENCODED_IPA_LINK) <br /> [Download-Link]($(echo "$IPA_LINK" | tr -d '"')) |
EOM
gh pr comment $FCI_PULL_REQUEST_NUMBER -b "$COMMENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment