def semver_handler()

in lambda-helpers/semver-handler/lambda.py [0:0]


def semver_handler(event, context):

  try:
    # Extract the Job ID
    job_id = event['CodePipeline.job']['id']
    
    # Extract the Job Data 
    job_data = event['CodePipeline.job']['data']
    
    # Extract the params
    params = get_user_params(job_data)
    repo = params['repo']
    branch = params['branch']

    ssm_param = ssm_root + '/simple-cicd/' + repo + '/' + branch + '/version'

    response = ssm.get_parameter(
        Name=ssm_param,
        WithDecryption=False
    )
    version = semver.parse_version_info(response['Parameter']['Value'])
    next_version = version.bump_patch()
    response = ssm.put_parameter(
        Name=ssm_param,
        Value=str(next_version),
        Type='String',
        Overwrite=True
    )

  except Exception as e:
    # If any other exceptions which we didn't expect are raised
    # then fail the job and log the exception message.
    print('Function failed due to exception.') 
    print(e)
    traceback.print_exc()
    put_job_failure(job_id, 'Function exception: ' + str(e))

  print('Function complete.')   
  put_job_success(job_id, 'Function complete')
  return "Complete."