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