Menu
myezbrew
  • Privacy Policy
  • prometheus documentation
myezbrew

Semver

Posted on November 7, 2022November 16, 2022 by Andy Jenkins
Follow us on Social Media
linkedin
				
					1900  ssh-keygen -t ed25519 -C "andy@myezbrew.com"
 1901  ls -la
 1902  cat id_ed25519.pub
 1903  cat id_ed25519
 1904  ssh-keyscan gitlab.com
 1905  cat id_ed25519
 1906  cat id_ed25519.pub
 1907  cat id_ed25519
 1908  cat id_ed25519|pbcopy
 1909  cat id_ed25519.pub|pbcopy
 1910  ls -ltr
 1911  rm -rf id*
 1912  history |grep ssh_ke
 1913  history |grep key
 1914  ssh-keygen -t rsa -b 2048
 1915  ssh-keygen -t rsa -b 4096 -C "" -f ./id_rsa
 1916  rm -rf id*
 1917  ssh-keygen -t rsa -b 4096 -C "" -f ./id_rsa
 1918  ls -la
 1919  cat id_rsa|pbcopy
 1920  ssh-keyscan gitlab.com
 1921  ssh-keyscan gitlab.com|pbcopy
				
			
				
					.bookends-ci.yml
.before:
  before_script:
    - python --version
    - pip3 install semantic-version
    - pip3 install GitPython
    - git config --global user.email "${GITLAB_USER_EMAIL}"
    - git config --global user.name "${GITLAB_USER_NAME}"
    - command -v ssh-agent >/dev/null
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d 'r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - env
.after:
  after_script:
    # - env
    - echo 'All Good Things... tng'
.gitlab-ci.yml
variables:
  MAJOR: 1
  MINOR: 2
  PACKAGE_VERSION: "0.0.0"
include:
  - local: '.version-ci.yml'
  - local: '.package-ci.yml'
stages:
  - test-version
  - dogfood
  - version
  - package
test-version:
  stage: test-version
  extends:
    - .before
    - .after
  script:
  - echo "${GIT_GITLAB_URL}"
  - echo "${CE_PROJECT_URL}"
  - echo "${CI_DEFAULT_BRANCH}"
  - echo "${CI_COMMIT_BRANCH}"
  - echo "${MAJOR}"
  - echo "${MINOR}"
  - echo "Executing - git remote set-url origin git@${GIT_GITLAB_URL}:${CE_PROJECT_URL}.git"
  - git remote set-url origin git@${GIT_GITLAB_URL}:${CE_PROJECT_URL}.git
  # - ls -Rlta
  - ls -ltra
  - git branch
  # The build server caches so we need to remove local tags
  # and fetch us some new ones.
  - git tag -d $(git tag -l)
  - git fetch --tags --all
  # The python script writes a file named 'version' that contains the new version
  - python3 semver.py --commit_branch ${CI_COMMIT_BRANCH} --default_branch ${CI_DEFAULT_BRANCH}
    --major ${MAJOR} --minor ${MINOR}
  # - ls -Rlta
  - ls -ltra
  - cat version.file
  - PACKAGE_VERSION=$(cat version.file)
  - echo "${PACKAGE_VERSION}"
  rules:
    - if: '$CI_COMMIT_BRANCH != null'
    # - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
.package-ci.yml
image: "python:3.7"
variables:
  MAJOR: 0
  MINOR: 0
  PACKAGE_VERSION: "0.0.0"
include:
  - local: '.bookends-ci.yml'
stages:
  - package
package:
  stage: package
  extends:
    - .before
    - .after
  script:
  - PACKAGE_VERSION=$(cat version.file)
  - echo "${PACKAGE_VERSION}"
  - echo "${CI_COMMIT_BRANCH}"
  - echo "${MAJOR}"
  - echo "${MINOR}"
  - echo "${CI_API_V4_URL}"
  - echo "${CI_PROJECT_ID}"
  - 'curl --header "PRIVATE-TOKEN: glpat-KsoCwmSYge8A32Na87wY" --upload-file semver.py "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/support_scripts/${PACKAGE_VERSION}/semver.py"'
  dependencies:
    - version
  needs: [version]
  rules:
    - if: $CI_COMMIT_TAG == null
.version-ci.yml
image: "python:3.7"
variables:
  MAJOR: 0
  MINOR: 0
  PACKAGE_VERSION: "0.0.0"
  GIT_GITLAB_URL: "gitlab.com"
  CE_PROJECT_URL: "ezbrew/vger/semantic-version"
  CE_SEMVER_PROJECT_ID: ${CI_PROJECT_ID}
  SEMVER_REF: "1.2.15"
include:
  - local: '.bookends-ci.yml'
stages:
  - dogfood
  - version
dogfood:
  stage: dogfood
  extends:
    - .before
    - .after
  script:
    - 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" ${CI_API_V4_URL}/projects/${CE_SEMVER_PROJECT_ID}/packages/generic/support_scripts/${SEMVER_REF}/semver.py --output-document=${SEMVER_REF}_semver.py'
    - ls -ltra
  artifacts:
    paths:
      - ./${SEMVER_REF}_semver.py
  rules:
    - if: '$CI_COMMIT_BRANCH != null'
version:
  stage: version
  extends:
    - .before
    - .after
  script:
  - echo "${GIT_GITLAB_URL}"
  - echo "${CE_PROJECT_URL}"
  - echo "${CI_DEFAULT_BRANCH}"
  - echo "${CI_COMMIT_BRANCH}"
  - echo "${MAJOR}"
  - echo "${MINOR}"
  - echo "Executing - git remote set-url origin git@${GIT_GITLAB_URL}:${CE_PROJECT_URL}.git"
  - git remote set-url origin git@${GIT_GITLAB_URL}:${CE_PROJECT_URL}.git
  # - ls -Rlta
  - ls -ltra
  - git branch
  # The build server caches so we need to remove local tags
  # and fetch us some new ones.
  - git tag -d $(git tag -l)
  - git fetch --tags --all
  # The python script writes a file named 'version' that contains the new version
  - python3 ${SEMVER_REF}_semver.py --commit_branch ${CI_COMMIT_BRANCH} --default_branch ${CI_DEFAULT_BRANCH}
    --major ${MAJOR} --minor ${MINOR}
  # - ls -Rlta
  - ls -ltra
  - cat version.file
  - PACKAGE_VERSION=$(cat version.file)
  - echo "${PACKAGE_VERSION}"
  rules:
    - if: '$CI_COMMIT_BRANCH != null'
    # - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
  artifacts:
    paths:
      - ./version.file
  needs: [dogfood]
# CI_PROJECT_NAMESPACE=ezbrew/vger
# CI_PROJECT_PATH=ezbrew/vger/semantic-version
# CI_PAGES_URL=https://ezbrew.gitlab.io/vger/semantic-version
# CI_PROJECT_URL=https://gitlab.com/ezbrew/vger/semantic-version
# git remote set-url origin git@gitlab.com:ezbrew/vger/semantic-version.git
# - git remote set-url origin git@gitlab.com:gitlab.com/ezbrew/vger/semantic-version.git
semver.py
import semantic_version
import argparse
import git
import re
parser = argparse.ArgumentParser()
parser.add_argument('--minor', type=str, help="Set the Minor version", default=0)
parser.add_argument('--major', type=str, help="Set the Major version", default=0)
parser.add_argument('--default_branch', type=str, help="Set the default branch", default='')
parser.add_argument('--commit_branch', type=str, help="Set the commit branch", default='')
args = parser.parse_args()
default_branch_pattern = '^default$|^master$|^main$'
featue_branch_pattern = '^OPSU-d+$|^BREW-d+$'
minor = args.minor
major = args.major
commit_branch = args.commit_branch
default_branch = args.default_branch
# initial_version = semantic_version.Version(int(major) + '.' + int(minor) + '.0') 
initial_version = semantic_version.Version(major=int(major), minor=int(minor), patch=0)
# output the arguments passed
print ('Passed arguments:')
print('  major: {}' .format(major))
print('  minor: {}' .format(minor))
print('  commit_branch: {}' .format(commit_branch))
print('  default_branch: {}n' .format(default_branch))
print('Base version values:')
print('  initial_version: {}' .format(initial_version))
# read the repo
repo = git.Repo( './.git' )
print('repo: {}' .format(repo))
def print_initial(): 
    print('  Before: ')
    print('   initial_version: {}' .format(initial_version))
    print('   initial_version.major: {}' .format(initial_version.major))
    print('   initial_version.minor: {}' .format(initial_version.minor))
    print('   initial_version.patch: {}' .format(initial_version.patch))
    print('   initial_version.prerelease: {}' .format(initial_version.prerelease))
    print('   initial_version.build: {}' .format(initial_version.build))
def print_final():
    print('  After: ')
    print('   final_version: {}' .format(final_version))
    print('   final_version: {}' .format(final_version.major))
    print('   final_version: {}' .format(final_version.minor))
    print('   final_version: {}' .format(final_version.patch))
    print('   initial_version.prerelease: {}' .format(final_version.prerelease))
    print('   initial_version.build: {}' .format(final_version.build))
def return_max_patch(patch_major, patch_minor):
    try:
        repo_describe_version = repo.tags
        print(' repo_describe_version: {}' .format(repo_describe_version))
        branch_pattern = str('^'+ str(patch_major) + '.'+ str(patch_minor) +'.d+$')
        patch_list = []
        print('branch_pattern: {}' .format(branch_pattern))
        print('patch_list[]: {}' .format(patch_list))
        for foo in repo_describe_version:
            print('foo: {}' .format(foo))
            match = re.search(branch_pattern, str(foo))
            if re.search(branch_pattern, str(foo)):
                print("I matched a real version... "+ str(foo))
                bar = str(foo).split('.')[-1]
                patch_list.append(int(bar))
            else:
                print("I didn't match a real version... "+ str(foo))
                print('match: {}' .format(match))
        print('patch_list: {}' .format(patch_list))
        max_patch = max(patch_list)
        print('max_patch: {}' .format(max_patch))
        return int(max_patch)   
    except Exception as e:
        print("Exception: {}" .format(e))
        pass
        return 0
def return_next_prerelease(patch_major, patch_minor, patch, prerelease):
    try:
        repo_describe_version = repo.tags
        print(' repo_describe_version: {}' .format(repo_describe_version))
        prerelease = re.sub("-", "-", prerelease)
        # branch_pattern = str('^'+ str(patch_major) + '.'+ str(patch_minor) + '.d+-' + prerelease + '.d+$')
        branch_pattern = str('^'+ str(patch_major) + '.'+ str(patch_minor) + '.' + patch + '-' + prerelease + '.d+$')
        patch_list = [0]
        print('branch_pattern: {}' .format(branch_pattern))
        print('patch_list[]: {}' .format(patch_list))
        for foo in repo_describe_version:
            print('foo: {}' .format(foo))
            match = re.search(branch_pattern, str(foo))
            if re.search(branch_pattern, str(foo)):
                print("I matched a real version... "+ str(foo))
                bar = str(foo).split('.')[-1]
                patch_list.append(int(bar))
            else:
                print("I didn't match a real version... "+ str(foo))
                print('match: {}' .format(match))
        print('patch_list: {}' .format(patch_list))
        prerelease_count = max(patch_list)
        print('prerelease_count: {}' .format(prerelease_count))
        prerelease_count = int(prerelease_count) + 1
        print('After Increment:n  prerelease_count: {}' .format(prerelease_count))
        return int(prerelease_count)   
    except Exception as e:
        print("Exception: {}" .format(e))
        pass
        return 0
# match = re.match(default_branch_pattern, default_branch)
# print('match: {}' .format(match))
# print('Start - use-case: commit branch == default branch')
if (commit_branch == default_branch):    
    print('nI am in: if commit_branch == default_branch: ')
    print_initial()
    initial_version.patch = return_max_patch(major, minor)
    print('  Calculated current:n    initial_version.patch: {}' .format(str(initial_version.patch)))
    print('    initial_version: {}' .format(initial_version))
    final_version = initial_version.next_patch()
    print_final()
else:
    print('I am in: else:') 
    if not re.match(featue_branch_pattern, commit_branch):
        print('I am in: if not re.match(featue_branch_pattern, commit_branch):') 
        commit_branch = 'patch'
        print('  Changed - commit_branch: {}' .format(commit_branch))
    print('I am in: else:n')
    print_initial()    
    initial_version.patch = return_max_patch(major, minor)
    print('  Calculated current:n    initial_version.patch: {}' .format(str(initial_version.patch)))
    print('    initial_version: {}' .format(initial_version))
    prerelease_count = return_next_prerelease(major, minor, str(initial_version.patch), commit_branch)
    print('  Calculated next prerelease count:n    prerelease_count: {}' .format(str(prerelease_count)))
    initial_version.prerelease = (str(commit_branch), str(prerelease_count))
    print('    initial_version.prerelease: {}' .format(initial_version.prerelease))
    final_version = semantic_version.Version(str(initial_version))
    print_final()
print('hello')
version_message = str("Version: " + str(final_version))
repo.git.checkout(commit_branch)
version_tag = repo.create_tag(str(final_version), message=version_message)
print('goodbye')
print ('version_tag: {}' .format(version_tag))
print ('version_tag.path: {}' .format(version_tag.path))
# repo.git.push('origin', str(version_tag))    
# repo.git.push(str(version_tag)) => stderr: 'fatal: '1.1.0-BREW-0000.1' does not appear to be a git repository  
repo.git.push('origin', str(version_tag))
version_file = open("version.file", "w")
version_file.write(str(final_version))
version_file.close()

				
			
				
					Module
gitlab-ci.yml
variables:
  MAJOR: 7
  MINOR: 11
  PACKAGE_VERSION: "0.0.0"
  SEMVER_REF: "1.2.23"
  CE_SEMVER_PROJECT_ID: "40803787"
  CE_PROJECT_URL: "ezbrew/wopr/mock-module"
include:
  - project: 'ezbrew/vger/semantic-version'
    ref: "1.2.23"
    file: 
      - '.version-ci.yml'
stages:
  - view
  - dogfood
  - version
  - parrallel-hello-world
view:
  stage: view
  script:
    - echo ${SEMVER_REF}
  needs: [version, dogfood]
parrallel-hello-world:
  stage: parrallel-hello-world
  script: echo $PLATFORM
  parallel:
    matrix:
      - PLATFORM: [windows, mac, linux]
  needs: [view]
# Set in the 24th century, the series follows the adventures of the crew of the USS Enterprise (NCC-1701-D). 
# In this episode, Lt. Worf (Michael Dorn) returns from a bat'leth tournament and slowly discovers that he 
# is being moved across parallel universes. The crew of an alternative Enterprise realises what is happening 
# and seeks to return him to his own reality, but, after an attack by a Bajoran ship, a space-time fissure 
# explodes, causing hundreds of thousands of alternative versions of the Enterprise to enter the same universe.
				
			

Recent Posts

  • HAOS – Notes
  • Vger: Docker Images
  • Project: Duplicate Terraform Cloud Global Variable
  • PowerShell Crash Day
  • vger: Using a man in the middle terraform module

Recent Comments

    Archives

    • October 2023
    • September 2023
    • August 2023
    • March 2023
    • February 2023
    • November 2022
    • May 2022
    • April 2022
    • December 2021
    • October 2021
    • September 2021

    Categories

    • devops
    • docker images
    • prometheus
    • Prometheus Alerting
    • Uncategorized
    • vger

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    ©2025 myezbrew | WordPress Theme by Superb Themes