// 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"'
    }
    
}
