2022-08-23 04:14:06 -05:00
import datetime
import json
import os
import re
2022-12-17 06:53:37 -06:00
import subprocess
2022-08-23 04:14:06 -05:00
import sys
ref = os . getenv ( ' GITHUB_REF ' )
2023-12-03 11:00:20 -06:00
event_name = os . getenv ( ' GITHUB_EVENT_NAME ' )
2022-08-23 04:14:06 -05:00
publish_hostport = os . getenv ( ' PUBLISH_HOSTPORT ' )
2022-10-19 11:29:16 -05:00
def set_output ( key , value ) :
with open ( os . getenv ( ' GITHUB_OUTPUT ' ) , ' a ' ) as f :
f . write ( f " { key } = { value } \n " )
2022-08-23 04:14:06 -05:00
match_stable = re . fullmatch ( r ' refs/tags/v([0-9]+) \ .([0-9]+) \ .([0-9]+) ' , ref )
match_beta = re . fullmatch ( r ' refs/tags/v([0-9]+) \ .([0-9]+) \ .([0-9]+)b ' , ref )
match_snapshot = re . fullmatch ( r ' refs/tags/snapshot-([0-9]+) ' , ref )
match_tptlibsdev = re . fullmatch ( r ' refs/heads/tptlibsdev-(.*) ' , ref )
2023-12-16 07:00:11 -06:00
match_alljobs = re . fullmatch ( r ' refs/heads/(.*)-alljobs ' , ref )
2022-09-10 23:49:07 -05:00
do_release = False
2023-12-03 11:00:20 -06:00
do_priority = 10
if event_name == ' pull_request ' :
do_priority = 0
2022-08-23 04:14:06 -05:00
if match_stable :
release_type = ' stable '
release_name = ' v %s . %s . %s ' % ( match_stable . group ( 1 ) , match_stable . group ( 2 ) , match_stable . group ( 3 ) )
2022-09-10 23:49:07 -05:00
do_release = True
2023-12-03 11:00:20 -06:00
do_priority = 0
2022-08-23 04:14:06 -05:00
elif match_beta :
release_type = ' beta '
release_name = ' v %s . %s . %s b ' % ( match_beta . group ( 1 ) , match_beta . group ( 2 ) , match_beta . group ( 3 ) )
2022-09-10 23:49:07 -05:00
do_release = True
2023-12-03 11:00:20 -06:00
do_priority = 0
2022-08-23 04:14:06 -05:00
elif match_snapshot :
release_type = ' snapshot '
release_name = ' snapshot- %s ' % match_snapshot . group ( 1 )
2022-09-10 23:49:07 -05:00
do_release = True
2023-12-03 11:00:20 -06:00
do_priority = 0
2022-08-23 04:14:06 -05:00
elif match_tptlibsdev :
release_type = ' tptlibsdev '
release_name = ' tptlibsdev- %s ' % match_tptlibsdev . group ( 1 )
2023-12-03 11:00:20 -06:00
do_priority = 0
2022-08-23 04:14:06 -05:00
else :
release_type = ' dev '
release_name = ' dev '
2023-12-16 07:00:11 -06:00
if match_alljobs :
do_priority = 0
2022-09-10 23:49:07 -05:00
do_publish = publish_hostport and do_release
2022-08-23 04:14:06 -05:00
2022-10-19 11:29:16 -05:00
set_output ( ' release_type ' , release_type )
set_output ( ' release_name ' , release_name )
2022-08-23 04:14:06 -05:00
2022-12-17 06:53:37 -06:00
subprocess . run ( [ ' meson ' , ' setup ' , ' -Dprepare=true ' , ' build-prepare ' ] , check = True )
build_options = { }
with open ( ' build-prepare/meson-info/intro-buildoptions.json ' ) as f :
for option in json . loads ( f . read ( ) ) :
build_options [ option [ ' name ' ] ] = option [ ' value ' ]
2022-12-19 12:57:49 -06:00
if int ( build_options [ ' mod_id ' ] ) == 0 and os . path . exists ( ' .github/mod_id.txt ' ) :
2022-12-19 08:40:14 -06:00
with open ( ' .github/mod_id.txt ' ) as f :
build_options [ ' mod_id ' ] = f . read ( )
2022-12-24 01:41:10 -06:00
if int ( build_options [ ' mod_id ' ] ) == 0 :
2023-10-04 00:55:31 -05:00
if release_type == ' stable ' :
pass
elif release_type == ' beta ' :
2022-12-24 01:41:10 -06:00
build_options [ ' app_name ' ] + = ' Beta '
build_options [ ' app_comment ' ] + = ' - Beta '
build_options [ ' app_exe ' ] + = ' beta '
build_options [ ' app_id ' ] + = ' beta '
2023-10-04 00:55:31 -05:00
elif release_type == ' snapshot ' :
2022-12-24 01:41:10 -06:00
build_options [ ' app_name ' ] + = ' Snapshot '
build_options [ ' app_comment ' ] + = ' - Snapshot '
build_options [ ' app_exe ' ] + = ' snapshot '
build_options [ ' app_id ' ] + = ' snapshot '
2023-10-04 00:55:31 -05:00
else :
build_options [ ' app_name ' ] + = ' Dev '
build_options [ ' app_comment ' ] + = ' - Dev '
build_options [ ' app_exe ' ] + = ' dev '
build_options [ ' app_id ' ] + = ' dev '
2022-12-24 01:41:10 -06:00
2022-12-17 06:53:37 -06:00
set_output ( ' mod_id ' , build_options [ ' mod_id ' ] )
set_output ( ' app_name ' , build_options [ ' app_name ' ] )
set_output ( ' app_comment ' , build_options [ ' app_comment ' ] )
set_output ( ' app_exe ' , build_options [ ' app_exe ' ] )
set_output ( ' app_id ' , build_options [ ' app_id ' ] )
set_output ( ' app_data ' , build_options [ ' app_data ' ] )
set_output ( ' app_vendor ' , build_options [ ' app_vendor ' ] )
app_exe = build_options [ ' app_exe ' ]
app_name = build_options [ ' app_name ' ]
app_name_slug = re . sub ( ' [^A-Za-z0-9] ' , ' _ ' , app_name )
2022-08-23 04:14:06 -05:00
2022-09-10 17:06:55 -05:00
build_matrix = [ ]
publish_matrix = [ ]
2022-10-22 14:51:12 -05:00
# consider disabling line wrapping to edit this monstrosity
2023-12-03 11:00:20 -06:00
for arch , platform , libc , statdyn , bplatform , runson , suffix , publish , artifact , dbgsuffix , mode , starcatcher , dbgrel , priority in [
( ' x86_64 ' , ' linux ' , ' gnu ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' x86_64 ' , ' linux ' , ' gnu ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , True , True , ' .dbg ' , None , ' x86_64-lin-gcc-static ' , ' release ' , 10 ) ,
( ' x86_64 ' , ' linux ' , ' gnu ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , True , ' .dbg ' , ' appimage ' , None , ' release ' , 0 ) , # priority = 0: appimage release
( ' x86_64 ' , ' linux ' , ' gnu ' , ' dynamic ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , False , None , None , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' linux ' , ' gnu ' , ' dynamic ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , False , None , ' nohttp ' , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' linux ' , ' gnu ' , ' dynamic ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , False , None , ' nolua ' , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' linux ' , ' gnu ' , ' dynamic ' , ' linux ' , ' ubuntu-20.04 ' , ' ' , False , False , None , None , None , ' release ' , 10 ) ,
2023-12-16 07:00:11 -06:00
# ( 'x86_64', 'windows', 'mingw', 'static', 'linux', 'ubuntu-20.04', '', False, False, None, None, None, 'debug', 10 ), # ubuntu-20.04 doesn't have windows TLS headers somehow and I haven't yet figured out how to get them; worse, it's a different toolchain
# ( 'x86_64', 'windows', 'mingw', 'static', 'linux', 'ubuntu-20.04', '', False, True, '.dbg', None, None, 'release', 10 ), # ubuntu-20.04 doesn't have windows TLS headers somehow and I haven't yet figured out how to get them; worse, it's a different toolchain
# ( 'x86_64', 'windows', 'mingw', 'dynamic', 'linux', 'ubuntu-20.04', '', False, False, None, None, None, 'debug', 10 ), # ubuntu-20.04 doesn't have ucrt64-capable mingw >_>
# ( 'x86_64', 'windows', 'mingw', 'dynamic', 'linux', 'ubuntu-20.04', '', False, False, None, None, None, 'release', 10 ), # ubuntu-20.04 doesn't have ucrt64-capable mingw >_>
2023-12-03 11:00:20 -06:00
( ' x86_64 ' , ' windows ' , ' mingw ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' x86_64 ' , ' windows ' , ' mingw ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , True , ' .dbg ' , None , None , ' release ' , 10 ) ,
( ' x86_64 ' , ' windows ' , ' mingw ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' windows ' , ' mingw ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' release ' , 10 ) ,
( ' x86_64 ' , ' windows ' , ' msvc ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' x86_64 ' , ' windows ' , ' msvc ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , True , True , ' .pdb ' , None , ' x86_64-win-msvc-static ' , ' release ' , 10 ) ,
( ' x86_64 ' , ' windows ' , ' msvc ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' windows ' , ' msvc ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , ' backendvs ' , None , ' debug ' , 0 ) , # priority = 0: backend=vs build
( ' x86_64 ' , ' windows ' , ' msvc ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' release ' , 10 ) ,
( ' x86 ' , ' windows ' , ' msvc ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' x86 ' , ' windows ' , ' msvc ' , ' static ' , ' windows ' , ' windows-2019 ' , ' .exe ' , True , True , ' .pdb ' , None , ' i686-win-msvc-static ' , ' release ' , 10 ) ,
( ' x86 ' , ' windows ' , ' msvc ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' debug ' , 10 ) ,
( ' x86 ' , ' windows ' , ' msvc ' , ' dynamic ' , ' windows ' , ' windows-2019 ' , ' .exe ' , False , False , None , None , None , ' release ' , 10 ) ,
2024-01-01 14:06:15 -06:00
( ' x86_64 ' , ' darwin ' , ' macos ' , ' static ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , False , False , None , ' dmg ' , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' x86_64 ' , ' darwin ' , ' macos ' , ' static ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , True , True , None , ' dmg ' , ' x86_64-mac-gcc-static ' , ' release ' , 10 ) , # I have no idea how to separate debug info on macos
( ' x86_64 ' , ' darwin ' , ' macos ' , ' dynamic ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , False , False , None , ' dmg ' , None , ' debug ' , 10 ) ,
( ' x86_64 ' , ' darwin ' , ' macos ' , ' dynamic ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , False , False , None , ' dmg ' , None , ' release ' , 10 ) ,
( ' aarch64 ' , ' darwin ' , ' macos ' , ' static ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , False , False , None , ' dmg ' , None , ' debug ' , 0 ) , # priority = 0: static debug build
( ' aarch64 ' , ' darwin ' , ' macos ' , ' static ' , ' darwin ' , ' macos-12 ' , ' .dmg ' , True , True , None , ' dmg ' , ' arm64-mac-gcc-static ' , ' release ' , 10 ) ,
# ( 'aarch64', 'darwin', 'macos', 'dynamic', 'darwin', 'macos-12', '.dmg', False, False, None, 'dmg', None, 'debug', 10 ), # macos-11.0 is x86_64 and I haven't yet figured out how to get homebrew to install aarch64 libs on x86_64
# ( 'aarch64', 'darwin', 'macos', 'dynamic', 'darwin', 'macos-12', '.dmg', False, False, None, 'dmg', None, 'release', 10 ), # macos-11.0 is x86_64 and I haven't yet figured out how to get homebrew to install aarch64 libs on x86_64
2023-12-03 11:00:20 -06:00
( ' x86 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: rarely used debug build
( ' x86 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , True , True , ' .dbg ' , None , ' i686-and-gcc-static ' , ' release ' , 10 ) ,
( ' x86_64 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: rarely used debug build
( ' x86_64 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , True , True , ' .dbg ' , None , ' x86_64-and-gcc-static ' , ' release ' , 10 ) ,
( ' arm ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: rarely used debug build
( ' arm ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , True , True , ' .dbg ' , None , ' arm-and-gcc-static ' , ' release ' , 10 ) ,
( ' aarch64 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: rarely used debug build
( ' aarch64 ' , ' android ' , ' bionic ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .apk ' , True , True , ' .dbg ' , None , ' arm64-and-gcc-static ' , ' release ' , 10 ) ,
( ' wasm32 ' , ' emscripten ' , ' emscripten ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .tar ' , False , False , None , None , None , ' debug ' , 0 ) , # priority = 0: rarely used debug build
( ' wasm32 ' , ' emscripten ' , ' emscripten ' , ' static ' , ' linux ' , ' ubuntu-20.04 ' , ' .tar ' , True , True , None , ' emscripten ' , ' wasm32-ems-static ' , ' release ' , 10 ) , # I have no idea how to separate debug info on emscripten
2022-08-23 04:14:06 -05:00
] :
2023-12-03 11:00:20 -06:00
if priority < do_priority :
continue
2023-12-03 11:24:49 -06:00
job_name = f ' build '
if starcatcher :
job_name + = f ' +target=starcatcher- { starcatcher } '
else :
job_name + = f ' +target= { arch } - { platform } - { libc } - { statdyn } - { dbgrel } '
if mode :
job_name + = f ' +mode= { mode } '
if bplatform != platform :
job_name + = f ' +bplatform= { bplatform } '
2022-11-03 01:05:31 -05:00
if not mode :
mode = ' default '
2022-08-23 04:14:06 -05:00
separate_debug = True
2022-11-03 01:05:31 -05:00
if not dbgsuffix :
dbgsuffix = ' BOGUS '
2022-08-23 04:14:06 -05:00
separate_debug = False
2022-11-03 01:05:31 -05:00
if not starcatcher :
starcatcher = ' BOGUS '
2022-09-10 17:06:55 -05:00
if publish :
assert artifact
2022-11-03 01:05:31 -05:00
if dbgrel != ' release ' :
assert not publish
assert not artifact
2022-12-17 06:53:37 -06:00
asset_path = f ' { app_exe } { suffix } '
asset_name = f ' { app_exe } - { release_name } - { arch } - { platform } - { libc } { suffix } '
debug_asset_path = f ' { app_exe } { dbgsuffix } '
debug_asset_name = f ' { app_exe } - { release_name } - { arch } - { platform } - { libc } { dbgsuffix } '
2022-11-03 01:05:31 -05:00
if mode == ' appimage ' :
2022-12-17 06:53:37 -06:00
asset_path = f ' { app_name_slug } - { arch } .AppImage '
asset_name = f ' { app_name_slug } - { arch } .AppImage '
debug_asset_path = f ' { app_name_slug } - { arch } .AppImage.dbg '
debug_asset_name = f ' { app_name_slug } - { arch } .AppImage.dbg '
2022-11-03 01:05:31 -05:00
starcatcher_name = f ' powder- { release_name } - { starcatcher } { suffix } '
2024-02-21 04:13:18 -06:00
msys2_bash = ( bplatform == ' windows ' and libc == ' mingw ' )
shell = ' bash '
if msys2_bash :
shell = ' msys2 {0} '
2022-11-03 01:05:31 -05:00
build_matrix . append ( {
' bsh_build_platform ' : bplatform , # part of the unique portion of the matrix
' bsh_host_arch ' : arch , # part of the unique portion of the matrix
' bsh_host_platform ' : platform , # part of the unique portion of the matrix
' bsh_host_libc ' : libc , # part of the unique portion of the matrix
' bsh_static_dynamic ' : statdyn , # part of the unique portion of the matrix
' bsh_debug_release ' : dbgrel , # part of the unique portion of the matrix
' runs_on ' : runson ,
2024-02-21 04:13:18 -06:00
' force_msys2_bash ' : msys2_bash and ' yes ' or ' no ' ,
2022-11-03 01:05:31 -05:00
' package_suffix ' : suffix ,
' package_mode ' : mode ,
' publish ' : publish and ' yes ' or ' no ' ,
' artifact ' : artifact and ' yes ' or ' no ' ,
' separate_debug ' : separate_debug and ' yes ' or ' no ' ,
' asset_path ' : asset_path ,
' asset_name ' : asset_name ,
' debug_asset_path ' : debug_asset_path ,
' debug_asset_name ' : debug_asset_name ,
2023-12-03 11:24:49 -06:00
' job_name ' : job_name ,
2024-02-21 04:13:18 -06:00
' shell ' : shell ,
2022-11-03 01:05:31 -05:00
} )
if publish :
publish_matrix . append ( {
' bsh_build_platform ' : bplatform , # part of the unique portion of the matrix
' bsh_host_arch ' : arch , # part of the unique portion of the matrix
' bsh_host_platform ' : platform , # part of the unique portion of the matrix
' bsh_host_libc ' : libc , # part of the unique portion of the matrix
' bsh_static_dynamic ' : statdyn , # part of the unique portion of the matrix
2022-09-15 04:52:04 -05:00
' asset_path ' : asset_path ,
' asset_name ' : asset_name ,
2022-11-03 01:05:31 -05:00
' starcatcher_name ' : starcatcher_name ,
2022-08-23 04:14:06 -05:00
} )
2022-10-19 11:29:16 -05:00
set_output ( ' build_matrix ' , json . dumps ( { ' include ' : build_matrix } ) )
set_output ( ' publish_matrix ' , json . dumps ( { ' include ' : publish_matrix } ) )
set_output ( ' do_release ' , do_release and ' yes ' or ' no ' )
set_output ( ' do_publish ' , do_publish and ' yes ' or ' no ' )