Skip to content

Instantly share code, notes, and snippets.

@nilsreichardt
Last active January 30, 2022 20:31
Show Gist options
  • Save nilsreichardt/58fef5bc4432accff37832da64a987c4 to your computer and use it in GitHub Desktop.
Save nilsreichardt/58fef5bc4432accff37832da64a987c4 to your computer and use it in GitHub Desktop.
app-preview-articel
workflows:
app-preview:
name: App Preview
# All available instance types:
# https://docs.codemagic.io/yaml/yaml-getting-started/#instance-type
instance_type: mac_pro
max_build_duration: 75
environment:
groups:
- github
- ios-publishing
- certificate_credentials
vars:
# IMPORTANT: Insert here your bundle id!
BUNDLE_ID: com.flutter.example
flutter: v2.8.1
when:
# We skipping the app preview for draft pull request to save Codemagic
# build seats.
condition: event.pull_request.draft == false
triggering:
events:
- pull_request
# We canceling the previous build, so save Codemagic build seats. This
# means, if we first push commit "A" and after a few minutes commit "B" to
# the pull request, will be the build for commit "A" canceled.
cancel_previous_builds: true
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