# Codemagic CI/CD

Source: https://help.testapp.io/codemagic/

Publish your Android & iOS apps from [Codemagic](https://codemagic.io/) to [TestApp.io](https://testapp.io/) and notify your testers for testing and feedback.

## iOS

> 💡 Codemagic example: [https://docs.codemagic.io/yaml-quick-start/building-a-native-ios-app/](https://docs.codemagic.io/yaml-quick-start/building-a-native-ios-app/)

---

TestApp.io environment variables in Codemagic

```
TESTAPPIO_APP_ID
TESTAPPIO_API_TOKEN
```

These values can be found in the portal: the API token at [Profile -> API Tokens](https://portal.testapp.io/profile/tokens), and the App ID under [App -> Integrations -> Releases](https://portal.testapp.io/apps)

### Using Fastlane (Build & Upload)

If you haven't yet, you would need to setup the fastlane and add the TestApp.io plugin.

[Setup fastlane](https://help.testapp.io/fastlane-plugin/)

```shell
fastlane add_plugin testappio
```

Fastlane environment and other configurations can be found in Codemagic documentation: [https://docs.codemagic.io/integrations/fastlane-integration/](https://docs.codemagic.io/integrations/fastlane-integration/)

Create or update: `codemagic.yaml` a file under your project root folder.

```yml
workflows:
  ios-workflow:
    name: iOS Workflow
    instance_type: mac_mini_m1 # Specify the instance type, example: mac_mini_m1

    environment:
      xcode: latest # Specify Xcode version, example: 13.3
      groups:
        - default # Example group, add your API tokens here TESTAPPIO_API_TOKEN and TESTAPPIO_APP_ID

    # BUILD AND UPLOAD PHASE
    scripts: 
      - name: Build and upload to TestApp.io
        script: |
          bundle install
          bundle exec fastlane ios development --verbose
```

### Without Fastlane (Upload only)

Create or update: `codemagic.yaml` file under your project root folder.

```yml
workflows:
  ios-workflow:
    name: iOS Workflow
    instance_type: mac_mini_m1 # Specify the instance type, example: mac_mini_m1

    environment:
      xcode: latest # Specify Xcode version, example: 13.3
      groups:
        - default # Example group, add your API tokens here TESTAPPIO_API_TOKEN and TESTAPPIO_APP_ID

    # OUTPUT
    artifacts:
      - build/ios/ipa/app.ipa # This path needs to align with the path in the publish command

    scripts:

      # BUILD
      # Add your build commands here
      #...

      # UPLOAD
      - name: Upload to TestApp.io
        script: |
          #!/bin/bash

          # Download and install the TestApp.io CLI
          curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash

          # Use the TestApp.io CLI to publish the app
          ta-cli publish \
            --api_token=$TESTAPPIO_API_TOKEN \
            --app_id=$TESTAPPIO_APP_ID \
            --release="ios" \
            --ipa=./build/ios/ipa/app.ipa \
            --notify=true \
            --git_release_notes=true \
            --git_commit_id=true \
            --source="Codemagic"
```

---

## Android

> 💡 Codemagic example: [https://docs.codemagic.io/yaml-quick-start/building-a-native-android-app/](https://docs.codemagic.io/yaml-quick-start/building-a-native-android-app/)

TestApp.io environment variables in Codemagic

```
TESTAPPIO_APP_ID
TESTAPPIO_API_TOKEN
```

These values can be found in the portal: the API token at [Profile -> API Tokens](https://portal.testapp.io/profile/tokens), and the App ID under [App -> Integrations -> Releases](https://portal.testapp.io/apps)

### Using Fastlane (Build & Upload)

If you haven't yet, you would need to set up Fastlane and add the TestApp.io plugin.

[Setup fastlane](https://help.testapp.io/fastlane-plugin/)

```shell
fastlane add_plugin testappio
```

Fastlane environment and other configurations can be found in Codemagic documentation: [https://docs.codemagic.io/integrations/fastlane-integration/](https://docs.codemagic.io/integrations/fastlane-integration/)

Create or update: `codemagic.yaml` a file under your project root folder.

```yml
workflows:
  android-workflow:
    name: Android Workflow
    instance_type: mac_mini_m1 # Specify the instance type, example: mac_mini_m1

    environment:
      groups:
        - default # Example group, add your API tokens here TESTAPPIO_API_TOKEN and TESTAPPIO_APP_ID
    
    # BUILD AND UPLOAD PHASE
    scripts: 
      - name: Build and upload to TestApp.io
        script: |
          bundle install
          bundle exec fastlane android beta --verbose
```

### Without Fastlane (Upload only)

Create or update: `codemagic.yaml` file under your project root folder.

```yml
workflows:
  android-workflow:
    name: Android Workflow
    instance_type: mac_mini_m1 # Specify the instance type, example: mac_mini_m1

    environment:
      groups:
        - default # Example group, add your API tokens here TESTAPPIO_API_TOKEN and TESTAPPIO_APP_ID

    scripts:

      # BUILD
      - name: Build Android debug
        script: | 
          ./gradlew assembleDebug

       # UPLOAD
      - name: Upload to TestApp.io
        script: |
          #!/bin/bash

          # Download and install the TestApp.io CLI
          curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash

          # Use the TestApp.io CLI to publish the app
          ta-cli publish \
            --api_token=$TESTAPPIO_API_TOKEN \
            --app_id=$TESTAPPIO_APP_ID \
            --release="android" \
            --apk=./app/build/outputs/apk/debug/app-debug.apk \
            --notify=true \
            --git_release_notes=true \
            --git_commit_id=true \
            --source="Codemagic"
```

---

#### Related Setup Guides

- [Setup iOS Project for Fastlane](https://help.testapp.io/setup-ios-project-for-fastlane/)

---

Need help? [Contact us](https://testapp.io/contact-us/). we're happy to assist!
