11#!/usr/bin/env python3
2- # This script is trigged from the Github Autobuild workflow.
3- # It analyzes Jamulus.pro and git push details (tag vs. branch, etc.) to decide
4- # - whether a release should be created,
5- # - whether it is a pre-release, and
6- # - what its title should be.
2+ ##############################################################################
3+ # Copyright (c) 2022-2024
4+ #
5+ # Author(s):
6+ # Christian Hoffmann
7+ # The Jamulus Development Team
8+ #
9+ ##############################################################################
10+ #
11+ # This program is free software; you can redistribute it and/or modify it under
12+ # the terms of the GNU General Public License as published by the Free Software
13+ # Foundation; either version 2 of the License, or (at your option) any later
14+ # version.
15+ #
16+ # This program is distributed in the hope that it will be useful, but WITHOUT
17+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18+ # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19+ # details.
20+ #
21+ # You should have received a copy of the GNU General Public License along with
22+ # this program; if not, write to the Free Software Foundation, Inc.,
23+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24+ #
25+ ##############################################################################
26+
27+ """
28+ This script is triggered from the GitHub Autobuild workflow.
29+ It analyzes Jamulus.pro and git push details (tag vs. branch, etc.) to decide
30+ - whether a release should be created,
31+ - whether it is a pre-release, and
32+ - what its title should be.
33+ """
734
835import os
936import re
1542def get_version_from_jamulus_pro ():
1643 with open (REPO_PATH + '/Jamulus.pro' , 'r' ) as f :
1744 pro_content = f .read ()
18- m = re .search (r'^VERSION\s*=\s*(\S+)$' , pro_content , re .MULTILINE )
19- if not m :
20- raise Exception ("Unable to determine Jamulus.pro VERSION" )
21- return m .group (1 )
45+ matches = re .search (r'^VERSION\s*=\s*(\S+)$' , pro_content , re .MULTILINE )
46+ if not matches :
47+ raise ValueError ("Unable to determine Jamulus.pro VERSION" )
48+ return matches .group (1 )
2249
2350
2451def get_git_hash ():
@@ -34,26 +61,26 @@ def get_git_hash():
3461
3562def get_build_version (jamulus_pro_version ):
3663 if "dev" in jamulus_pro_version :
37- version = "{ }-{}" . format ( jamulus_pro_version , get_git_hash ())
64+ version = f" { jamulus_pro_version } -{ get_git_hash ()} "
3865 return 'intermediate' , version
3966
4067 version = jamulus_pro_version
4168 return 'release' , version
4269
4370
4471def set_github_variable (varname , varval ):
45- print ("{ }='{}'". format ( varname , varval ) ) # console output
46- outputfile = os .getenv ('GITHUB_OUTPUT' )
47- with open (outputfile , "a" ) as ghout :
72+ print (f" { varname } ='{ varval } '" ) # console output
73+ output_file = os .getenv ('GITHUB_OUTPUT' )
74+ with open (output_file , "a" ) as ghout :
4875 ghout .write (f"{ varname } ={ varval } \n " )
4976
5077jamulus_pro_version = get_version_from_jamulus_pro ()
5178set_github_variable ("JAMULUS_PRO_VERSION" , jamulus_pro_version )
5279build_type , build_version = get_build_version (jamulus_pro_version )
5380print (f'building a version of type "{ build_type } ": { build_version } ' )
5481
55- fullref = os .environ ['GITHUB_REF' ]
56- publish_to_release = bool (re .match (r'^refs/tags/r\d+_\d+_\d+\S*$' , fullref ))
82+ full_ref = os .environ ['GITHUB_REF' ]
83+ publish_to_release = bool (re .match (r'^refs/tags/r\d+_\d+_\d+\S*$' , full_ref ))
5784
5885# BUILD_VERSION is required for all builds including branch pushes
5986# and PRs:
@@ -65,12 +92,12 @@ def set_github_variable(varname, varval):
6592set_github_variable ("PUBLISH_TO_RELEASE" , str (publish_to_release ).lower ())
6693
6794if publish_to_release :
68- reflist = fullref .split ("/" , 2 )
69- release_tag = reflist [2 ]
95+ ref_list = full_ref .split ("/" , 2 )
96+ release_tag = ref_list [2 ]
7097 release_title = f"Release { build_version } ({ release_tag } )"
7198 is_prerelease = not re .match (r'^r\d+_\d+_\d+$' , release_tag )
7299 if not is_prerelease and build_version != release_tag [1 :].replace ('_' , '.' ):
73- raise Exception (f"non-pre-release tag { release_tag } doesn't match Jamulus.pro VERSION = { build_version } " )
100+ raise ValueError (f"non-pre-release tag { release_tag } doesn't match Jamulus.pro VERSION = { build_version } " )
74101
75102 # Those variables are only used when a release is created at all:
76103 set_github_variable ("IS_PRERELEASE" , str (is_prerelease ).lower ())
0 commit comments