1use std::cell::RefCell;
2
3use gh_workflow::{Concurrency, Env, Expression, Step, WorkflowDispatchInput};
4
5use crate::tasks::workflows::{runners::Platform, steps::NamedJob};
6
7macro_rules! secret {
8 ($secret_name:ident) => {
9 pub const $secret_name: &str = concat!("${{ secrets.", stringify!($secret_name), " }}");
10 };
11}
12
13macro_rules! var {
14 ($secret_name:ident) => {
15 pub const $secret_name: &str = concat!("${{ vars.", stringify!($secret_name), " }}");
16 };
17}
18
19secret!(ANTHROPIC_API_KEY);
20secret!(OPENAI_API_KEY);
21secret!(GOOGLE_AI_API_KEY);
22secret!(GOOGLE_CLOUD_PROJECT);
23secret!(APPLE_NOTARIZATION_ISSUER_ID);
24secret!(APPLE_NOTARIZATION_KEY);
25secret!(APPLE_NOTARIZATION_KEY_ID);
26secret!(AZURE_SIGNING_CLIENT_ID);
27secret!(AZURE_SIGNING_CLIENT_SECRET);
28secret!(AZURE_SIGNING_TENANT_ID);
29secret!(CACHIX_AUTH_TOKEN);
30secret!(DIGITALOCEAN_SPACES_ACCESS_KEY);
31secret!(DIGITALOCEAN_SPACES_SECRET_KEY);
32secret!(GITHUB_TOKEN);
33secret!(MACOS_CERTIFICATE);
34secret!(MACOS_CERTIFICATE_PASSWORD);
35secret!(SENTRY_AUTH_TOKEN);
36secret!(ZED_CLIENT_CHECKSUM_SEED);
37secret!(ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON);
38secret!(ZED_SENTRY_MINIDUMP_ENDPOINT);
39secret!(SLACK_APP_ZED_UNIT_EVALS_BOT_TOKEN);
40secret!(ZED_ZIPPY_APP_ID);
41secret!(ZED_ZIPPY_APP_PRIVATE_KEY);
42secret!(DISCORD_WEBHOOK_RELEASE_NOTES);
43secret!(WINGET_TOKEN);
44secret!(VERCEL_TOKEN);
45secret!(SLACK_WEBHOOK_WORKFLOW_FAILURES);
46
47// todo(ci) make these secrets too...
48var!(AZURE_SIGNING_ACCOUNT_NAME);
49var!(AZURE_SIGNING_CERT_PROFILE_NAME);
50var!(AZURE_SIGNING_ENDPOINT);
51
52pub fn bundle_envs(platform: Platform) -> Env {
53 let env = Env::default()
54 .add("CARGO_INCREMENTAL", 0)
55 .add("ZED_CLIENT_CHECKSUM_SEED", ZED_CLIENT_CHECKSUM_SEED)
56 .add("ZED_MINIDUMP_ENDPOINT", ZED_SENTRY_MINIDUMP_ENDPOINT);
57
58 match platform {
59 Platform::Linux => env,
60 Platform::Mac => env
61 .add("MACOS_CERTIFICATE", MACOS_CERTIFICATE)
62 .add("MACOS_CERTIFICATE_PASSWORD", MACOS_CERTIFICATE_PASSWORD)
63 .add("APPLE_NOTARIZATION_KEY", APPLE_NOTARIZATION_KEY)
64 .add("APPLE_NOTARIZATION_KEY_ID", APPLE_NOTARIZATION_KEY_ID)
65 .add("APPLE_NOTARIZATION_ISSUER_ID", APPLE_NOTARIZATION_ISSUER_ID),
66 Platform::Windows => env
67 .add("AZURE_TENANT_ID", AZURE_SIGNING_TENANT_ID)
68 .add("AZURE_CLIENT_ID", AZURE_SIGNING_CLIENT_ID)
69 .add("AZURE_CLIENT_SECRET", AZURE_SIGNING_CLIENT_SECRET)
70 .add("ACCOUNT_NAME", AZURE_SIGNING_ACCOUNT_NAME)
71 .add("CERT_PROFILE_NAME", AZURE_SIGNING_CERT_PROFILE_NAME)
72 .add("ENDPOINT", AZURE_SIGNING_ENDPOINT)
73 .add("FILE_DIGEST", "SHA256")
74 .add("TIMESTAMP_DIGEST", "SHA256")
75 .add("TIMESTAMP_SERVER", "http://timestamp.acs.microsoft.com"),
76 }
77}
78
79pub(crate) fn one_workflow_per_non_main_branch() -> Concurrency {
80 Concurrency::default()
81 .group("${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}")
82 .cancel_in_progress(true)
83}
84
85pub(crate) fn allow_concurrent_runs() -> Concurrency {
86 Concurrency::default()
87 .group("${{ github.workflow }}-${{ github.ref_name }}-${{ github.run_id }}")
88 .cancel_in_progress(true)
89}
90
91// Represents a pattern to check for changed files and corresponding output variable
92pub(crate) struct PathCondition {
93 pub name: &'static str,
94 pub pattern: &'static str,
95 pub invert: bool,
96 pub set_by_step: RefCell<Option<String>>,
97}
98impl PathCondition {
99 pub fn new(name: &'static str, pattern: &'static str) -> Self {
100 Self {
101 name,
102 pattern,
103 invert: false,
104 set_by_step: Default::default(),
105 }
106 }
107 pub fn inverted(name: &'static str, pattern: &'static str) -> Self {
108 Self {
109 name,
110 pattern,
111 invert: true,
112 set_by_step: Default::default(),
113 }
114 }
115 pub fn guard(&self, job: NamedJob) -> NamedJob {
116 let set_by_step = self
117 .set_by_step
118 .borrow()
119 .clone()
120 .unwrap_or_else(|| panic!("condition {},is never set", self.name));
121 NamedJob {
122 name: job.name,
123 job: job
124 .job
125 .add_need(set_by_step.clone())
126 .cond(Expression::new(format!(
127 "needs.{}.outputs.{} == 'true'",
128 &set_by_step, self.name
129 ))),
130 }
131 }
132}
133
134pub(crate) struct StepOutput {
135 name: &'static str,
136 step_id: String,
137}
138
139impl StepOutput {
140 pub fn new<T>(step: &Step<T>, name: &'static str) -> Self {
141 Self {
142 name,
143 step_id: step
144 .value
145 .id
146 .clone()
147 .expect("Steps that produce outputs must have an ID"),
148 }
149 }
150}
151
152impl serde::Serialize for StepOutput {
153 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
154 where
155 S: serde::Serializer,
156 {
157 serializer.serialize_str(&self.to_string())
158 }
159}
160
161impl std::fmt::Display for StepOutput {
162 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163 write!(f, "${{{{ steps.{}.outputs.{} }}}}", self.step_id, self.name)
164 }
165}
166
167pub(crate) struct Input {
168 pub input_type: &'static str,
169 pub name: &'static str,
170 pub default: Option<String>,
171}
172
173impl Input {
174 pub fn string(name: &'static str, default: Option<String>) -> Self {
175 Self {
176 input_type: "string",
177 name,
178 default,
179 }
180 }
181
182 pub fn input(&self) -> WorkflowDispatchInput {
183 WorkflowDispatchInput {
184 description: self.name.to_owned(),
185 required: self.default.is_none(),
186 input_type: self.input_type.to_owned(),
187 default: self.default.clone(),
188 }
189 }
190}
191
192impl std::fmt::Display for Input {
193 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
194 write!(f, "${{{{ inputs.{} }}}}", self.name)
195 }
196}
197
198impl serde::Serialize for Input {
199 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
200 where
201 S: serde::Serializer,
202 {
203 serializer.serialize_str(&self.to_string())
204 }
205}
206
207pub mod assets {
208 // NOTE: these asset names also exist in the zed.dev codebase.
209 pub const MAC_AARCH64: &str = "Zed-aarch64.dmg";
210 pub const MAC_X86_64: &str = "Zed-x86_64.dmg";
211 pub const LINUX_AARCH64: &str = "zed-linux-aarch64.tar.gz";
212 pub const LINUX_X86_64: &str = "zed-linux-x86_64.tar.gz";
213 pub const WINDOWS_X86_64: &str = "Zed-x86_64.exe";
214 pub const WINDOWS_AARCH64: &str = "Zed-aarch64.exe";
215
216 pub const REMOTE_SERVER_MAC_AARCH64: &str = "zed-remote-server-macos-aarch64.gz";
217 pub const REMOTE_SERVER_MAC_X86_64: &str = "zed-remote-server-macos-x86_64.gz";
218 pub const REMOTE_SERVER_LINUX_AARCH64: &str = "zed-remote-server-linux-aarch64.gz";
219 pub const REMOTE_SERVER_LINUX_X86_64: &str = "zed-remote-server-linux-x86_64.gz";
220
221 pub fn all() -> Vec<&'static str> {
222 vec![
223 MAC_AARCH64,
224 MAC_X86_64,
225 LINUX_AARCH64,
226 LINUX_X86_64,
227 WINDOWS_X86_64,
228 WINDOWS_AARCH64,
229 REMOTE_SERVER_MAC_AARCH64,
230 REMOTE_SERVER_MAC_X86_64,
231 REMOTE_SERVER_LINUX_AARCH64,
232 REMOTE_SERVER_LINUX_X86_64,
233 ]
234 }
235}