1use crate::tasks::workflows::{
2 steps::{FluentBuilder, NamedJob, dependant_job, named},
3 vars::{mac_bundle_envs, windows_bundle_envs},
4};
5
6use super::{runners, steps, vars};
7use gh_workflow::*;
8use indexmap::IndexMap;
9
10pub fn run_bundling() -> Workflow {
11 named::workflow()
12 .on(Event::default().pull_request(
13 PullRequest::default().types([PullRequestType::Labeled, PullRequestType::Synchronize]),
14 ))
15 .concurrency(
16 Concurrency::new(Expression::new(
17 "${{ github.workflow }}-${{ github.head_ref || github.ref }}",
18 ))
19 .cancel_in_progress(true),
20 )
21 .add_env(("CARGO_TERM_COLOR", "always"))
22 .add_env(("CARGO_INCREMENTAL", "0"))
23 .add_env(("RUST_BACKTRACE", "1"))
24 .add_env(("ZED_CLIENT_CHECKSUM_SEED", vars::ZED_CLIENT_CHECKSUM_SEED))
25 .add_env(("ZED_MINIDUMP_ENDPOINT", vars::ZED_SENTRY_MINIDUMP_ENDPOINT))
26 .add_job(
27 "bundle_mac_x86_64",
28 bundle_mac_job(runners::Arch::X86_64, &[]),
29 )
30 .add_job(
31 "bundle_mac_arm64",
32 bundle_mac_job(runners::Arch::ARM64, &[]),
33 )
34 .add_job(
35 "bundle_linux_x86_64",
36 bundle_linux_job(runners::Arch::X86_64, &[]),
37 )
38 .add_job(
39 "bundle_linux_arm64",
40 bundle_linux_job(runners::Arch::ARM64, &[]),
41 )
42 .add_job(
43 "bundle_windows_x86_64",
44 bundle_windows_job(runners::Arch::X86_64, &[]),
45 )
46 .add_job(
47 "bundle_windows_arm64",
48 bundle_windows_job(runners::Arch::ARM64, &[]),
49 )
50}
51
52fn bundle_job(deps: &[&NamedJob]) -> Job {
53 dependant_job(deps)
54 .when(deps.len() == 0, |job|
55 job.cond(Expression::new(
56 "(github.event.action == 'labeled' && github.event.label.name == 'run-bundling') ||
57 (github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'run-bundling'))",
58 )))
59 .timeout_minutes(60u32)
60}
61
62pub(crate) fn bundle_mac_job(arch: runners::Arch, deps: &[&NamedJob]) -> Job {
63 use vars::GITHUB_SHA;
64 let artifact_name = format!("Zed_{GITHUB_SHA}-{arch}.dmg");
65 let remote_server_artifact_name = format!("zed-remote-server-{GITHUB_SHA}-macos-{arch}.gz");
66 bundle_job(deps)
67 .runs_on(runners::MAC_DEFAULT)
68 .envs(mac_bundle_envs())
69 .add_step(steps::checkout_repo())
70 .add_step(steps::setup_node())
71 .add_step(steps::setup_sentry())
72 .add_step(steps::clear_target_dir_if_large(runners::Platform::Mac))
73 .add_step(bundle_mac(arch))
74 .add_step(steps::upload_artifact(
75 &artifact_name,
76 &format!("target/{arch}-apple-darwin/release/Zed.dmg"),
77 ))
78 .add_step(steps::upload_artifact(
79 &remote_server_artifact_name,
80 &format!("target/zed-remote-server-macos-{arch}.gz"),
81 ))
82 .outputs(
83 [
84 ("zed".to_string(), artifact_name),
85 ("remote-server".to_string(), remote_server_artifact_name),
86 ]
87 .into_iter()
88 .collect::<IndexMap<_, _>>(),
89 )
90}
91
92pub fn bundle_mac(arch: runners::Arch) -> Step<Run> {
93 named::bash(&format!("./script/bundle-mac {arch}-apple-darwin"))
94}
95
96pub(crate) fn bundle_linux_job(arch: runners::Arch, deps: &[&NamedJob]) -> Job {
97 let artifact_name = format!("zed-{}-{}.tar.gz", vars::GITHUB_SHA, arch.triple());
98 let remote_server_artifact_name = format!(
99 "zed-remote-server-{}-{}.tar.gz",
100 vars::GITHUB_SHA,
101 arch.triple()
102 );
103 bundle_job(deps)
104 .runs_on(arch.linux_bundler())
105 .add_step(steps::checkout_repo())
106 .add_step(steps::setup_sentry())
107 .map(steps::install_linux_dependencies)
108 .add_step(steps::script("./script/bundle-linux"))
109 .add_step(steps::upload_artifact(
110 &artifact_name,
111 "target/release/zed-*.tar.gz",
112 ))
113 .add_step(steps::upload_artifact(
114 &remote_server_artifact_name,
115 "target/zed-remote-server-*.gz",
116 ))
117 .outputs(
118 [
119 ("zed".to_string(), artifact_name),
120 ("remote-server".to_string(), remote_server_artifact_name),
121 ]
122 .into_iter()
123 .collect::<IndexMap<_, _>>(),
124 )
125}
126
127pub(crate) fn bundle_windows_job(arch: runners::Arch, deps: &[&NamedJob]) -> Job {
128 use vars::GITHUB_SHA;
129 let artifact_name = format!("Zed_{GITHUB_SHA}-{arch}.exe");
130 bundle_job(deps)
131 .runs_on(runners::WINDOWS_DEFAULT)
132 .envs(windows_bundle_envs())
133 .add_step(steps::checkout_repo())
134 .add_step(steps::setup_sentry())
135 .add_step(bundle_windows(arch))
136 .add_step(steps::upload_artifact(
137 &artifact_name,
138 "${{ env.SETUP_PATH }}",
139 ))
140 .outputs(
141 [("zed".to_string(), artifact_name)]
142 .into_iter()
143 .collect::<IndexMap<_, _>>(),
144 )
145}
146
147fn bundle_windows(arch: runners::Arch) -> Step<Run> {
148 let step = match arch {
149 runners::Arch::X86_64 => named::pwsh("script/bundle-windows.ps1 -Architecture x86_64"),
150 runners::Arch::ARM64 => named::pwsh("script/bundle-windows.ps1 -Architecture aarch64"),
151 };
152 step.working_directory("${{ env.ZED_WORKSPACE }}")
153}