Merge pull request #8 from RightBrain-Networks/feature/noCommit
Commitless Semver
This commit is contained in:
		
							
								
								
									
										26
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							@ -15,32 +15,10 @@ pipeline {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  stages {
 | 
					  stages {
 | 
				
			||||||
    //Pulls docker image for self-versioning
 | 
					 | 
				
			||||||
    stage("Pull Versioning Image")
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        steps
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          withEcr {
 | 
					 | 
				
			||||||
            sh "docker pull ${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}"
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    //Runs versioning in docker container
 | 
					    //Runs versioning in docker container
 | 
				
			||||||
    stage('Version') {
 | 
					    stage('Self Version') {
 | 
				
			||||||
        agent {
 | 
					 | 
				
			||||||
            docker {
 | 
					 | 
				
			||||||
                image "${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}"
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      steps {
 | 
					      steps {
 | 
				
			||||||
        // runs the automatic semver tool which will version, & tag,
 | 
					        runAutoSemver("${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}")
 | 
				
			||||||
        runAutoSemver()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //Grabs current version
 | 
					 | 
				
			||||||
        script
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            env.VERSION = getVersion('-d')
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      post{
 | 
					      post{
 | 
				
			||||||
        // Update Git with status of version stage.
 | 
					        // Update Git with status of version stage.
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
 | 
					from semver.get_version import get_tag_version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try: 
 | 
					try: 
 | 
				
			||||||
    from configparser import ConfigParser
 | 
					    from configparser import ConfigParser
 | 
				
			||||||
except ImportError:
 | 
					except ImportError:
 | 
				
			||||||
@ -97,6 +99,19 @@ class SemVer(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    # use bumpversion to increment the appropriate version type
 | 
					    # use bumpversion to increment the appropriate version type
 | 
				
			||||||
    def version_repo(self):
 | 
					    def version_repo(self):
 | 
				
			||||||
 | 
					        config_file = ""
 | 
				
			||||||
 | 
					        with open(".bumpversion.cfg", "r") as file:
 | 
				
			||||||
 | 
					            config_file = file.read()
 | 
				
			||||||
 | 
					        # Update .bumpconfig
 | 
				
			||||||
 | 
					        pattern = re.compile("current_version = [0-9.]*")
 | 
				
			||||||
 | 
					        current_config = re.search(pattern, config_file)
 | 
				
			||||||
 | 
					        if current_config:
 | 
				
			||||||
 | 
					            config_file.replace(current_config, "current_version = " + get_tag_version())
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            config_file.replace("[bumpversion]","[bumpversion]\ncurrent_version = " + get_tag_version())
 | 
				
			||||||
 | 
					        with open(".bumpversion.cfg", "w") as file:
 | 
				
			||||||
 | 
					            file.write(config_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # version repo
 | 
					        # version repo
 | 
				
			||||||
        p = subprocess.Popen(['bumpversion', self.version_type],
 | 
					        p = subprocess.Popen(['bumpversion', self.version_type],
 | 
				
			||||||
                             cwd='.')
 | 
					                             cwd='.')
 | 
				
			||||||
 | 
				
			|||||||
@ -11,11 +11,22 @@ except ImportError:
 | 
				
			|||||||
    import os
 | 
					    import os
 | 
				
			||||||
    DEVNULL = open(os.devnull, 'wb')
 | 
					    DEVNULL = open(os.devnull, 'wb')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_tag_version():
 | 
				
			||||||
def get_version(dot=False):
 | 
					 | 
				
			||||||
    config = ConfigParser()
 | 
					    config = ConfigParser()
 | 
				
			||||||
    config.read('./.bumpversion.cfg')
 | 
					    config.read('./.bumpversion.cfg')
 | 
				
			||||||
    version = config.get('bumpversion', 'current_version')
 | 
					    tag_expression = config.get('bumpversion','tag_name').replace('{new_version}','[0-9]*.[0-9]*.[0-9]*')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    version = "0.0.0"
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    tagged_versions = subprocess.Popen(['git','tag','-l',tag_expression],
 | 
				
			||||||
 | 
					        stdout=subprocess.PIPE, stderr=DEVNULL, cwd=".").stdout.read().decode('utf-8').rstrip().split('\n')
 | 
				
			||||||
 | 
					    if len(tagged_versions) > 0 and tagged_versions[-1] != "":
 | 
				
			||||||
 | 
					        version = tagged_versions[-1]
 | 
				
			||||||
 | 
					    return version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_version(dot=False):
 | 
				
			||||||
 | 
					    version = get_tag_version()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Get the commit hash of the version 
 | 
					    # Get the commit hash of the version 
 | 
				
			||||||
    v_hash = subprocess.Popen(['git', 'rev-list', '-n', '1', version], stdout=subprocess.PIPE,
 | 
					    v_hash = subprocess.Popen(['git', 'rev-list', '-n', '1', version], stdout=subprocess.PIPE,
 | 
				
			||||||
                             stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip()
 | 
					                             stderr=DEVNULL, cwd='.').stdout.read().decode('utf-8').rstrip()
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user