Skip to content

Instantly share code, notes, and snippets.

@willianantunes
Created November 19, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willianantunes/c700fc334256a9a0cb771f5834945d49 to your computer and use it in GitHub Desktop.
Save willianantunes/c700fc334256a9a0cb771f5834945d49 to your computer and use it in GitHub Desktop.
You can use it in your Azure DevOps pipeline to create new flows
import sys
from json import load
from urllib.request import urlopen
# $(Build.Repository.Name) is expected as parameter
organization, app_name = sys.argv[1].split("/")
env_should_publish = "ENV_SHOULD_PUBLISH"
def return_line_which_has_value(file_name: str, value_to_be_found: str) -> str:
with open(file_name, mode="r") as file:
for line in file:
if value_to_be_found in line:
return line
def get_latest_version_from_project_in_pypi(project_name: str) -> str:
project_details = load(urlopen(f"https://pypi.python.org/pypi/{project_name}/json"))
return project_details["info"]["version"]
def set_value(key, value):
print(f"Set key {key} as {value}")
print(f"##vso[task.setvariable variable={key};]{value}")
def do_the_thing(app_name: str):
line = return_line_which_has_value("setup.py", "version")
start_of_value = line.index('"') + 1
end_of_value = line.rindex('"')
current_version_in_setup_py = line[start_of_value:end_of_value]
print(f"Current verion in setup.py: {current_version_in_setup_py}")
current_version_in_pypi = get_latest_version_from_project_in_pypi(app_name)
print(f"Current verion in PyPI: {current_version_in_pypi}")
if current_version_in_setup_py != current_version_in_pypi:
set_value(env_should_publish, True)
else:
set_value(env_should_publish, False)
do_the_thing(app_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment