Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart
11.7 KB
Raw Blame
definitions:
  scripts:
    - &notify_discord_start
      name: Notify Discord (build started)
      script: |
        if [ -z "$DISCORD_WEBHOOK_URL" ]; then exit 0; fi
        VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
        curl -sS -X POST "$DISCORD_WEBHOOK_URL" \
          -H "Content-Type: application/json" \
          -d "{\"embeds\":[{\"title\":\"Build started\",\"description\":\"**$CM_WORKFLOW_NAME** v$VERSION\\n[Build log]($CM_BUILD_URL)\",\"color\":3447003}]}" \
          > /dev/null 2>&1 || true

    - &notify_discord_end
      name: Notify Discord (build finished)
      script: |
        if [ -z "$DISCORD_WEBHOOK_URL" ]; then exit 0; fi
        VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
        if [ "$CM_BUILD_STATUS" = "success" ]; then
          TITLE="Build successful"
          COLOR=3066993
        else
          TITLE="Build failed"
          COLOR=15158332
        fi
        curl -sS -X POST "$DISCORD_WEBHOOK_URL" \
          -H "Content-Type: application/json" \
          -d "{\"embeds\":[{\"title\":\"$TITLE\",\"description\":\"**$CM_WORKFLOW_NAME** v$VERSION\\n[Build log]($CM_BUILD_URL)\",\"color\":$COLOR}]}" \
          > /dev/null 2>&1 || true

workflows:
  github-release:
    name: GitHub APK Only
    max_build_duration: 60
    instance_type: mac_mini_m2
    environment:
      android_signing:
        - absorb_keystore
      groups:
        - github_credentials
        - discord_notifications
      flutter: stable
      java: 17
    scripts:
      - *notify_discord_start
      - name: Set up key.properties
        script: |
          cat >> $CM_BUILD_DIR/android/key.properties <<EOF
          storePassword=$CM_KEYSTORE_PASSWORD
          keyPassword=$CM_KEY_PASSWORD
          keyAlias=$CM_KEY_ALIAS
          storeFile=$CM_KEYSTORE_PATH
          EOF
      - name: Build universal and split GitHub APKs
        script: bash scripts/build-github-apks
      - name: Publish to GitHub Draft Release
        script: |
          VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
          UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
          if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
            gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
          else
            gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
          fi
          for apk in build/app/outputs/apk/github/release/*.apk; do
            [ "$apk" = "$UNIVERSAL" ] && continue
            gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
          done
    artifacts:
      - build/app/outputs/apk/github/release/*.apk
    publishing:
      scripts:
        - *notify_discord_end

  android-release:
    name: Android Release (GitHub + Play Store)
    max_build_duration: 60
    instance_type: mac_mini_m2
    environment:
      android_signing:
        - absorb_keystore
      groups:
        - github_credentials
        - discord_notifications
      flutter: stable
      java: 17
    scripts:
      - *notify_discord_start
      - name: Set up key.properties
        script: |
          cat >> $CM_BUILD_DIR/android/key.properties <<EOF
          storePassword=$CM_KEYSTORE_PASSWORD
          keyPassword=$CM_KEY_PASSWORD
          keyAlias=$CM_KEY_ALIAS
          storeFile=$CM_KEYSTORE_PATH
          EOF
      - name: Build universal and split GitHub APKs
        script: bash scripts/build-github-apks
      - name: Build Play Store AAB
        script: flutter build appbundle --release --flavor playstore --dart-define=PLAYSTORE_BUILD=true
      - name: Rename AAB with version
        script: |
          RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
          AAB_SRC=$(ls build/app/outputs/bundle/playstoreRelease/*.aab | head -1)
          mv "$AAB_SRC" "build/app/outputs/bundle/playstoreRelease/absorb-${RAW}.aab"
      - name: Publish to GitHub Draft Release
        script: |
          VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
          UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
          if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
            gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
          else
            gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
          fi
          for apk in build/app/outputs/apk/github/release/*.apk; do
            [ "$apk" = "$UNIVERSAL" ] && continue
            gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
          done
          for aab in build/app/outputs/bundle/playstoreRelease/*.aab; do
            gh release upload "$VERSION" "$aab" --clobber --repo "$CM_REPO_SLUG"
          done
    artifacts:
      - build/app/outputs/apk/github/release/*.apk
      - build/app/outputs/bundle/playstoreRelease/*.aab
    publishing:
      scripts:
        - *notify_discord_end

  ios-release:
    name: iOS Release
    max_build_duration: 60
    instance_type: mac_mini_m2
    integrations:
      app_store_connect: Apple Dev Key
    environment:
      ios_signing:
        distribution_type: app_store
        bundle_identifier: com.barnabas.absorb
      groups:
        - github_credentials
        - discord_notifications
      flutter: stable
      xcode: latest
    scripts:
      - *notify_discord_start
      - name: Set up code signing
        script: xcode-project use-profiles
      - name: Build IPA
        script: flutter build ipa --release --export-options-plist=/Users/builder/export_options.plist
      - name: Rename IPA with version
        script: |
          RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
          IPA_SRC=$(ls build/ios/ipa/*.ipa | head -1)
          mv "$IPA_SRC" "build/ios/ipa/absorb-${RAW}.ipa"
      - name: Publish IPA to GitHub Draft Release
        script: |
          VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
          if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
            gh release upload "$VERSION" \
              build/ios/ipa/*.ipa \
              --clobber \
              --repo "$CM_REPO_SLUG"
          else
            gh release create "$VERSION" \
              build/ios/ipa/*.ipa \
              --draft \
              --title "$VERSION" \
              --repo "$CM_REPO_SLUG"
          fi
      - name: Publish to TestFlight
        script: |
          # Replaces the auto `publishing.app_store_connect.submit_to_testflight`
          # so we can attach optional TestFlight "What to Test" notes
          # (BETA_TEST_NOTES) and assign the build to a beta group
          # (BETA_GROUP). Caller (scripts/codemagic-ios.sh) sets the env vars
          # when triggering; if unset, the build is uploaded without them.
          IPA_PATH=$(ls build/ios/ipa/*.ipa | head -1)
          ARGS=(--path "$IPA_PATH" --testflight)
          if [ -n "$BETA_TEST_NOTES" ]; then
            echo "  + TestFlight notes ($(printf '%s' "$BETA_TEST_NOTES" | wc -c) chars)"
            ARGS+=(--whats-new "$BETA_TEST_NOTES" --locale en-US)
          fi
          if [ -n "$BETA_GROUP" ]; then
            echo "  + Beta group: $BETA_GROUP"
            ARGS+=(--beta-group "$BETA_GROUP")
          fi
          app-store-connect publish "${ARGS[@]}"
    artifacts:
      - build/ios/ipa/*.ipa
    publishing:
      scripts:
        - *notify_discord_end

  ios-altstore:
    name: iOS AltStore Build
    max_build_duration: 60
    instance_type: mac_mini_m2
    integrations:
      app_store_connect: Apple Dev Key
    environment:
      ios_signing:
        distribution_type: app_store
        bundle_identifier: com.barnabas.absorb
      groups:
        - discord_notifications
      flutter: stable
      xcode: latest
    scripts:
      - *notify_discord_start
      - name: Set up code signing
        script: xcode-project use-profiles
      - name: Build IPA
        script: flutter build ipa --release --export-options-plist=/Users/builder/export_options.plist
    artifacts:
      - build/ios/ipa/*.ipa
    publishing:
      scripts:
        - *notify_discord_end

  all-release:
    name: All Platforms Release (APK + AAB + IPA to GitHub + TestFlight)
    max_build_duration: 120
    instance_type: mac_mini_m2
    integrations:
      app_store_connect: Apple Dev Key
    environment:
      android_signing:
        - absorb_keystore
      ios_signing:
        distribution_type: app_store
        bundle_identifier: com.barnabas.absorb
      groups:
        - github_credentials
        - discord_notifications
      flutter: stable
      java: 17
      xcode: latest
    scripts:
      - *notify_discord_start
      - name: Set up key.properties
        script: |
          cat >> $CM_BUILD_DIR/android/key.properties <<EOF
          storePassword=$CM_KEYSTORE_PASSWORD
          keyPassword=$CM_KEY_PASSWORD
          keyAlias=$CM_KEY_ALIAS
          storeFile=$CM_KEYSTORE_PATH
          EOF
      - name: Set up iOS code signing
        script: xcode-project use-profiles
      - name: Build universal and split GitHub APKs
        script: bash scripts/build-github-apks
      - name: Build Play Store AAB
        script: flutter build appbundle --release --flavor playstore --dart-define=PLAYSTORE_BUILD=true
      - name: Build iOS IPA
        script: flutter build ipa --release --export-options-plist=/Users/builder/export_options.plist
      - name: Rename AAB and IPA with version
        script: |
          RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
          AAB_SRC=$(ls build/app/outputs/bundle/playstoreRelease/*.aab | head -1)
          mv "$AAB_SRC" "build/app/outputs/bundle/playstoreRelease/absorb-${RAW}.aab"
          IPA_SRC=$(ls build/ios/ipa/*.ipa | head -1)
          mv "$IPA_SRC" "build/ios/ipa/absorb-${RAW}.ipa"
      - name: Publish all to GitHub Draft Release
        script: |
          VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
          UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
          if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
            gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
          else
            gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
          fi
          for apk in build/app/outputs/apk/github/release/*.apk; do
            [ "$apk" = "$UNIVERSAL" ] && continue
            gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
          done
          for artifact in build/app/outputs/bundle/playstoreRelease/*.aab build/ios/ipa/*.ipa; do
            gh release upload "$VERSION" "$artifact" --clobber --repo "$CM_REPO_SLUG"
          done
      - name: Publish to TestFlight
        script: |
          # Mirrors the ios-release workflow's explicit publish so this
          # all-platforms workflow also picks up BETA_TEST_NOTES and
          # BETA_GROUP env vars when set by scripts/codemagic-ios.sh.
          IPA_PATH=$(ls build/ios/ipa/*.ipa | head -1)
          ARGS=(--path "$IPA_PATH" --testflight)
          if [ -n "$BETA_TEST_NOTES" ]; then
            echo "  + TestFlight notes ($(printf '%s' "$BETA_TEST_NOTES" | wc -c) chars)"
            ARGS+=(--whats-new "$BETA_TEST_NOTES" --locale en-US)
          fi
          if [ -n "$BETA_GROUP" ]; then
            echo "  + Beta group: $BETA_GROUP"
            ARGS+=(--beta-group "$BETA_GROUP")
          fi
          app-store-connect publish "${ARGS[@]}"
    artifacts:
      - build/app/outputs/apk/github/release/*.apk
      - build/app/outputs/bundle/playstoreRelease/*.aab
      - build/ios/ipa/*.ipa
    publishing:
      scripts:
        - *notify_discord_end