azkaban-aplcache

Add a script to create a new release tag (#1839) This change

7/10/2018 3:09:24 PM

Details

settings.gradle 3(+2 -1)

diff --git a/settings.gradle b/settings.gradle
index 43383a8..6366ff3 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 LinkedIn Corp.
+ * Copyright 2018 LinkedIn Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
@@ -31,3 +31,4 @@ include 'az-reportal'
 include 'az-hadoop-jobtype-plugin'
 include 'az-jobsummary'
 include 'az-hdfs-viewer'
+include 'tools'

tools/.gitignore 9(+9 -0)

diff --git a/tools/.gitignore b/tools/.gitignore
new file mode 100644
index 0000000..af69b28
--- /dev/null
+++ b/tools/.gitignore
@@ -0,0 +1,9 @@
+# direnv files see https://github.com/direnv/direnv
+.envrc
+.direnv/
+
+# pytest
+.pytest_cache/
+
+#python
+__pycache__/
diff --git a/tools/create_release.py b/tools/create_release.py
new file mode 100755
index 0000000..9dddf8f
--- /dev/null
+++ b/tools/create_release.py
@@ -0,0 +1,81 @@
+#! /usr/bin/env python3
+"""
+Script to publish a new version.
+
+Require a clean tracking master branch and the upstream remote points to the main Azkaban repository.
+"""
+
+import subprocess
+
+
+def update_tags():
+    """
+    Update the tags in the local branch from the remote upstream.
+    """
+    run_cmd('git fetch upstream')
+    run_cmd('git checkout master')
+    run_cmd('git merge upstream/master')
+
+
+def run_cmd(cmd):
+    """
+    Runs a command without capturing the output.
+
+    :param cmd: cmd string
+    :return:
+    """
+    print("Running cmd: " + cmd)
+    subprocess.run(cmd, capture_output=False, check=True, text=False, shell=True)
+
+
+def get_latest_tag():
+    cmd = 'git describe --abbrev=0'
+    output = subprocess.run(cmd, capture_output=True, check=True, text=True, shell=True)
+    latest_tag = output.stdout
+    print("Latest tag : {}".format(latest_tag))
+    return latest_tag
+
+
+def calculate_new_version(latest_tag):
+    """
+    Calculates the new version.
+
+    Increment the minor version by 1 and set the patch version to 0.
+
+    :param latest_tag: the latest version tag
+    :return: the new version tag
+    """
+    major, minor, patch = latest_tag.split('.')
+    new_minor = int(minor) + 1
+    new_version = "{}.{}.0".format(major, new_minor)
+    print("New version : {}".format(new_version))
+    return new_version
+
+
+def publish_new_version(version):
+    print("publishing new version: " + version)
+    create_local_tag_cmd = 'git tag -a {0} -m "Release {0}"'.format(version)
+    run_cmd(create_local_tag_cmd)
+    push_tag_cmd = 'git push upstream {0}'.format(version)
+    run_cmd(push_tag_cmd)
+
+
+def should_publish():
+    answer = input("Publish the new version? (y/N)")
+    if answer == 'y':
+        return True
+    return False
+
+
+def create_release():
+    update_tags()
+    latest_tag = get_latest_tag()
+    new_version = calculate_new_version(latest_tag)
+    if should_publish():
+        publish_new_version(new_version)
+    else:
+        print("Abort.")
+
+
+if __name__ == "__main__":
+    create_release()
diff --git a/tools/create_release_test.py b/tools/create_release_test.py
new file mode 100644
index 0000000..099e1d7
--- /dev/null
+++ b/tools/create_release_test.py
@@ -0,0 +1,6 @@
+import create_release
+
+
+def test_calculate_new_version():
+    new_version = create_release.calculate_new_version('3.10.0')
+    assert new_version == '3.11.0'

tools/README.md 9(+9 -0)

diff --git a/tools/README.md b/tools/README.md
new file mode 100644
index 0000000..c8af3f4
--- /dev/null
+++ b/tools/README.md
@@ -0,0 +1,9 @@
+The python scripts in this direcory require python3.
+
+A python virtual environment is recommended to run these scripts.
+
+To download the dependencies, run 
+
+```bash
+pip3 install -r requirements.txt
+```
diff --git a/tools/requirements.txt b/tools/requirements.txt
new file mode 100644
index 0000000..e079f8a
--- /dev/null
+++ b/tools/requirements.txt
@@ -0,0 +1 @@
+pytest