-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
executable file
·73 lines (61 loc) · 2.36 KB
/
release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
#
# Copyright (c) 2020 Basile Maret.
#
# This file is part of BUVIC - Brewer UV Irradiance Calculator
# (see https://github.com/pec0ra/buvic).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
from subprocess import PIPE, run
FNULL = open(os.devnull, "w")
def run_command(command, show_std_err=False, pipe_stdout=True):
stderr = None if show_std_err else FNULL
stdout = PIPE if pipe_stdout else None
result = run(command, stdout=stdout, stderr=stderr, shell=True)
return result
def make_release(new_version):
print(f"* Will create a release for version {new_version}")
print()
print("* Checking branch state")
res = run_command("git status --porcelain", show_std_err=True)
if res.returncode != 0:
print("An unexpected error occurred.")
exit(1)
if len(res.stdout) != 0:
print("Branch is not clean. Please commit your changes before making a release")
exit(1)
res = run_command("git describe --abbrev=0", show_std_err=True)
last_version = res.stdout.decode().strip()
if last_version == new_version:
print("Version number has not changed since last release. Please change it in the file 'version' before running this script.")
exit(1)
print()
print("* Creating git tag")
res = run_command(f'git tag {new_version} -a -m "UV Server {new_version}"', True)
if res.returncode != 0:
print("An error occurred while creating the tag")
exit(1)
res = run_command(f"git push --tags --porcelain", True)
if res.returncode != 0:
print("An error occurred while creating the tag")
exit(1)
try:
if len(sys.argv) != 2:
print("Usage: ./release <version>")
make_release(sys.argv[1])
except KeyboardInterrupt:
exit(1)