fork/wezterm
git clone https://git.julia.blue/fork/wezterm
d1bdb8a35
main
1#!/usr/bin/env python3 2import os 3import sys 4import glob 5from copy import deepcopy 6 7TRIGGER_PATHS = [ 8"**/*.rs" , 9"**/Cargo.lock" , 10"**/Cargo.toml" , 11".cargo/config.toml" , 12"assets/fonts/**/*" , 13"assets/icon/*" , 14"ci/deploy.sh" , 15] 16 17TRIGGER_PATHS_APPIMAGE = [ 18"ci/appimage.sh" , 19"ci/appstreamcli" , 20"ci/source-archive.sh" , 21] 22 23TRIGGER_PATHS_UNIX = [ 24"assets/open-wezterm-here" , 25"assets/shell-completion/**/*" , 26"assets/shell-integration/**/*" , 27"assets/wezterm-nautilus.py" , 28"assets/wezterm.appdata.xml" , 29"assets/wezterm.desktop" , 30"get-deps" , 31"ci/tag-name.sh" , 32"termwiz/data/wezterm.terminfo" , 33] 34 35TRIGGER_PATHS_MAC = [ 36"assets/macos/**/*" , 37"ci/macos-entitlement.plist" , 38"get-deps" , 39"ci/tag-name.sh" , 40] 41 42TRIGGER_PATHS_WIN = [ 43"assets/windows/**/*" , 44"ci/windows-installer.iss" , 45] 46 47 48def yv (v ,depth = 0 ): 49if v is True : 50return "true" 51if v is False : 52return "false" 53if v is None : 54return "nil" 55 56if isinstance (v ,str ): 57if "\n" in v : 58indent = " " * depth 59result = "" 60for l in v .splitlines (): 61result = result + "\n" + (f" { indent } { l } " if l else "" ) 62return "|" + result 63# This is hideous 64if '"' in v : 65return "'" + v + "'" 66return '"' + v + '"' 67 68return v 69 70 71class Step (object ): 72def render (self ,f ,depth = 0 ): 73raise NotImplementedError (repr (self )) 74 75 76class RunStep (Step ): 77def __init__ (self ,name ,run ,shell = "bash" ,env = None ,condition = None ): 78self .name = name 79self .run = run 80self .shell = shell 81self .env = env 82self .condition = condition 83 84def render (self ,f ,depth = 0 ): 85indent = " " * depth 86f .write (f" { indent } - name: { yv ( self . name ) } \n" ) 87if self .condition : 88f .write (f" { indent } if: { self . condition } \n" ) 89if self .env : 90f .write (f" { indent } env:\n" ) 91keys = list (self .env .keys ()) 92keys .sort () 93for k in keys : 94v = self .env [k ] 95f .write (f" { indent } { k } : { v } \n" ) 96if self .shell : 97f .write (f" { indent } shell: { self . shell } \n" ) 98 99run = self .run 100 101f .write (f" { indent } run: { yv ( run , depth + 2 ) } \n" ) 102 103 104class ActionStep (Step ): 105def __init__ (self ,name ,action ,params = None ,env = None ,condition = None ,id = None ): 106self .name = name 107self .action = action 108self .params = params 109self .env = env 110self .condition = condition 111self .id = id 112 113def render (self ,f ,depth = 0 ): 114indent = " " * depth 115f .write (f" { indent } - name: { yv ( self . name ) } \n" ) 116f .write (f" { indent } uses: { self . action } \n" ) 117if self .id : 118f .write (f" { indent } id: { self . id } \n" ) 119if self .condition : 120f .write (f" { indent } if: { self . condition } \n" ) 121if self .params : 122f .write (f" { indent } with:\n" ) 123for k ,v in self .params .items (): 124f .write (f" { indent } { k } : { yv ( v , depth + 3 ) } \n" ) 125if self .env : 126f .write (f" { indent } env:\n" ) 127for k ,v in self .env .items (): 128f .write (f" { indent } { k } : { yv ( v , depth + 3 ) } \n" ) 129 130 131class CacheStep (ActionStep ): 132def __init__ (self ,name ,path ,key ,id = None ): 133super ().__init__ ( 134name ,action = "actions/cache@v4" ,params = {"path" :path ,"key" :key },id = id 135 ) 136 137 138class SccacheStep (ActionStep ): 139def __init__ (self ,name ): 140super ().__init__ (name ,action = "mozilla-actions/sccache-action@v0.0.9" ) 141 142 143class CheckoutStep (ActionStep ): 144def __init__ (self ,name = "checkout repo" ,submodules = True ,container = None ): 145params = {} 146if submodules : 147params ["submodules" ]= "recursive" 148# Newer versions of the checkout action use a binary-incompatible node 149# binary, so we are pinned back on v3 150# https://github.com/actions/checkout/issues/1442 151version = "v3" if container is not None and "centos7" in container else "v4" 152super ().__init__ (name ,action = f"actions/checkout@ { version } " ,params = params ) 153 154 155class InstallCrateStep (ActionStep ): 156def __init__ (self ,crate :str ,key :str ,version = None ): 157params = {"crate" :crate ,"cache-key" :key } 158if version is not None : 159params ["version" ]= version 160super ().__init__ ( 161f"Install { crate } from Cargo" , 162action = "baptiste0928/cargo-install@v3" , 163params = params , 164 ) 165 166 167class Job (object ): 168def __init__ (self ,runs_on ,container = None ,steps = None ,env = None ): 169self .runs_on = runs_on 170self .container = container 171self .steps = steps 172self .env = env 173 174def render (self ,f ,depth = 0 ): 175f .write ("\n steps:\n" ) 176for s in self .steps : 177s .render (f ,depth ) 178 179 180class Target (object ): 181def __init__ ( 182self , 183name = None , 184os = "ubuntu-latest" , 185container = None , 186bootstrap_git = False , 187rust_target = None , 188continuous_only = False , 189app_image = False , 190is_tag = False , 191 ): 192if not name : 193if container : 194name = container 195else : 196name = os 197self .name = name .replace (":" ,"" ) 198self .os = os 199self .container = container 200self .bootstrap_git = bootstrap_git 201self .rust_target = rust_target 202self .continuous_only = continuous_only 203self .app_image = app_image 204self .env = {} 205self .is_tag = is_tag 206 207def render_env (self ,f ,depth = 0 ): 208self .global_env () 209if self .env : 210indent = " " 211f .write (f" { indent } env:\n" ) 212for k ,v in self .env .items (): 213f .write (f" { indent } { k } : { yv ( v , depth + 3 ) } \n" ) 214 215def uses_yum (self ): 216if "fedora" in self .name : 217return True 218if "centos" in self .name : 219return True 220return False 221 222def uses_apt (self ): 223if "ubuntu" in self .name : 224return True 225if "debian" in self .name : 226return True 227return False 228 229def uses_apk (self ): 230if "alpine" in self .name : 231return True 232return False 233 234def uses_zypper (self ): 235if "suse" in self .name : 236return True 237return False 238 239def needs_sudo (self ): 240if not self .container and self .uses_apt (): 241return True 242return False 243 244def install_system_package (self ,name ): 245installer = None 246if self .uses_yum (): 247installer = "yum" 248elif self .uses_apt (): 249installer = "apt-get" 250elif self .uses_apk (): 251installer = "apk" 252elif self .uses_zypper (): 253installer = "zypper" 254else : 255return [] 256if self .needs_sudo (): 257installer = f"sudo -n { installer } " 258if self .uses_apk (): 259return [RunStep (f"Install { name } " ,f" { installer } add { name } " )] 260else : 261return [RunStep (f"Install { name } " ,f" { installer } install -y { name } " )] 262 263def install_curl (self ): 264if ( 265self .uses_yum () 266or self .uses_apk () 267or self .uses_zypper () 268or (self .uses_apt ()and self .container ) 269 ): 270if "centos:stream9" in self .container : 271return self .install_system_package ("curl-minimal" ) 272else : 273return self .install_system_package ("curl" ) 274return [] 275 276def install_openssh_server (self ): 277steps = [] 278if ( 279self .uses_yum () 280or self .uses_zypper () 281or (self .uses_apt ()and self .container ) 282 ): 283steps += [ 284RunStep ("Ensure /run/sshd exists" ,"mkdir -p /run/sshd" ) 285 ]+ self .install_system_package ("openssh-server" ) 286if self .uses_apk (): 287steps += self .install_system_package ("openssh" ) 288return steps 289 290def install_newer_compiler (self ): 291steps = [] 292if self .name == "centos7" : 293steps .append ( 294RunStep ( 295"Install SCL" , 296"yum install -y centos-release-scl-rh" , 297 ) 298 ) 299steps .append ( 300RunStep ( 301"Update compiler" , 302"yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++" , 303 ) 304 ) 305return steps 306 307def install_git (self ): 308steps = [] 309if self .bootstrap_git : 310GIT_VERS = "2.26.2" 311steps .append ( 312CacheStep ( 313"Cache Git installation" , 314path = "/usr/local/git" , 315key = f" { self . name } -git- { GIT_VERS } " , 316 ) 317 ) 318 319pre_reqs = "" 320if self .uses_yum (): 321pre_reqs = "yum install -y wget curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker make" 322elif self .uses_apt (): 323pre_reqs = "apt-get install -y wget libcurl4-openssl-dev libexpat-dev gettext libssl-dev libz-dev gcc libextutils-autoinstall-perl make" 324elif self .uses_zypper (): 325pre_reqs = "zypper install -y wget libcurl-devel libexpat-devel gettext-tools libopenssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker make" 326 327steps .append ( 328RunStep ( 329name = "Install Git from source" , 330shell = "bash" , 331run = f""" { pre_reqs } 332if test ! -x /usr/local/git/bin/git ; then 333cd /tmp 334wget https://github.com/git/git/archive/v { GIT_VERS } .tar.gz 335tar xzf v { GIT_VERS } .tar.gz 336cd git- { GIT_VERS } 337make prefix=/usr/local/git install 338fi 339ln -s /usr/local/git/bin/git /usr/local/bin/git""" , 340 ) 341 ) 342 343else : 344if "tumbleweed" in self .name : 345# git-core requires /usr/bin/which and that gets satisfied 346# by busybox-which by default, which blocks installing 347# rpmbuild, which depends on the which rpm directly, 348# but that is blocked by the conflicting busybox-which rpm. 349# So we explicitly install which here now 350steps += self .install_system_package ("which" ) 351 352steps += self .install_system_package ("git" ) 353 354return steps 355 356def install_rust (self ,cache = True ,toolchain = "stable" ): 357salt = "2" 358key_prefix = f" { self . name } - { self . rust_target } - { salt } -${{{{ runner.os }}}}" 359params = dict () 360if self .rust_target : 361params ["target" ]= self .rust_target 362steps = [] 363# Manually setup rust toolchain in CentOS7 curl is too old for the action 364if "centos7" in self .name : 365steps += [ 366RunStep ( 367name = "Install Rustup" , 368run = """ 369if ! command -v rustup &>/dev/null; then 370curl --proto '=https' --tlsv1.2 --retry 10 -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y 371echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH 372fi 373""" , 374 ), 375RunStep ( 376name = "Setup Toolchain" , 377run = f""" 378rustup toolchain install { toolchain } --profile minimal --no-self-update 379rustup default { toolchain } 380""" , 381 ), 382 ] 383elif "macos" in self .name : 384steps += [ 385RunStep ( 386name = "Install Rust (ARM)" , 387run = "rustup target add aarch64-apple-darwin" , 388 ), 389RunStep ( 390name = "Install Rust (Intel)" , 391run = "rustup target add x86_64-apple-darwin" , 392 ) 393 ] 394else : 395steps += [ 396ActionStep ( 397name = "Install Rust" , 398action = f"dtolnay/rust-toolchain@ { toolchain } " , 399params = params , 400 ), 401 ] 402if cache : 403steps += [ 404SccacheStep (name = "Compile with sccache" ), 405# Cache vendored dependecies 406CacheStep ( 407name = "Cache Rust Dependencies" , 408path = "vendor\n.cargo/config" , 409key = "cargo-deps-${{ hashFiles('**/Cargo.lock') }}" , 410id = "cache-cargo-vendor" , 411 ), 412# Vendor dependencies 413RunStep ( 414name = "Vendor dependecies" , 415condition = "steps.cache-cargo-vendor.outputs.cache-hit != 'true'" , 416run = "cargo vendor --locked --versioned-dirs >> .cargo/config" , 417 ), 418 ] 419return steps 420 421def install_system_deps (self ): 422if "win" in self .name : 423return [] 424sudo = "sudo -n " if self .needs_sudo ()else "" 425return [ 426RunStep ( 427name = "Install System Deps" , 428run = f" { sudo } env CI=yes PATH=$PATH ./get-deps" , 429 ) 430 ] 431 432def fixup_windows_path (self ,cmd ): 433if "win" in self .name : 434return "PATH C:\\Strawberry\\perl\\bin;%PATH%\n" + cmd 435return cmd 436 437def build_all_release (self ): 438bin_crates = [ 439"wezterm" , 440"wezterm-gui" , 441"wezterm-mux-server" , 442"strip-ansi-escapes" , 443 ] 444steps = [] 445for bin in bin_crates : 446if "win" in self .name : 447steps += [ 448RunStep ( 449name = f"Build { bin } (Release mode)" , 450shell = "cmd" , 451run = self .fixup_windows_path (f"cargo build -p { bin } --release" ), 452 ) 453 ] 454elif "macos" in self .name : 455steps += [ 456RunStep ( 457name = f"Build { bin } (Release mode Intel)" , 458run = f"cargo build --target x86_64-apple-darwin -p { bin } --release" , 459 ), 460RunStep ( 461name = f"Build { bin } (Release mode ARM)" , 462run = f"cargo build --target aarch64-apple-darwin -p { bin } --release" , 463 ), 464 ] 465else : 466if self .name == "centos7" : 467enable = "source /opt/rh/devtoolset-9/enable && " 468else : 469enable = "" 470steps += [ 471RunStep ( 472name = f"Build { bin } (Release mode)" , 473run = enable + f"cargo build -p { bin } --release" , 474 ) 475 ] 476return steps 477 478def test_all (self ): 479run = "cargo nextest run --all --no-fail-fast" 480if "macos" in self .name : 481run += " --target=x86_64-apple-darwin" 482if self .name == "centos7" : 483run = "source /opt/rh/devtoolset-9/enable\n" + run 484return [ 485# Install cargo-nextest 486InstallCrateStep ("cargo-nextest" ,key = self .name ), 487# Run tests 488RunStep (name = "Test" ,run = self .fixup_windows_path (run ),shell = "cmd" ) 489if "win" in self .name 490else RunStep (name = "Test" ,run = run ), 491 ] 492 493def package (self ,trusted = False ): 494steps = [] 495deploy_env = None 496if trusted and ("mac" in self .name ): 497deploy_env = { 498"MACOS_CERT" :"${{ secrets.MACOS_CERT }}" , 499"MACOS_CERT_PW" :"${{ secrets.MACOS_CERT_PW }}" , 500"MACOS_TEAM_ID" :"${{ secrets.MACOS_TEAM_ID }}" , 501"MACOS_APPLEID" :"${{ secrets.MACOS_APPLEID }}" , 502"MACOS_APP_PW" :"${{ secrets.MACOS_APP_PW }}" , 503 } 504steps = [RunStep ("Package" ,"bash ci/deploy.sh" ,env = deploy_env )] 505if self .app_image : 506# AppImage needs fuse 507steps += self .install_system_package ("libfuse2" ) 508steps .append (RunStep ("Source Tarball" ,"bash ci/source-archive.sh" )) 509steps .append (RunStep ("Build AppImage" ,"bash ci/appimage.sh" )) 510return steps 511 512def upload_artifact (self ): 513steps = [] 514 515if self .uses_yum (): 516steps .append ( 517RunStep ( 518"Move RPM" , 519f"mv ~/rpmbuild/RPMS/*/*.rpm ." , 520 ) 521 ) 522elif self .uses_apk (): 523steps += [ 524# Add the distro name/version into the filename 525RunStep ( 526"Rename APKs" , 527f"mv ~/packages/wezterm/x86_64/*.apk $(echo ~/packages/wezterm/x86_64/*.apk | sed -e 's/wezterm-/wezterm- { self . name } -/')" , 528 ), 529# Move it to the repo dir 530RunStep ( 531"Move APKs" , 532f"mv ~/packages/wezterm/x86_64/*.apk ." , 533 ), 534# Move and rename the keys 535RunStep ( 536"Move APK keys" , 537f"mv ~/.abuild/*.pub wezterm- { self . name } .pub" , 538 ), 539 ] 540elif self .uses_zypper (): 541steps .append ( 542RunStep ( 543"Move RPM" , 544f"mv /usr/src/packages/RPMS/*/*.rpm ." , 545 ) 546 ) 547 548patterns = self .asset_patterns () 549glob = " " .join (patterns ) 550paths = "\n" .join (patterns ) 551 552return steps + [ 553ActionStep ( 554"Upload artifact" , 555action = "actions/upload-artifact@v4" , 556params = {"name" :self .name ,"path" :paths }, 557 ), 558 ] 559 560def asset_patterns (self ): 561patterns = [] 562if self .uses_yum ()or self .uses_zypper (): 563patterns += ["wezterm-*.rpm" ] 564elif "win" in self .name : 565patterns += ["WezTerm-*.zip" ,"WezTerm-*.exe" ] 566elif "mac" in self .name : 567patterns += ["WezTerm-*.zip" ] 568elif ("ubuntu" in self .name )or ("debian" in self .name ): 569patterns += ["wezterm-*.deb" ,"wezterm-*.xz" ] 570elif "alpine" in self .name : 571patterns += ["wezterm-*.apk" ] 572if self .is_tag : 573patterns .append ("*.pub" ) 574 575if self .app_image : 576patterns .append ("*src.tar.gz" ) 577patterns .append ("*.AppImage" ) 578#patterns.append("*.zsync") broken upstream: <https://github.com/linuxdeploy/linuxdeploy/issues/309> 579return patterns 580 581def upload_artifact_nightly (self ): 582steps = [] 583 584if self .uses_yum (): 585steps .append ( 586RunStep ( 587"Move RPM" , 588f"mv ~/rpmbuild/RPMS/*/*.rpm wezterm-nightly- { self . name } .rpm" , 589 ) 590 ) 591elif self .uses_apk (): 592steps .append ( 593RunStep ( 594"Move APKs" , 595f"mv ~/packages/wezterm/x86_64/*.apk wezterm-nightly- { self . name } .apk" , 596 ) 597 ) 598elif self .uses_zypper (): 599steps .append ( 600RunStep ( 601"Move RPM" , 602f"mv /usr/src/packages/RPMS/*/*.rpm wezterm-nightly- { self . name } .rpm" , 603 ) 604 ) 605 606patterns = self .asset_patterns () 607glob = " " .join (patterns ) 608paths = "\n" .join (patterns ) 609 610return steps + [ 611ActionStep ( 612"Upload artifact" , 613action = "actions/upload-artifact@v4" , 614params = {"name" :self .name ,"path" :paths ,"retention-days" :5 }, 615 ), 616 ] 617 618def upload_asset_nightly (self ): 619steps = [] 620 621patterns = self .asset_patterns () 622checksum = RunStep ( 623"Checksum" , 624f"for f in { ' ' . join ( patterns ) } ; do sha256sum $f > $f.sha256 ; done" , 625 ) 626 627patterns .append ("*.sha256" ) 628glob = " " .join (patterns ) 629 630if self .container == "ubuntu:22.04" : 631steps += [ 632RunStep ( 633"Upload to gemfury" , 634f"for f in wezterm*.deb ; do curl -i -F package=@$f https://$FURY_TOKEN@push.fury.io/wez/ ; done" , 635env = {"FURY_TOKEN" :"${{ secrets.FURY_TOKEN }}" }, 636 ), 637 ] 638 639return [ 640ActionStep ( 641"Download artifact" , 642action = "actions/download-artifact@v4" , 643params = {"name" :self .name }, 644 ), 645checksum , 646RunStep ( 647"Upload to Nightly Release" , 648f"bash ci/retry.sh gh release upload --clobber nightly { glob } " , 649env = {"GITHUB_TOKEN" :"${{ secrets.GITHUB_TOKEN }}" }, 650 ), 651 ]+ steps 652 653def upload_asset_tag (self ): 654steps = [] 655 656patterns = self .asset_patterns () 657checksum = RunStep ( 658"Checksum" , 659f"for f in { ' ' . join ( patterns ) } ; do sha256sum $f > $f.sha256 ; done" , 660 ) 661 662patterns .append ("*.sha256" ) 663glob = " " .join (patterns ) 664 665if self .container == "ubuntu:22.04" : 666steps += [ 667RunStep ( 668"Upload to gemfury" , 669f"for f in wezterm*.deb ; do curl -i -F package=@$f https://$FURY_TOKEN@push.fury.io/wez/ ; done" , 670env = {"FURY_TOKEN" :"${{ secrets.FURY_TOKEN }}" }, 671 ), 672 ] 673 674return steps + [ 675ActionStep ( 676"Download artifact" , 677action = "actions/download-artifact@v4" , 678params = {"name" :self .name }, 679 ), 680checksum , 681RunStep ( 682"Create pre-release" , 683"bash ci/retry.sh bash ci/create-release.sh $(ci/tag-name.sh)" , 684env = { 685"GITHUB_TOKEN" :"${{ secrets.GITHUB_TOKEN }}" , 686 }, 687 ), 688RunStep ( 689"Upload to Tagged Release" , 690f"bash ci/retry.sh gh release upload --clobber $(ci/tag-name.sh) { glob } " , 691env = { 692"GITHUB_TOKEN" :"${{ secrets.GITHUB_TOKEN }}" , 693 }, 694 ), 695 ] 696 697def create_flathub_pr (self ): 698if not self .app_image : 699return [] 700return [ 701ActionStep ( 702"Checkout flathub/org.wezfurlong.wezterm" , 703action = "actions/checkout@v4" , 704params = { 705"repository" :"flathub/org.wezfurlong.wezterm" , 706"path" :"flathub" , 707"token" :"${{ secrets.GH_PAT }}" , 708 }, 709 ), 710RunStep ( 711"Create flathub commit and push" , 712"bash ci/make-flathub-pr.sh" , 713 ), 714RunStep ( 715"Submit PR" , 716'cd flathub && gh pr create --fill --body "PR automatically created by release automation in the wezterm repo"' , 717env = { 718"GITHUB_TOKEN" :"${{ secrets.GH_PAT }}" , 719 }, 720 ), 721 ] 722 723def create_winget_pr (self ): 724steps = [] 725if "windows" in self .name : 726steps += [ 727ActionStep ( 728"Checkout winget-pkgs" , 729action = "actions/checkout@v4" , 730params = { 731"repository" :"wez/winget-pkgs" , 732"path" :"winget-pkgs" , 733"token" :"${{ secrets.GH_PAT }}" , 734 }, 735 ), 736RunStep ( 737"Setup email for winget repo" , 738"cd winget-pkgs && git config user.email wez@wezfurlong.org" , 739 ), 740RunStep ( 741"Setup name for winget repo" , 742"cd winget-pkgs && git config user.name 'Wez Furlong'" , 743 ), 744RunStep ( 745"Create winget manifest and push to fork" , 746"bash ci/make-winget-pr.sh winget-pkgs WezTerm-*.exe" , 747 ), 748RunStep ( 749"Submit PR" , 750'cd winget-pkgs && gh pr create --fill --body "PR automatically created by release automation in the wezterm repo"' , 751env = { 752"GITHUB_TOKEN" :"${{ secrets.GH_PAT }}" , 753 }, 754 ), 755 ] 756 757return steps 758 759def update_homebrew_tap (self ): 760steps = [] 761if "macos" in self .name : 762steps += [ 763ActionStep ( 764"Checkout homebrew tap" , 765action = "actions/checkout@v4" , 766params = { 767"repository" :"wez/homebrew-wezterm" , 768"path" :"homebrew-wezterm" , 769"token" :"${{ secrets.GH_PAT }}" , 770 }, 771 ), 772RunStep ( 773"Update homebrew tap formula" , 774"cp wezterm.rb homebrew-wezterm/Casks/wezterm.rb" , 775 ), 776ActionStep ( 777"Commit homebrew tap changes" , 778action = "stefanzweifel/git-auto-commit-action@v5" , 779params = { 780"commit_message" :"Automated update to match latest tag" , 781"repository" :"homebrew-wezterm" , 782 }, 783 ), 784 ] 785elif self .app_image : 786steps += [ 787ActionStep ( 788"Checkout linuxbrew tap" , 789action = "actions/checkout@v4" , 790params = { 791"repository" :"wez/homebrew-wezterm-linuxbrew" , 792"path" :"linuxbrew-wezterm" , 793"token" :"${{ secrets.GH_PAT }}" , 794 }, 795 ), 796RunStep ( 797"Update linuxbrew tap formula" , 798"cp wezterm-linuxbrew.rb linuxbrew-wezterm/Formula/wezterm.rb" , 799 ), 800ActionStep ( 801"Commit linuxbrew tap changes" , 802action = "stefanzweifel/git-auto-commit-action@v5" , 803params = { 804"commit_message" :"Automated update to match latest tag" , 805"repository" :"linuxbrew-wezterm" , 806 }, 807 ), 808 ] 809 810return steps 811 812def global_env (self ): 813self .env ["CARGO_INCREMENTAL" ]= "0" 814self .env ["SCCACHE_GHA_ENABLED" ]= "true" 815self .env ["RUSTC_WRAPPER" ]= "sccache" 816if "macos" in self .name : 817self .env ["MACOSX_DEPLOYMENT_TARGET" ]= "10.12" 818if "alpine" in self .name : 819self .env ["RUSTFLAGS" ]= "-C target-feature=-crt-static" 820if "win" in self .name : 821self .env ["RUSTUP_WINDOWS_PATH_ADD_BIN" ]= "1" 822return 823 824def prep_environment (self ,cache = True ): 825steps = [] 826sudo = "sudo -n " if self .needs_sudo ()else "" 827if self .uses_apt (): 828if self .container : 829steps += [ 830RunStep ( 831"set APT to non-interactive" , 832"echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections" , 833 ), 834 ] 835steps += [ 836RunStep ("Update APT" ,f" { sudo } apt update" ), 837 ] 838 839if self .uses_zypper (): 840if self .container : 841steps += [ 842RunStep ( 843"Seed GITHUB_PATH to work around possible @action/core bug" , 844f'echo "$PATH:/bin:/usr/bin" >> $GITHUB_PATH' , 845 ), 846RunStep ( 847"Install util-linux" , 848"zypper install -y util-linux" , 849 ), 850 ] 851if self .container : 852if ("fedora" in self .container )or ( 853 ("centos" in self .container )and ("centos7" not in self .container ) 854 ): 855steps += [ 856RunStep ( 857"Install config manager" , 858"dnf install -y 'dnf-command(config-manager)'" , 859 ), 860 ] 861if "centos:stream8" in self .container : 862steps += [ 863RunStep ( 864"Enable PowerTools" , 865"dnf config-manager --set-enabled powertools" , 866 ), 867 ] 868if "centos:stream9" in self .container : 869steps += [ 870# This holds the xcb bits 871RunStep ( 872"Enable CRB repo for X bits" , 873"dnf config-manager --set-enabled crb" , 874 ), 875 ] 876if "alpine" in self .container : 877steps += [ 878RunStep ( 879"Upgrade system" , 880"apk upgrade --update-cache" , 881shell = "sh" , 882 ), 883RunStep ( 884"Install CI dependencies" , 885"apk add nodejs zstd wget bash coreutils tar findutils" , 886shell = "sh" , 887 ), 888RunStep ( 889"Allow root login" , 890"sed 's/root:!/root:*/g' -i /etc/shadow" , 891 ), 892 ] 893if "opensuse" in self .container : 894steps += [ 895# This holds the xcb bits 896RunStep ( 897"Install tar" , 898"zypper install -yl tar gzip" , 899 ), 900 ] 901 902steps += self .install_newer_compiler () 903steps += self .install_git () 904steps += self .install_curl () 905 906if self .uses_apt (): 907if self .container : 908steps += [ 909RunStep ("Update APT" ,f" { sudo } apt update" ), 910 ] 911 912steps += self .install_openssh_server () 913steps += self .checkout () 914# We should be able to cache mac builds now? 915steps += self .install_rust ()# cache="mac" not in self.name) 916steps += self .install_system_deps () 917return steps 918 919def pull_request (self ): 920steps = self .prep_environment () 921steps += self .build_all_release () 922steps += self .test_all () 923steps += self .package () 924steps += self .upload_artifact () 925 926return ( 927Job ( 928runs_on = self .os , 929container = self .container , 930steps = steps , 931env = self .env , 932 ), 933None , 934 ) 935 936def checkout (self ,submodules = True ): 937steps = [] 938if self .container : 939steps += [ 940RunStep ( 941"Workaround git permissions issue" , 942"git config --global --add safe.directory /__w/wezterm/wezterm" , 943 ) 944 ] 945steps += [CheckoutStep (submodules = submodules ,container = self .container )] 946return steps 947 948def continuous (self ): 949steps = self .prep_environment () 950steps += self .build_all_release () 951steps += self .test_all () 952steps += self .package (trusted = True ) 953steps += self .upload_artifact_nightly () 954 955self .env ["BUILD_REASON" ]= "Schedule" 956 957uploader = Job ( 958runs_on = "ubuntu-latest" , 959steps = self .checkout (submodules = False )+ self .upload_asset_nightly (), 960 ) 961 962return ( 963Job ( 964runs_on = self .os , 965container = self .container , 966steps = steps , 967env = self .env , 968 ), 969uploader , 970 ) 971 972def tag (self ): 973steps = self .prep_environment () 974steps += self .build_all_release () 975steps += self .test_all () 976steps += self .package (trusted = True ) 977steps += self .upload_artifact () 978 979uploader = Job ( 980runs_on = "ubuntu-latest" , 981steps = self .checkout (submodules = False ) 982+ self .update_homebrew_tap () 983+ self .upload_asset_tag () 984+ self .create_winget_pr () 985+ self .create_flathub_pr (), 986 ) 987 988return ( 989Job ( 990runs_on = self .os , 991container = self .container , 992steps = steps , 993env = self .env , 994 ), 995uploader , 996 ) 997 998 999TARGETS = [ 1000Target (container = "ubuntu:20.04" ,continuous_only = True ,app_image = True ), 1001Target (container = "ubuntu:22.04" ,continuous_only = True ), 1002Target (container = "ubuntu:24.04" ,continuous_only = True ), 1003# debian 8's wayland libraries are too old for wayland-client 1004# Target(container="debian:8.11", continuous_only=True, bootstrap_git=True), 1005# harfbuzz's C++ is too new for debian 9's toolchain 1006# Target(container="debian:9.12", continuous_only=True, bootstrap_git=True), 1007Target (container = "debian:11" ,continuous_only = True ), 1008Target (container = "debian:12" ,continuous_only = True ), 1009Target (name = "centos9" ,container = "quay.io/centos/centos:stream9" ), 1010Target (name = "macos" ,os = "macos-latest" ), 1011# https://fedoraproject.org/wiki/End_of_life?rd=LifeCycle/EOL 1012Target (container = "fedora:39" ), 1013Target (container = "fedora:40" ), 1014Target (container = "fedora:41" ), 1015# Target(container="alpine:3.15"), 1016Target (name = "windows" ,os = "windows-latest" ,rust_target = "x86_64-pc-windows-msvc" ), 1017] 1018 1019 1020def generate_actions (namer ,jobber ,trigger ,is_continuous ,is_tag = False ): 1021for t in TARGETS : 1022# Clone the definition, as some Target methods called 1023# in the body below have side effects that we don't 1024# want to bleed across into different schedule types 1025t = deepcopy (t ) 1026 1027t .is_tag = is_tag 1028# if t.continuous_only and not is_continuous: 1029# continue 1030name = namer (t ).replace (":" ,"" ) 1031name ) 1032job ,uploader = jobber (t ) 1033 1034file_name = f".github/workflows/gen_ { name } .yml" 1035if job .container : 1036if t .app_image : 1037container = f"container:\n image: { yv ( job . container ) } \n options: --privileged" 1038else : 1039container = f"container: { yv ( job . container ) } " 1040 1041else : 1042container = "" 1043 1044trigger_paths = [file_name ] 1045trigger_paths += TRIGGER_PATHS 1046if "win" in name : 1047trigger_paths += TRIGGER_PATHS_WIN 1048elif "macos" in name : 1049trigger_paths += TRIGGER_PATHS_MAC 1050else : 1051trigger_paths += TRIGGER_PATHS_UNIX 1052if t .app_image : 1053trigger_paths += TRIGGER_PATHS_APPIMAGE 1054 1055trigger_paths = "- " + "\n - " .join (yv (p )for p in sorted (trigger_paths )) 1056trigger_with_paths = trigger .replace ("@PATHS@" ,trigger_paths ) 1057 1058with open (file_name ,"w" )as f : 1059f .write ( 1060f"""name: { name } 1061{ trigger_with_paths } 1062jobs: 1063build: 1064runs-on: { yv ( job . runs_on ) } 1065{ container } 1066""" 1067 ) 1068 1069t .render_env (f ) 1070 1071job .render (f ,3 ) 1072 1073# We upload using a native runner as github API access 1074# inside a container is really unreliable and can result 1075# in broken releases that can't automatically be repaired 1076# <https://github.com/cli/cli/issues/4863> 1077if uploader : 1078f .write ( 1079""" 1080upload: 1081runs-on: ubuntu-latest 1082needs: build 1083if: github.repository == 'wezterm/wezterm' 1084permissions: 1085contents: write 1086pages: write 1087id-token: write 1088""" 1089 ) 1090uploader .render (f ,3 ) 1091 1092# Sanity check the yaml, if pyyaml is available 1093try : 1094import yaml 1095 1096with open (file_name )as f : 1097yaml .safe_load (f ) 1098except ImportError : 1099pass 1100 1101 1102def generate_pr_actions (): 1103generate_actions ( 1104lambda t :f" { t . name } " , 1105lambda t :t .pull_request (), 1106trigger = """ 1107on: 1108pull_request: 1109branches: 1110- main 1111paths: 1112@PATHS@ 1113""" , 1114is_continuous = False , 1115 ) 1116 1117 1118def continuous_actions (): 1119generate_actions ( 1120lambda t :f" { t . name } _continuous" , 1121lambda t :t .continuous (), 1122trigger = """ 1123on: 1124schedule: 1125- cron: "10 3 * * *" 1126push: 1127branches: 1128- main 1129paths: 1130@PATHS@ 1131""" , 1132is_continuous = True , 1133 ) 1134 1135 1136def tag_actions (): 1137generate_actions ( 1138lambda t :f" { t . name } _tag" , 1139lambda t :t .tag (), 1140trigger = """ 1141on: 1142push: 1143tags: 1144- "20*" 1145""" , 1146is_continuous = True , 1147is_tag = True , 1148 ) 1149 1150 1151def remove_gen_actions (): 1152for name in glob .glob (".github/workflows/gen_*.yml" ): 1153os .remove (name ) 1154 1155 1156remove_gen_actions () 1157generate_pr_actions () 1158continuous_actions () 1159tag_actions ()