#!/usr/bin/env groovy

def initSourceTree(boardName, needsNative = false) {
    sh """
       /opt/gcompute-tools/git-cookie-authdaemon

       git config --global url.https://aiyprojects.googlesource.com/.insteadOf sso://aiyprojects/

       mkdir -p .repo/local_manifests
       mkdir -p cache
       chmod 777 cache .repo/local_manifests
       """

    timeout(time: 20, unit: 'MINUTES') {
        checkout([$class: 'RepoScm',
                  currentBranch: true,
                  jobs: 24,
                  manifestRepositoryUrl: 'http://coral.googlesource.com/manifest',
                  manifestBranch: 'master',
                  manifestFile: "${boardName}.xml",
                  manifestGroup: "default,internal",
                  depth: 1,
                  quiet: true])
    }

    // Bring in the pbuilder tarballs.
    //
    // archiveArtifacts includes the relative path to the
    // files we archive, so we don't have to specify cache/
    // here in the target.
    if (needsNative) {
        copyArtifacts(projectName: 'global.pbuilder.arm64', filter: '**/*.tgz')
        copyArtifacts(projectName: 'global.pbuilder.armhf', filter: '**/*.tgz')
    } else {
        copyArtifacts(projectName: 'global.pbuilder.cross', filter: '**/*.tgz')
    }
}

def buildTarget(targetName) {
    sh "bash -c 'source build/setup.sh; m prereqs ${targetName}; exit \$?'"
}

def nameFromRepoType(repoType, boardName) {
    if (repoType == "core") {
        return "core"
    } else if (repoType == "bsp") {
        return "bsp-${boardName}"
    } else {
        error 'Unknown repoType ${repoType}'
    }
}

def uploadAllGeneratedPackages(repoType, boardName, packageNames) {
    def outPath = repoType
    def repoName = nameFromRepoType(repoType, boardName)

    for (packageName in packageNames) {
        def packages = findFiles(glob: "out/**/${packageName}*.deb")
        def sources  = findFiles(glob: "out/**/${packageName}*.dsc")

        if (packages.size() == 0) {
            error 'No packages were generated! Assuming failed build.'
        }

        for (file in packages) {
            sh "aptly repo add -force-replace unstable-${repoName} ${file.path}"
        }

        for (file in sources) {
            sh "aptly repo add -force-replace unstable-${repoName} ${file.path}"
        }
    }
}

def buildPackagePipeline(boardName, repoType, targetName, packageNames, needsNative = false) {
    def workspacePath = "/home/jenkins/workspace"
    def buildLabel = "${targetName}-${UUID.randomUUID().toString()}"
    def sourcePath = "${workspacePath}/src"

    // FIXME(jtgans): Get rid of privileged! This is a security risk!
    def jnlpContainer = containerTemplate(name: 'jnlp',
                                          image: 'jenkins/jnlp-slave:alpine')
    def debianContainer = containerTemplate(name: 'debian',
                                            image: 'gcr.io/mendel-linux-cloud-infra/mendel-builder:latest',
                                            command: 'cat',
                                            args: '',
                                            ttyEnabled: true,
                                            privileged: true)
    def aptlyVolume = persistentVolumeClaim(claimName: 'aptly-state', mountPath: '/var/lib/aptly')

    podTemplate(label: buildLabel, containers: [jnlpContainer, debianContainer], volumes: [aptlyVolume], envVars: []) {
        node(buildLabel) {
            dir(sourcePath) {
                container('debian') {
                    stage('Init') {
                        initSourceTree(boardName, needsNative)
                    }

                    stage('Build') {
                        buildTarget(targetName)
                    }

                    stage('Deploy') {
                        uploadAllGeneratedPackages(repoType, boardName, packageNames)
                    }
                }
            }
        }
    }
}
