// Copyright 2017-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

def app = '${app}'
def version = '${version}'
def nextVersion = '${nextVersion}'
def branch = '${branch}'


def changeVersion(def newVersion) {
    // TODO any other versions we need to account for?
    sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit'
}

node ('ubuntu16.04-basebuild-1c-2g') {

    stage ('Configure Git') {
        sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts'
        
        sh 'git config --global user.name "Jenkins"'
        sh 'git config --global user.email "do-not-reply@opencord.org"'
    }

    stage ('Checkout code') {
        cleanWs()
        
        sshagent (credentials: ['gerrit-jenkins-user']) {
            git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user'

            sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
        }
    }
        
    stage ('Move to release version') {
        changeVersion(version)
        sh 'git add -A && git commit -m "Release version ' + version + '"'
    }

    stage ('Verify code') {
        def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true
        if (found == 0) {
            timeout(time: 1, unit: 'HOURS') {
                metadata = input id: 'manual-verify', 
                message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?',
                        submitter: 'jono,dbainbri'
            }
        }
    }
    
    // This step is basically to test that everything still builds once the version has
    // been bumped up before we start pushing things publicly
    stage ('Build and Test') {
        // TODO can we do this with clean .m2?
        sh 'mvn clean install'
        sh 'mvn javadoc:javadoc'
    }

    stage ('Push to Gerrit') {
        sshagent (credentials: ['gerrit-jenkins-user']) {
            sh 'git push origin HEAD:refs/for/' + branch
        }
    }
    
    stage ('Wait for merge') {
        timeout(time: 1, unit: 'HOURS') {
            metadata = input id: 'release-build', 
            message: 'Go to Gerrit and merge the release patch',
                    submitter: 'jono,dbainbri'
        }
    }

    stage ('Release to Maven Central') {
        configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) {
            sh 'mvn -s $MAVEN_SETTINGS -Prelease clean deploy'
        }
    }

    stage ('Wait for release on Sonatype') {
        timeout(time: 1, unit: 'HOURS') {
            metadata = input id: 'release-build', 
            message: 'Go to Sonatype and release the artifacts',
                    submitter: 'jono,dbainbri'
        }
    }

    stage ('Tag the release') {
        sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
        sshagent (credentials: ['gerrit-jenkins-user']) {
            sh 'git push origin ' + version
        }
    }
    
    stage ('Move to next SNAPSHOT version') {
        def snapshot = nextVersion + '-SNAPSHOT'
        changeVersion(snapshot)
        sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
        sshagent (credentials: ['gerrit-jenkins-user']) {
            sh 'git push origin HEAD:refs/for/' + branch
        }
    }

    stage ('Finish') {
        sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"'
    }
    
}
