Compare commits

...

36 Commits

Author SHA1 Message Date
078f5624b2 Merge pull request 'fix: project username' (#14) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/14
new-tag: 1.0.0
2023-03-19 21:02:07 +01:00
cclecle
348204abb5 fix: project username 2023-03-19 19:59:01 +00:00
44c10b88a5 Merge pull request 'fix: typo in jenkins pipeline file' (#13) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/13
new-tag: 1.0.0
2023-03-19 20:57:20 +01:00
cclecle
48114149fb fix: typo in jenkins pipeline file 2023-03-19 19:54:46 +00:00
a4b7b27a65 Merge pull request 'dev' (#12) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/12
new-tag:1.0.0
2023-03-19 20:53:01 +01:00
cclecle
5eb2f1c5cf fix: pipeline 2023-03-19 19:50:23 +00:00
cclecle
65927077aa fix: git credentials for pushing 2023-03-19 19:49:57 +00:00
77e2be2714 Merge pull request 'fix: remove branch on git push (useless)' (#11) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/11
new-tag:1.0.0
2023-03-19 20:41:37 +01:00
cclecle
0c02512814 fix: remove branch on git push (useless) 2023-03-19 19:35:37 +00:00
f422b9ff7d Merge pull request 'fix git tag cmd' (#10) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/10
new-tag:1.0.0
2023-03-19 20:34:23 +01:00
cclecle
9f900ba597 fix git tag cmd 2023-03-19 19:31:37 +00:00
660270d49b Merge pull request 'fix git username/address in jenkinsfile' (#9) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/9
new-tag:1.0.0
2023-03-19 20:29:40 +01:00
cclecle
97612703b7 fix git username/address in jenkinsfile 2023-03-19 19:26:04 +00:00
9f442a7b8e Merge pull request 'update jenkinsfile' (#8) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/8
new-tag:1.0.0
2023-03-19 20:24:31 +01:00
cclecle
5bb8b35c73 update jenkinsfile 2023-03-19 19:21:48 +00:00
8fb9ba8406 Merge pull request 'dev' (#7) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/7
2023-03-19 20:02:38 +01:00
cclecle
a6c2513d9f fix fstrings 2023-03-19 18:55:58 +00:00
cclecle
70ef90a529 fix jenkinsfile python 2023-03-19 18:53:52 +00:00
cclecle
f728842a5a random fixes 2023-03-19 18:51:35 +00:00
38abaa58c5 Merge pull request 'fix deps' (#6) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/6
2023-03-19 19:47:06 +01:00
cclecle
4837a99ac6 fix deps 2023-03-19 18:46:52 +00:00
35d75ea019 Merge pull request 'dev' (#5) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/5
2023-03-19 19:43:17 +01:00
cclecle
3e130e6bdf revert to full setuptools-git-versioning in toml file 2023-03-19 18:42:24 +00:00
cclecle
d7fbf52647 test 2023-03-19 18:23:42 +00:00
0b8651a30a Merge pull request 'dev' (#4) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/4
2023-03-19 19:22:48 +01:00
cclecle
f5c97757b6 make setuptools-git-versioning use pygitversionhelper
+ add getCurrentFormatedVersion()
2023-03-19 18:22:26 +00:00
cclecle
3c0e5bebc2 update doc 2023-03-19 18:02:02 +00:00
cclecle
c5962d533b fix tag -> version api 2023-03-19 17:59:27 +00:00
cclecle
e9e25793d8 fix doc bullets 2023-03-19 17:57:28 +00:00
cclecle
17f74d6675 test gitversionhelper calls 2023-03-19 17:57:20 +00:00
cclecle
264c51de2e update CI/CD 2023-03-19 17:51:11 +00:00
c5b3055bfe Merge pull request 'feature: add log-line in pipeline' (#3) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/3
2023-03-19 11:39:08 +01:00
cclecle
ac942480cb feature: add log-line in pipeline 2023-03-19 10:34:34 +00:00
92a1d1a30f Merge pull request 'update jenkinsFile' (#2) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/2
2023-03-19 11:29:50 +01:00
cclecle
be9ef684e4 update jenkinsFile => no error when master build are skipped because of
no-tag
2023-03-19 10:26:23 +00:00
f2c0bf1ddd Merge pull request 'bump master release' (#1) from dev into master
Reviewed-on: https://chacha.ddns.net/gitea/chacha/pygitversionhelper/pulls/1
2023-03-19 11:23:54 +01:00
4 changed files with 100 additions and 31 deletions

79
Jenkinsfile vendored
View File

@@ -120,17 +120,21 @@ pipeline {
echo("_GITEA_BASE_URL: . . . . . . . . $_GITEA_BASE_URL")
echo("GIT_COMMIT:. . . . . . . . . . . $GIT_COMMIT ")
echo("_PROJECT_USER_NAME:. . . . . . . $_PROJECT_USER_NAME")
echo("_GITEA_PROJECT_NAME: . . . . . . $_PROJECT_NAME")
echo("_PROJECT_NAME: . . . . . . . . . $_PROJECT_NAME")
echo("_MaintainerEmail:. . . . . . . . $_MaintainerEmail")
echo("_MaintainerName:. . . . . . . . $_MaintainerName")
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python BUILD_ENV")
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TEST_ENV")
sh("virtualenv --pip=embed --setuptools=embed --wheel=embed --no-periodic-update --activators bash,python TOOLS_ENV")
sh(". ~/BUILD_ENV/bin/activate && pip install --upgrade setuptools build pip copier jinja2-slug toml \"setuptools-git-versioning<2\"")
sh(". ~/TOOLS_ENV/bin/activate && pip install simple_rest_client requests")
sh(". ~/TOOLS_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master")
sh("git config --global user.email $_MaintainerEmail")
sh("git config --global user.name $_MaintainerName")
}
}
@@ -148,23 +152,67 @@ pipeline {
{
if(sh(returnStdout: true, script: "git tag --points-at HEAD").trim().isEmpty())
{
error("master push/merge must have an explicit tag release number")
BUMPED_VERSION = sh(script: """#!/bin/sh -
|. ~/TOOLS_ENV/bin/activate
|exec python - << '__EOWRAPPER__'
|
|from pygitversionhelper import gitversionhelper
|import re
|
|lastcommit=gitversionhelper.commit.getLast(same_branch=True)
|msg=gitversionhelper.commit.getMessage(lastcommit)
|
|_match=re.search(r"\\s*(?:#)?\\s*(?<=new-tag:)(?:\\s*)(?P<TAG>\\S*)",msg)
|print(_match.group("TAG"),end="")
|
|__EOWRAPPER__
""".stripMargin(),
returnStdout: true).trim()
if(BUMPED_VERSION.isEmpty())
{
echo "master push/merge must have an explicit tag release number, stopping pipeline"
currentBuild.getRawBuild().getExecutor().doStop()
}
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 ")
// using setuptools_git_versioning to get the generated version number based on Git tags and logs
// TODO: read dev_template from toml
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())
// get current (or bumped) version number from git history
PY_PROJECT_VERSION = sh(script: """#!/bin/sh -
|. ~/BUILD_ENV/bin/activate
|. ~/TOOLS_ENV/bin/activate
|exec python - << '__EOWRAPPER__'
|
|from setuptools_git_versioning import version_from_git
|from pygitversionhelper import gitversionhelper
|
|print(str(version_from_git(tag_filter="^\\d+\\.\\d+\\.\\d+\$",dev_template = "{tag}.post{ccount}")),end ="")
|print(gitversionhelper.version.getCurrentVersion(formated_output=True,version_std="PEP440",bump_type="dev",bump_dev_strategy="post"),end ="")
|
|__EOWRAPPER__
""".stripMargin(),
@@ -176,8 +224,6 @@ pipeline {
// => 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("git config --global user.email $_MaintainerEmail")
sh("git config --global user.name $_MaintainerName")
sh("rm -Rf ~/_gitrepo || true")
@@ -387,13 +433,15 @@ pipeline {
def GITEA_LOGIN_TOKEN=credentials("GiteaCHACHAPush")
}
steps {
sh("python3 -m pip install simple_rest_client requests")
dir("gitrepo") {
script {
def CurrentDateTime=java.time.LocalDateTime.now()
withCredentials([string( credentialsId: _MkDocsWebCredentials,variable: 'MKDOCSTOKEN' )])
{
sh(script: """#!/usr/bin/env python3
sh(script: """#!/bin/sh -
|. ~/TOOLS_ENV/bin/activate
|exec python - << '__EOWRAPPER__'
|
|from simple_rest_client.api import API
|from simple_rest_client.resource import Resource
|import json
@@ -477,8 +525,9 @@ pipeline {
|response=requests.post("http://${_MkDocsWebURL}/API.php?REQ=pushDoc",data=reqData,files=files)
|if response.status_code != 200:
| raise RuntimeError(f"Wrong server response: {response.status_code}")
|
""".stripMargin())
|
|__EOWRAPPER__
""".stripMargin())
}
}
}

View File

@@ -75,25 +75,39 @@ Get the distance from HEAD to last tag [only on same branch]:
Get the last found version in the repository [return MetaVersion object]:
print(f"most recent repository version: {gitversionhelper.tag.getLastVersion()}")
print(f"most recent repository version: {gitversionhelper.version.getLastVersion()}")
Get the last found version in the repository [return formated string]:
print(f"most recent repository version: {gitversionhelper.tag.getLastVersion(formated_output=True)}")
print(f"most recent repository version: {gitversionhelper.version.getLastVersion(formated_output=True)}")
Others kwargs available to this function:
- version_std: string to force a version standard for rendering ["PEP440" or "SemVer"]
- same_branch: boolean to force searching on same branch
- ignore_unknown_tags: boolean to allow unknown tag to be ignored
* version_std: string to force a version standard for rendering ["PEP440" or "SemVer"]
* same_branch: boolean to force searching on same branch
* ignore\_unknown\_tags: boolean to allow unknown tag to be ignored
Get the current version of the repository, automatically bump it if the last one is not tagged [returns MetaVersion object]:
print(f"most recent repository version: {gitversionhelper.tag.getCurrentVersion()}")
print(f"current repository version: {gitversionhelper.version.getCurrentVersion()}")
Or with formated output:
print(f"current repository version: {gitversionhelper.version.getCurrentVersion(formated_output=True)}")
Typical usage in CI/CD env:
bumped_version = gitversionhelper.version.getCurrentVersion( formated_output=True, \
version_std="PEP440", \
bump_type="dev", \
bump_dev_strategy="post")
print(f"current repository version: {bumped_version}")
kwargs available to this function:
- All same args as getLastVersion()
- bump_type: if version need to be pump, allow to configure next release update type: major, minor, patch, dev
- bump_dev_strategy: if bump_type is dev, allow to choose dev update strategy: post, pre-patch, pre-minor, pre-major
* All same args as getLastVersion()
* bump_type: if version need to be pump, allow to configure next release update type: __major, minor, patch, dev__
* bump\_dev\_strategy: if bump\_type is dev, allow to choose dev update strategy: __post, pre-patch, pre-minor, pre-major__
A version object can also be manually formated:
@@ -108,6 +122,7 @@ kwargs available to those function:
## Limitations
There is unfortunately some technical limitation :
- MultiThreading and async behavior is not tested.
- Multiple tag on the same commit is not supported.
- Branch filter when searching for a version is only tested with -no-ff strategy
* MultiThreading and async behavior is not tested.
* Multiple tag on the same commit is not supported.
* Branch filter when searching for a version is only tested with -no-ff strategy

View File

@@ -36,6 +36,7 @@ classifiers = [
]
dependencies = [
'importlib-metadata; python_version<"3.9"',
'packaging'
]
dynamic = ["version"]
@@ -49,10 +50,6 @@ where = ["src"]
[tool.setuptools.package-data]
"pygitversionhelper.data" = ["*.*"]
#[tool.setuptools_scm]
#write_to = "src/pygitversionhelper/_version.py"
#version_scheme = "python-simplified-semver"
[project.urls]
Homepage = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper"
Documentation = "https://chacha.ddns.net/gitea/chacha/pygitversionhelper/wiki"

View File

@@ -494,6 +494,14 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
return _v.doFormatVersion(**kwargs)
return _v
@classmethod
def getCurrentFormatedVersion(cls,**kwargs) -> str :
"""
Same as getCurrentVersion() with formated_output kwarg activated
"""
kwargs["formated_output"]=True
return cls.getCurrentVersion(kwargs)
@classmethod
def _parseTag(cls,tag,**kwargs): # pylint: disable=R0914, R0912, R0915
"""get the last version from tags