# Travis CI

Source: https://help.testapp.io/travis-ci/

The Travis CI pipeline allows you to build and upload both Android & iOS apps to TestApp.io to notify your testers for testing and feedback.

## Configuration

| Key | Description | Env Var(s) | Default |
| --- | --- | --- | --- |
| api_token | You can get it from [https://portal.testapp.io/profile/tokens](https://portal.testapp.io/profile/tokens) | TESTAPPIO_API_TOKEN |  |
| app_id | You can get it from your app page at [https://portal.testapp.io/apps](https://portal.testapp.io/apps) | TESTAPPIO_APP_ID |  |
| release | It can be either both or Android or iOS | TESTAPPIO_RELEASE |  |
| apk | Path to the Android APK file | TESTAPPIO_ANDROID_PATH |  |
| ipa | Path to the iOS IPA file | TESTAPPIO_IOS_PATH |  |
| release_notes | Manually add the release notes to be displayed for the testers | TESTAPPIO_RELEASE_NOTES |  |
| git_release_notes | Collect release notes from the latest git commit message to be displayed for the testers: true or false | TESTAPPIO_GIT_RELEASE_NOTES | true |
| git_commit_id | Include the last commit ID in the release notes (works with both release notes options): true or false | TESTAPPIO_GIT_COMMIT_ID | false |
| notify | Send notifications to your team members about this release: true or false | TESTAPPIO_NOTIFY | false |

*Check* [*TA-CLI*](https://help.testapp.io/ta-cli/) *for more info*

## iOS

We will demonstrate with our sample iOS project [testappio-ios-sample-app](https://github.com/testappio/ios-sample-app) to integrate **TestApp.io** with **Travis-CI**.

### fastlane">Configure iOS project for Fastlane

1. Install Fastlane

The below command works for most cases. If not, please read this - [Setup Fastlane](https://docs.fastlane.tools/getting-started/ios/setup/)

```bash
bundle install fastlane
```

1. Init Fastlane

In the iOS project folder

```bash
bundle exec fastlane init
```

And follow the wizard; it will create `./fastlane/Appfile` with your Apple ID and team.

1. Init `Match`

[Fastlane **match**](https://docs.fastlane.tools/actions/match/) is a tool for generating all necessary certificates and provisioning profiles and storing them in a Git repository encrypted.

Create a private empty GitHub repository for storing certificates and provisioning profiles.

```bash
bundle exec fastlane match init
```

Follow the instruction, give the new empty git repository when asked, and it will create the `Matchfile`.

> 💡 Note: Please use the *****HTTPS***** Git repository address if you integrate with the Travis CI.

1. Generate the certificate and provision profile

```bash
bundle exec fastlane match adhoc
```

Following the instruction, it will generate certificates/profiles and store them in the Git repository specified in the previous step.

> 💡 Note: Provide a matching password that is used for encrypting the certificates and profiles in the Git repository.

1. Select provisioning profiles in Xcode

The newly created certificates and profiles should now be possible to select inside our project. Open up Xcode and go to Signing & Capabilities.

> ⚠️ Note: Don't choose ****Automatically manage signing****

1. Configure `MATCH_PASSWORD` environment parameter in Travis CI

Go to Travis's repository `Settings` page, add an environment parameter `MATCH_PASSWORD` as below.

![](https://f000.backblazeb2.com/file/help-testappio/2022/03/match_password.jpg)

Configure `FASTLANE_PASSWORD` environment parameter in Travis CI  
This is used for login your Apple ID to the Apple Developer's portal.

Configure `GITHUB_API_TOKEN` environment parameters in Travis CI

Navigate to [Tokens](https://github.com/settings/tokens) to generate a **Personal Access Token**, and create a `GITHUB_API_TOKEN` environment parameter in Travis CI.

1. Using `testappio` plugin for Fastlane

```bash
bundle exec fastlane add_plugin testappio
```

1. Add environment parameters for `testappio` Fastlane plugin  
   Add `TESTAPPIO_API_TOKEN` and `TESTAPPIO_APP_ID` to Travis environment parameters.

### Run the pipeline

1. Finally, create the `lane`

Create: `./fastlane/Fastfile` and copy the below content:

```ruby
default_platform(:ios)

platform :ios do

  desc "Build the adhoc and upload to TestApp.io"
  lane :beta do
    match(type: "adhoc")
    gym(export_method: "ad-hoc")
    upload_to_testappio(
      release_notes: "My release notes here...",
      git_release_notes: true,
      git_commit_id: false,
      notify: true
    )
  end
  
end
```

More info on the Fastlane plugin: [https://help.testapp.io/fastlane-plugin/#usage](https://help.testapp.io/fastlane-plugin/#usage)

You may already have your lane in place; copy the `upload_to_testappio` action and put it into your pipeline after the **IPA** export.

1. The Travis pipeline:

Create: `.travis.yml` file under your project root folder. E.g.

```yml
language: swift
osx_image: xcode13.3

cache:
  bundler: true

install:
  - bundle install  # install fastlane and its dependencies
script: 
  - echo "machine github.com login $GITHUB_API_TOKEN" >> ~/.netrc
  - bundle exec fastlane ios development # run the lane
```

1. Commit and push the change to trigger the Travis pipeline.

## Android

We will demonstrate with our sample Android project [testappio-android-sample](https://github.com/testappio/android-sample-app) to integrate TestApp.io with Travis-CI.

Add Travis environment parameters for `ta-cli`  
a.`TESTAPPIO_API_TOKEN`  
b.`TESTAPPIO_APP_ID`  
Check the [configuration](https://help.testapp.io/travis-ci/#configuration) for more info

Create `.travis.yml` file

```yml
language: android
jdk: openjdk11
dist: trusty

env:
  - release_notes="My release notes here..." git_release_notes=false git_commit_id=false notify=true

before_cache:
  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
  directories:
    - $HOME/.gradle/caches/
    - $HOME/.gradle/wrapper/
    - $HOME/.android/build-cache

before_script:
  - export JAVA_HOME=/usr/lib/jvm/java-8-oracle
  - OLDPATH=$PATH
  - export PATH=$JAVA_HOME/bin:$PATH
  - echo yes | sdkmanager "build-tools;30.0.3"
  - echo yes | sdkmanager "platforms;android-31"
  - export JAVA_HOME=~/openjdk11
  - export PATH=$OLDPATH

script: 
  - ./gradlew assembleDebug
  - export INSTALL_DIR=/tmp
  - curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
  - $INSTALL_DIR/ta-cli publish --api_token=$TESTAPPIO_API_TOKEN --app_id=$TESTAPPIO_APP_ID --release=$release  --apk=./app/build/outputs/apk/debug/app-debug.apk --release_notes=$release_notes --git_release_notes=$git_release_notes --git_commit_id=$git_commit_id --notify=$notify --source="Travis CI"
```

If you already have your Travis pipeline for testing/building your Android app, you could just put the below sections:

```yml
...
env:
  - release_notes="My release notes here..." git_release_notes=false git_commit_id=false notify=true
...
script: 
  ...
  - export INSTALL_DIR=/tmp
  - curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
  - $INSTALL_DIR/ta-cli publish --api_token=$TESTAPPIO_API_TOKEN --app_id=$TESTAPPIO_APP_ID --release=$release  --apk=./app/build/outputs/apk/debug/app-debug.apk --release_notes=$release_notes --git_release_notes=$git_release_notes --git_commit_id=$git_commit_id --notify=$notify --source="Travis CI"
```

---

#### Related Setup Guides

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

> **Tip:** Once your CI/CD pipeline uploads a build, team members using the [TestApp.io mobile app](https://help.testapp.io/mobile-app-getting-started/) receive a push notification and can install the build with a single tap. You can also create [share links](https://help.testapp.io/how-to-share/) to distribute builds to external testers and clients.

---

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