fork/wezterm

git clone https://git.julia.blue/fork/wezterm

Wez Furlongci: remove fedora 386fe9d01e6

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