Skip to content

Instantly share code, notes, and snippets.

@nilsreichardt
Created January 30, 2022 21:14
Show Gist options
  • Save nilsreichardt/37b8ae8708ab69f7b1cf83634a6cd372 to your computer and use it in GitHub Desktop.
Save nilsreichardt/37b8ae8708ab69f7b1cf83634a6cd372 to your computer and use it in GitHub Desktop.
App previews with Codemagic, but only andorid
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
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 we 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
artifacts:
- build/**/outputs/apk/**/*.apk
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 ENCODED_APK_LINK=$(jq -rn --arg x $APK_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 |
|:-:
| ![image](https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=$ENCODED_APK_LINK) <br /> [Download-Link]($(echo "$APK_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