Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force to tag.py #76

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,38 @@ def run_command(args):
print(f'--- Running command: {" ".join(args)}')
subprocess.check_call(args)

def check_version_to_commit():
cmd = ['git', 'diff', '--cached', 'app/src/main/AndroidManifest.xml']
return subprocess.check_output(cmd) != b''

def commit_change(version):
run_command(['git', 'add', 'app/src/main/AndroidManifest.xml'])
if not check_version_to_commit():
print('--- Version did not change, nothing to commit')
return
run_command(['git', 'commit', '-m', f'Release {version}'])

def create_tag(tag):
run_command(['git', 'tag', tag])
def create_tag(tag, force):
if force:
run_command(['git', 'tag', '-f', tag])
else:
run_command(['git', 'tag', tag])

def push_change(remote, tag):
def push_change(remote, tag, force):
run_command(['git', 'push', remote, 'HEAD'])
run_command(['git', 'push', remote, tag])
if force:
run_command(['git', 'push', '-f', remote, tag])
else:
run_command(['git', 'push', remote, tag])

def main():
os.chdir(os.path.dirname(os.path.realpath(__file__)))

parser = argparse.ArgumentParser(description='Create and push tag for new release')
parser.add_argument('--push', metavar='REMOTE', required=False,
help='remote to push (e.g. "origin")')
parser.add_argument('-f', '--force', action='store_true', required=False,
help='force creation of tag, even when already exists')
parser.add_argument('version', metavar='VERSION',
help='version to release ("N.N.N" or "vN.N.N")')
args = parser.parse_args()
Expand All @@ -62,18 +77,19 @@ def main():

version = version.lstrip('v')
remote = args.push
force = args.force
tag = f'v{version}'

if check_tag_exists(tag):
if not force and check_tag_exists(tag):
print(f'Error: tag "{tag}" already exists', file=sys.stderr)
sys.exit(1)

write_version(version)
commit_change(version)
create_tag(tag)
create_tag(tag, force)
if remote:
push_change(remote, tag)
push_change(remote, tag, force)
print(f'--- Successfully released {tag}')

if __name__ == '__main__':
main()
main()