Skip to content

Commit

Permalink
Add --force to tag.py
Browse files Browse the repository at this point in the history
Fix missing parameter
  • Loading branch information
Geoffrey JOUNT authored and ortex committed Sep 19, 2023
1 parent 96c8c93 commit ae9b647
Showing 1 changed file with 24 additions and 8 deletions.
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()

0 comments on commit ae9b647

Please sign in to comment.