// 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 createBranch(def proj, def branch, def parent) {
    cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
    sh returnStdout: true, script: cmd
}

int checkBranchExists(def proj, def branch) {
    url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + branch
    response = httpRequest url: url, validResponseCodes: '200,404'
    if (response.status == 404) {
        return 1
    }
    return 0
}

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

node ('master') {
    stage 'Checkout code' {
        //checkout([$class: 'RepoScm', currentBranch: true, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true])
        git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app
    }

    
    //stage 'Create support branch'
    //if (checkBranchExists(app, branch) == 0) {
    //  echo "Branch " + branch + " doesn't exist, creating
        //createBranch(app, version, 'opencord/master')
    //} else {
    //  echo "Support branch " + branch + " already exists"
    //}
    
    stage 'Checkout branch' {
        sh 'git checkout ' + branch
        sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
    }
        
    stage 'Bump versions' {
        changeVersion(version)
    }
    
    stage 'Commit' {
        sh 'git add -A && git commit -m "Release version ' + version + '"'
    }
    
    stage 'Build and Test' {
        // TODO can we do this with clean .m2?
        sh 'mvn clean install'
    }

    stage 'Push to Gerrit' {
        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'
        }
    }

    stage 'Release to Maven Central' {
        sh 'mvn -Prelease clean deploy'
    }

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

    stage 'Tag the release' {
        sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
        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 + '"'
        sh 'git push origin HEAD:refs/for/' + branch
    }

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