Skip to main content
Deno 2 is finally here 🎉️
Learn more

Android Pipeline

deno module deno compatibility

A ready-to-use GitLab CI Pipeline and Jobs for your Android projects.

🚀 Usage

Quick start:

import { GitLab } from "https://deno.land/x/android_pipeline/mod.ts";

const { pipeline } = GitLab;

pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml

Or, if you want to use the predefined jobs:

import { GitlabCI } from "https://deno.land/x/fluent_gitlab_ci/mod.ts";
import { GitLab } from "https://deno.land/x/android_pipeline/mod.ts";

const { assembleDebug, debugTests, lintDebug } = GitLab;

const const pipeline = new GitlabCI()
  .image("openjdk:11-jdk")
  .variables({
    ANDROID_COMPILE_SDK: "30",
    ANDROID_BUILD_TOOLS: "30.0.3",
    ANDROID_SDK_TOOLS: "7583922",
  })
  .comment("Packages installation before running script")
  .beforeScript(
    `
    apt-get --quiet update --yes
    apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
    export ANDROID_HOME="\${PWD}/android-home"
    install -d $ANDROID_HOME
    wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-\${ANDROID_SDK_TOOLS}_latest.zip
    pushd $ANDROID_HOME
    unzip -d cmdline-tools cmdline-tools.zip
    pushd cmdline-tools
    mv cmdline-tools tools || true
    popd
    popd
    export PATH=$PATH:\${ANDROID_HOME}/cmdline-tools/tools/bin/
    sdkmanager --version
    yes | sdkmanager --licenses || true
    sdkmanager "platforms;android-\${ANDROID_COMPILE_SDK}"
    sdkmanager "platform-tools"
    sdkmanager "build-tools;\${ANDROID_BUILD_TOOLS}"
    chmod +x ./gradlew
  `
  )
  .comment("Basic android and gradle stuff")
  .comment("Check linting")
  .addJob("lintDebug", lintDebug)
  .comment("Make Project")
  .addJob("assembleDebug", assembleDebug)
  .comment("Run all tests, if any fails, interrupt the pipeline(fail it)")
  .addJob("debugTests", debugTests);

pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml

It will generate the following .gitlab-ci.yml file:

# Do not edit this file directly. It is generated by Fluent GitLab CI

image: openjdk:11-jdk

variables:
  ANDROID_COMPILE_SDK: "30"
  ANDROID_BUILD_TOOLS: 30.0.3
  ANDROID_SDK_TOOLS: "7583922"

# Packages installation before running script
before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - export ANDROID_HOME="${PWD}/android-home"
  - install -d $ANDROID_HOME
  - wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
  - pushd $ANDROID_HOME
  - unzip -d cmdline-tools cmdline-tools.zip
  - pushd cmdline-tools
  - mv cmdline-tools tools || true
  - popd
  - popd
  - export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
  - sdkmanager --version
  - yes | sdkmanager --licenses || true
  - sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
  - sdkmanager "platform-tools"
  - sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}"
  - chmod +x ./gradlew

# Basic android and gradle stuff
# Check linting
lintDebug:
  interruptible: true
  stage: build
  script:
    - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint

# Make Project
assembleDebug:
  interruptible: true
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
      - app/build/outputs/

# Run all tests, if any fails, interrupt the pipeline(fail it)
debugTests:
  interruptible: true
  stage: test
  script:
    - ./gradlew -Pci --console=plain :app:testDebug