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