diff --git a/Jenkinsfile b/Jenkinsfile index d5327e5..fb306e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -135,6 +135,9 @@ pipeline { sh("git config --global user.email $_MaintainerEmail") sh("git config --global user.name $_MaintainerName") + withCredentials([usernamePassword(credentialsId: _SCMCredentials, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { + sh("git remote set-url origin https://${GIT_USERNAME}:${GIT_PASSWORD}@chacha.ddns.net/gitea/${_PROJECT_USER_NAME}/${_PROJECT_NAME}.git") + } } } @@ -148,6 +151,26 @@ pipeline { extensions: [[$class: "CloneOption", noTags: false, shallow: false, depth: 0, reference: '']], userRemoteConfigs: [[credentialsId: _SCMCredentials, url: GIT_URL]]]) script{ + // using git to get the latest tag on this branch (before processing) + def latestTag_beforeProcessing = sh(returnStdout: true, script: "git tag --sort=-creatordate | head -n 1").trim() + echo("latestTag_beforeProcessing:. . . . . . . . . . . . $latestTag ") + + sh(script: """#!/bin/sh - + |. ~/TOOLS_ENV/bin/activate + |exec python - << '__EOWRAPPER__' + | + |from pygitversionhelper import gitversionhelper + | + |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag()}") + |print(f"most recent repository tag: {gitversionhelper.tag.getLastTag(same_branch=True)}") + |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag()}") + |print(f"number of commit since last tag: {gitversionhelper.tag.getDistanceFromTag(same_branch=True)}") + |print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}") + |print(f'current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post")}') + | + |__EOWRAPPER__ + """.stripMargin()) + if(_GIT_BRANCH=="master") { if(sh(returnStdout: true, script: "git tag --points-at HEAD").trim().isEmpty()) @@ -176,20 +199,14 @@ pipeline { else { echo "new-tag requested in commit message: $BUMPED_VERSION" - withCredentials([usernamePassword(credentialsId: _SCMCredentials, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { - sh("git remote set-url origin https://${GIT_USERNAME}:${GIT_PASSWORD}@chacha.ddns.net/gitea/${_PROJECT_USER_NAME}/${_PROJECT_NAME}.git") - } + sh("git tag $BUMPED_VERSION") sh("git push origin --tags") } } } - - // using git to get the latest tag on this branch - def latestTag = sh(returnStdout: true, script: "git tag --sort=-creatordate | head -n 1").trim() - echo("latestTag:. . . . . . . . . . . . $latestTag ") - - sh(script: """#!/bin/sh - + + sh(script: """#!/bin/sh - |. ~/TOOLS_ENV/bin/activate |exec python - << '__EOWRAPPER__' | @@ -204,7 +221,20 @@ pipeline { | |__EOWRAPPER__ """.stripMargin()) - + + latestTag = sh(script: """#!/bin/sh - + |. ~/TOOLS_ENV/bin/activate + |exec python - << '__EOWRAPPER__' + | + |from pygitversionhelper import gitversionhelper + | + |print(gitversionhelper.tag.getLastTag(same_branch=True),end ="") + | + |__EOWRAPPER__ + """.stripMargin(), + returnStdout: true) + echo("latestTag:. . . . . . . . . . . . $latestTag ") + // get current (or bumped) version number from git history PY_PROJECT_VERSION = sh(script: """#!/bin/sh - |. ~/TOOLS_ENV/bin/activate @@ -220,11 +250,18 @@ pipeline { echo("PY_PROJECT_VERSION: . . . . . . . . . $PY_PROJECT_VERSION") PY_PROJECT_VERSION_STRIPPED=ExtractBaseVersion(PY_PROJECT_VERSION) + // Manually pushing a new tag with version string guessed by gitversionhelper + // because setuptools-git-versioning cant fing tag on other branches, so will guess a wring version without this tag. + if(latestTag!=PY_PROJECT_VERSION) + { + sh("git tag $PY_PROJECT_VERSION") + sh("git push origin --tags") + } + // specific handling to test the template itself // => little hacky... creating a new git repo with a commit/tag corresponding to HEAD of the official one if(_PROJECT_NAME=="pyChaChaDummyProject") //specific case to test the template itself { - sh("rm -Rf ~/_gitrepo || true") sh(script: """#!/bin/sh -