<commit_before>#! /usr/bin/env python

import argparse
import time
import subprocess
import sys

from apiclient import sample_tools
from oauth2client import client
from subprocess import CalledProcessError

"""
A script to push releases to Google Play
See samples: https://github.com/googlesamples/android-play-publisher-api

Requires Google API python client
Insall with: pip install google-api-python-client
"""

PACKAGE = 'com.thebluealliance.androidclient'
CHANGELOG_PATH = 'android/src/prod/play/en-US/whatsnew'
INAPP_CHANGELOG = 'android/src/main/res/raw/changelog.txt'

parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("tag", help="New version number (e.g. 3.1.4)")
parser.add_argument("--message", "-m", help="Tag message. Defaults to 'Version v<tag>'")
parser.add_argument("--skip-tag", action="store_true", default=False,
                    help="Do not make a new git tag. Instead, push existing release identified by <tag>")
parser.add_argument("--dirty-repo", action="store_true", default=False,
                    help="Allow untracked changes in the repo")


def check_clean_repo():
    try:
        subprocess.check_output(["git", "diff-files", "--quiet", "--ignore-submodules"])
    except CalledProcessError:
        print "You have uncommitted changes in the repository. Commit them and try again"
        sys.exit(1)


def check_unittest():
    print "Running project unit tests..."
    time.sleep(2)
    try:
        subprocess.check_call(["./gradlew", "testProdDebugUnitTest"])
        print "Unit tests passed!"
    except CalledProcessError:
        print "Unit tests failed. Fix them before releasing"
        sys.exit(1)


def update_whatsnew():
    print "Updating whatsnew file ({}). Limit 500 characters".format(CHANGELOG_PATH)
    time.sleep(2)
    subprocess.call(["vim", CHANGELOG_PATH])

    # Check character count
    chars = subprocess.check_output(["wc", "-m", CHANGELOG_PATH])
    if int(chars.split()[0]) > 500:
        print "Changelog too long. Must be limited to 500 characters"
        sys.exit(1)

    # Copy to in-app changelog
    subprocess.call(["cp", CHANGELOG_PATH, INAPP_CHANGELOG])

    # Fix line breaks
    subprocess.call(["sed", "-i", 's/$/<br>/', INAPP_CHANGELOG])
    subprocess.call(["rm", "-f", "{}{}".format(INAPP_CHANGELOG, "bak")])


def commit_whatsnew():
    print "Committing new changelog"
    time.sleep(2)
    subprocess.call(["git", "add", INAPP_CHANGELOG, CHANGELOG_PATH])
    try:
        subprocess.check_output(["git", "commit", "-m", "Version {} Whatsnew".format(args.tag)])
    except CalledProcessError:
        print "Unable to commit new changelog"
        sys.exit(1)


def create_tag(args):
    # Add the git tag
    name = args.message if args.message else "Version {}".format(args.tag)
    print("Creating new git tag for release v{}: {}".format(args.tag, name))
    print("To skip creating a new tag, run with --skip_tag")
    time.sleep(2)
    subprocess.call(["git", "tag", "-a", "v{}".format(args.tag), "-m", name])


def build_apk(args):
    # Check out repo at specified tag and build
    old_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
    print "Leaving {}, checking out tag v{}".format(old_branch, args.tag)
    time.sleep(2)
    subprocess.call(["git", "checkout", "v{}".format(args.tag)])
    print "Building and uploading the app..."
    time.sleep(2)
    subprocess.call(["./gradlew", "publishProdRelease"])
    print "Returning to {}".format(old_branch)
    subprocess.call(["git", "checkout", old_branch])


def push_repo():
    subprocess.call(["git", "push", "upstream"])
    subprocess.call(["git", "push", "--tags", "upstream"])

if __name__ == "__main__":
    args = parser.parse_args()
    if not args.dirty_repo:
        check_clean_repo()
    check_unittest()
    if not args.skip_tag:
        update_whatsnew()
        commit_whatsnew()
        create_tag(args)
    build_apk(args)
    push_repo()<commit_msg>Validate apk on real device before pushing<commit_after>#! /usr/bin/env python

import argparse
import time
import subprocess
import sys

from apiclient import sample_tools
from oauth2client import client
from subprocess import CalledProcessError

"""
A script to push releases to Google Play
See samples: https://github.com/googlesamples/android-play-publisher-api

Requires Google API python client
Insall with: pip install google-api-python-client
"""

PACKAGE = 'com.thebluealliance.androidclient'
CHANGELOG_PATH = 'android/src/prod/play/en-US/whatsnew'
INAPP_CHANGELOG = 'android/src/main/res/raw/changelog.txt'

parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("tag", help="New version number (e.g. 3.1.4)")
parser.add_argument("--message", "-m", help="Tag message. Defaults to 'Version v<tag>'")
parser.add_argument("--skip-tag", action="store_true", default=False,
                    help="Do not make a new git tag. Instead, push existing release identified by <tag>")
parser.add_argument("--dirty-repo", action="store_true", default=False,
                    help="Allow untracked changes in the repo")
parser.add_argument("--skip-validate", action="store_true", default=False,
                    help="Do not build an install the prod apk to test on a real device")


def check_clean_repo():
    try:
        subprocess.check_output(["git", "diff-files", "--quiet", "--ignore-submodules"])
    except CalledProcessError:
        print "You have uncommitted changes in the repository. Commit them and try again"
        sys.exit(1)


def check_unittest():
    print "Running project unit tests..."
    time.sleep(2)
    try:
        subprocess.check_call(["./gradlew", "testProdReleaseUnitTest"])
        print "Unit tests passed!"
    except CalledProcessError:
        print "Unit tests failed. Fix them before releasing"
        sys.exit(1)


def update_whatsnew():
    print "Updating whatsnew file ({}). Limit 500 characters".format(CHANGELOG_PATH)
    time.sleep(2)
    subprocess.call(["vim", CHANGELOG_PATH])

    # Check character count
    chars = subprocess.check_output(["wc", "-m", CHANGELOG_PATH])
    if int(chars.split()[0]) > 500:
        print "Changelog too long. Must be limited to 500 characters"
        sys.exit(1)

    # Copy to in-app changelog
    subprocess.call(["cp", CHANGELOG_PATH, INAPP_CHANGELOG])

    # Fix line breaks
    subprocess.call(["sed", "-i", 's/$/<br>/', INAPP_CHANGELOG])
    subprocess.call(["rm", "-f", "{}{}".format(INAPP_CHANGELOG, "bak")])


def commit_whatsnew():
    print "Committing new changelog"
    time.sleep(2)
    subprocess.call(["git", "add", INAPP_CHANGELOG, CHANGELOG_PATH])
    try:
        subprocess.check_output(["git", "commit", "-m", "Version {} Whatsnew".format(args.tag)])
    except CalledProcessError:
        print "Unable to commit new changelog"
        sys.exit(1)


def create_tag(args):
    # Add the git tag
    name = args.message if args.message else "Version {}".format(args.tag)
    print("Creating new git tag for release v{}: {}".format(args.tag, name))
    print("To skip creating a new tag, run with --skip_tag")
    time.sleep(2)
    subprocess.call(["git", "tag", "-a", "v{}".format(args.tag), "-m", name])


def validate_build():
    print "Installing build, ensure a device is plugged in with USB Debugging enabled"
    subprocess.call(["adb", "devices"])
    try:
        input("Press Enter to continue...")
    except SyntaxError:
        pass
    time.sleep(5)
    subprocess.check_call(["./gradlew", "installProdRelease"])
    subprocess.call(["adb", "shell", "am", "start", "-n", "com.thebluealliance.androidclient/com.thebluealliance.androidclient.activities.LaunchActivity"])
    try:
        input("Press Enter to continue the release, or ^C to quit")
    except SyntaxError:
        pass


def build_apk(args):
    # Check out repo at specified tag and build
    old_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip()
    print "Leaving {}, checking out tag v{}".format(old_branch, args.tag)
    time.sleep(2)
    subprocess.call(["git", "checkout", "v{}".format(args.tag)])
    print "Building and uploading the app..."
    time.sleep(2)
    subprocess.call(["./gradlew", "publishProdRelease"])
    print "Returning to {}".format(old_branch)
    subprocess.call(["git", "checkout", old_branch])


def push_repo():
    subprocess.call(["git", "push", "upstream"])
    subprocess.call(["git", "push", "--tags", "upstream"])

if __name__ == "__main__":
    args = parser.parse_args()
    if not args.dirty_repo:
        check_clean_repo()
    check_unittest()
    if not args.skip_tag:
        update_whatsnew()
        commit_whatsnew()
        create_tag(args)
    if not args.skip_validate:
        validate_build()
    build_apk(args)
    push_repo()
{'fraction_non_alphanumeric': 0.1444797819173103, 'fraction_numerical': 0.005565651976374375, 'mean_word_length': 3.6147798742138364, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5862045', 'n_tokens_mistral': 2850, 'n_tokens_neox': 2804, 'n_words': 724}