Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T06:49:55.756Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

vars.rs

408 lines · 12.3 KB · rust
1use std::{cell::RefCell, ops::Not};
2
3use gh_workflow::{
4    Concurrency, Env, Expression, Step, WorkflowCallInput, WorkflowCallSecret,
5    WorkflowDispatchInput,
6};
7
8use crate::tasks::workflows::{runners::Platform, steps::NamedJob};
9
10macro_rules! secret {
11    ($secret_name:ident) => {
12        pub const $secret_name: &str = concat!("${{ secrets.", stringify!($secret_name), " }}");
13    };
14}
15
16macro_rules! var {
17    ($var_name:ident) => {
18        pub const $var_name: &str = concat!("${{ vars.", stringify!($var_name), " }}");
19    };
20}
21
22secret!(APPLE_NOTARIZATION_ISSUER_ID);
23secret!(APPLE_NOTARIZATION_KEY);
24secret!(APPLE_NOTARIZATION_KEY_ID);
25secret!(AZURE_SIGNING_CLIENT_ID);
26secret!(AZURE_SIGNING_CLIENT_SECRET);
27secret!(AZURE_SIGNING_TENANT_ID);
28secret!(CACHIX_AUTH_TOKEN);
29secret!(CLUSTER_NAME);
30secret!(DIGITALOCEAN_ACCESS_TOKEN);
31secret!(DIGITALOCEAN_SPACES_ACCESS_KEY);
32secret!(DIGITALOCEAN_SPACES_SECRET_KEY);
33secret!(GITHUB_TOKEN);
34secret!(MACOS_CERTIFICATE);
35secret!(MACOS_CERTIFICATE_PASSWORD);
36secret!(SENTRY_AUTH_TOKEN);
37secret!(ZED_CLIENT_CHECKSUM_SEED);
38secret!(ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON);
39secret!(ZED_SENTRY_MINIDUMP_ENDPOINT);
40secret!(ZED_ZIPPY_APP_ID);
41secret!(ZED_ZIPPY_APP_PRIVATE_KEY);
42secret!(DISCORD_WEBHOOK_RELEASE_NOTES);
43secret!(WINGET_TOKEN);
44secret!(ZED_DEV_REVALIDATE_TOKEN);
45secret!(SLACK_WEBHOOK_WORKFLOW_FAILURES);
46secret!(R2_ACCOUNT_ID);
47secret!(R2_ACCESS_KEY_ID);
48secret!(R2_SECRET_ACCESS_KEY);
49secret!(CLOUDFLARE_API_TOKEN);
50secret!(CLOUDFLARE_ACCOUNT_ID);
51secret!(DOCS_AMPLITUDE_API_KEY);
52secret!(DOCS_CONSENT_IO_INSTANCE);
53
54// todo(ci) make these secrets too...
55var!(AZURE_SIGNING_ACCOUNT_NAME);
56var!(AZURE_SIGNING_CERT_PROFILE_NAME);
57var!(AZURE_SIGNING_ENDPOINT);
58
59pub fn bundle_envs(platform: Platform) -> Env {
60    let env = Env::default()
61        .add("CARGO_INCREMENTAL", 0)
62        .add("ZED_CLIENT_CHECKSUM_SEED", ZED_CLIENT_CHECKSUM_SEED)
63        .add("ZED_MINIDUMP_ENDPOINT", ZED_SENTRY_MINIDUMP_ENDPOINT);
64
65    match platform {
66        Platform::Linux => env,
67        Platform::Mac => env
68            .add("MACOS_CERTIFICATE", MACOS_CERTIFICATE)
69            .add("MACOS_CERTIFICATE_PASSWORD", MACOS_CERTIFICATE_PASSWORD)
70            .add("APPLE_NOTARIZATION_KEY", APPLE_NOTARIZATION_KEY)
71            .add("APPLE_NOTARIZATION_KEY_ID", APPLE_NOTARIZATION_KEY_ID)
72            .add("APPLE_NOTARIZATION_ISSUER_ID", APPLE_NOTARIZATION_ISSUER_ID),
73        Platform::Windows => env
74            .add("AZURE_TENANT_ID", AZURE_SIGNING_TENANT_ID)
75            .add("AZURE_CLIENT_ID", AZURE_SIGNING_CLIENT_ID)
76            .add("AZURE_CLIENT_SECRET", AZURE_SIGNING_CLIENT_SECRET)
77            .add("ACCOUNT_NAME", AZURE_SIGNING_ACCOUNT_NAME)
78            .add("CERT_PROFILE_NAME", AZURE_SIGNING_CERT_PROFILE_NAME)
79            .add("ENDPOINT", AZURE_SIGNING_ENDPOINT)
80            .add("FILE_DIGEST", "SHA256")
81            .add("TIMESTAMP_DIGEST", "SHA256")
82            .add("TIMESTAMP_SERVER", "http://timestamp.acs.microsoft.com"),
83    }
84}
85
86pub fn one_workflow_per_non_main_branch() -> Concurrency {
87    one_workflow_per_non_main_branch_and_token("")
88}
89
90pub fn one_workflow_per_non_main_branch_and_token<T: AsRef<str>>(token: T) -> Concurrency {
91    Concurrency::default()
92        .group(format!(
93            concat!(
94                "${{{{ github.workflow }}}}-${{{{ github.ref_name }}}}-",
95                "${{{{ github.ref_name == 'main' && github.sha || 'anysha' }}}}{}"
96            ),
97            token.as_ref()
98        ))
99        .cancel_in_progress(true)
100}
101
102// Represents a pattern to check for changed files and corresponding output variable
103pub struct PathCondition {
104    pub name: &'static str,
105    pub pattern: &'static str,
106    pub invert: bool,
107    pub set_by_step: RefCell<Option<String>>,
108}
109impl PathCondition {
110    pub fn new(name: &'static str, pattern: &'static str) -> Self {
111        Self {
112            name,
113            pattern,
114            invert: false,
115            set_by_step: Default::default(),
116        }
117    }
118    pub fn inverted(name: &'static str, pattern: &'static str) -> Self {
119        Self {
120            name,
121            pattern,
122            invert: true,
123            set_by_step: Default::default(),
124        }
125    }
126
127    pub fn and_always<'a>(&'a self) -> PathContextCondition<'a> {
128        PathContextCondition {
129            condition: self,
130            run_in_merge_queue: true,
131        }
132    }
133
134    pub fn and_not_in_merge_queue<'a>(&'a self) -> PathContextCondition<'a> {
135        PathContextCondition {
136            condition: self,
137            run_in_merge_queue: false,
138        }
139    }
140}
141
142pub struct PathContextCondition<'a> {
143    condition: &'a PathCondition,
144    run_in_merge_queue: bool,
145}
146
147impl<'a> PathContextCondition<'a> {
148    pub fn then(&'a self, job: NamedJob) -> NamedJob {
149        let set_by_step = self
150            .condition
151            .set_by_step
152            .borrow()
153            .clone()
154            .unwrap_or_else(|| panic!("condition {},is never set", self.condition.name));
155        NamedJob {
156            name: job.name,
157            job: job.job.add_need(set_by_step.clone()).cond(Expression::new(
158                format!(
159                    "needs.{}.outputs.{} == 'true' {merge_queue_condition}",
160                    &set_by_step,
161                    self.condition.name,
162                    merge_queue_condition = self
163                        .run_in_merge_queue
164                        .not()
165                        .then_some("&& github.event_name != 'merge_group'")
166                        .unwrap_or_default()
167                )
168                .trim(),
169            )),
170        }
171    }
172}
173
174pub(crate) struct StepOutput {
175    pub name: &'static str,
176    step_id: String,
177}
178
179impl StepOutput {
180    pub fn new<T>(step: &Step<T>, name: &'static str) -> Self {
181        let step_id = step
182            .value
183            .id
184            .clone()
185            .expect("Steps that produce outputs must have an ID");
186
187        assert!(
188            step.value
189                .run
190                .as_ref()
191                .is_none_or(|run_command| run_command.contains(name)),
192            "Step output with name '{name}' must occur at least once in run command with ID {step_id}!"
193        );
194
195        Self { name, step_id }
196    }
197
198    pub fn new_unchecked<T>(step: &Step<T>, name: &'static str) -> Self {
199        let step_id = step
200            .value
201            .id
202            .clone()
203            .expect("Steps that produce outputs must have an ID");
204
205        Self { name, step_id }
206    }
207
208    pub fn expr(&self) -> String {
209        format!("steps.{}.outputs.{}", self.step_id, self.name)
210    }
211
212    pub fn as_job_output(self, job: &NamedJob) -> JobOutput {
213        JobOutput {
214            job_name: job.name.clone(),
215            name: self.name,
216        }
217    }
218}
219
220impl serde::Serialize for StepOutput {
221    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
222    where
223        S: serde::Serializer,
224    {
225        serializer.serialize_str(&self.to_string())
226    }
227}
228
229impl std::fmt::Display for StepOutput {
230    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
231        write!(f, "${{{{ {} }}}}", self.expr())
232    }
233}
234
235pub(crate) struct JobOutput {
236    job_name: String,
237    name: &'static str,
238}
239
240impl JobOutput {
241    pub fn expr(&self) -> String {
242        format!("needs.{}.outputs.{}", self.job_name, self.name)
243    }
244}
245
246impl serde::Serialize for JobOutput {
247    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
248    where
249        S: serde::Serializer,
250    {
251        serializer.serialize_str(&self.to_string())
252    }
253}
254
255impl std::fmt::Display for JobOutput {
256    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
257        write!(f, "${{{{ {} }}}}", self.expr())
258    }
259}
260
261pub struct WorkflowInput {
262    pub input_type: &'static str,
263    pub name: &'static str,
264    pub default: Option<String>,
265    pub description: Option<String>,
266}
267
268impl WorkflowInput {
269    pub fn string(name: &'static str, default: Option<String>) -> Self {
270        Self {
271            input_type: "string",
272            name,
273            default,
274            description: None,
275        }
276    }
277
278    pub fn bool(name: &'static str, default: Option<bool>) -> Self {
279        Self {
280            input_type: "boolean",
281            name,
282            default: default.as_ref().map(ToString::to_string),
283            description: None,
284        }
285    }
286
287    pub fn description(mut self, description: impl ToString) -> Self {
288        self.description = Some(description.to_string());
289        self
290    }
291
292    pub fn input(&self) -> WorkflowDispatchInput {
293        WorkflowDispatchInput {
294            description: self
295                .description
296                .clone()
297                .unwrap_or_else(|| self.name.to_owned()),
298            required: self.default.is_none(),
299            input_type: self.input_type.to_owned(),
300            default: self.default.clone(),
301        }
302    }
303
304    pub fn call_input(&self) -> WorkflowCallInput {
305        WorkflowCallInput {
306            description: self.name.to_owned(),
307            required: self.default.is_none(),
308            input_type: self.input_type.to_owned(),
309            default: self.default.clone(),
310        }
311    }
312
313    pub(crate) fn expr(&self) -> String {
314        format!("inputs.{}", self.name)
315    }
316}
317
318impl std::fmt::Display for WorkflowInput {
319    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
320        write!(f, "${{{{ {} }}}}", self.expr())
321    }
322}
323
324impl serde::Serialize for WorkflowInput {
325    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
326    where
327        S: serde::Serializer,
328    {
329        serializer.serialize_str(&self.to_string())
330    }
331}
332
333pub(crate) struct WorkflowSecret {
334    pub name: &'static str,
335    description: String,
336    required: bool,
337}
338
339impl WorkflowSecret {
340    pub fn new(name: &'static str, description: impl ToString) -> Self {
341        Self {
342            name,
343            description: description.to_string(),
344            required: true,
345        }
346    }
347
348    pub fn secret_configuration(&self) -> WorkflowCallSecret {
349        WorkflowCallSecret {
350            description: self.description.clone(),
351            required: self.required,
352        }
353    }
354}
355
356impl std::fmt::Display for WorkflowSecret {
357    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
358        write!(f, "${{{{ secrets.{} }}}}", self.name)
359    }
360}
361
362impl serde::Serialize for WorkflowSecret {
363    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
364    where
365        S: serde::Serializer,
366    {
367        serializer.serialize_str(&self.to_string())
368    }
369}
370
371pub mod assets {
372    // NOTE: these asset names also exist in the zed.dev codebase.
373    pub const MAC_AARCH64: &str = "Zed-aarch64.dmg";
374    pub const MAC_X86_64: &str = "Zed-x86_64.dmg";
375    pub const LINUX_AARCH64: &str = "zed-linux-aarch64.tar.gz";
376    pub const LINUX_X86_64: &str = "zed-linux-x86_64.tar.gz";
377    pub const BWRAP_LINUX_AARCH64: &str = "bwrap-linux-aarch64.gz";
378    pub const BWRAP_LINUX_X86_64: &str = "bwrap-linux-x86_64.gz";
379    pub const WINDOWS_X86_64: &str = "Zed-x86_64.exe";
380    pub const WINDOWS_AARCH64: &str = "Zed-aarch64.exe";
381
382    pub const REMOTE_SERVER_MAC_AARCH64: &str = "zed-remote-server-macos-aarch64.gz";
383    pub const REMOTE_SERVER_MAC_X86_64: &str = "zed-remote-server-macos-x86_64.gz";
384    pub const REMOTE_SERVER_LINUX_AARCH64: &str = "zed-remote-server-linux-aarch64.gz";
385    pub const REMOTE_SERVER_LINUX_X86_64: &str = "zed-remote-server-linux-x86_64.gz";
386    pub const REMOTE_SERVER_WINDOWS_AARCH64: &str = "zed-remote-server-windows-aarch64.zip";
387    pub const REMOTE_SERVER_WINDOWS_X86_64: &str = "zed-remote-server-windows-x86_64.zip";
388
389    pub fn all() -> Vec<&'static str> {
390        vec![
391            MAC_AARCH64,
392            MAC_X86_64,
393            LINUX_AARCH64,
394            LINUX_X86_64,
395            BWRAP_LINUX_AARCH64,
396            BWRAP_LINUX_X86_64,
397            WINDOWS_X86_64,
398            WINDOWS_AARCH64,
399            REMOTE_SERVER_MAC_AARCH64,
400            REMOTE_SERVER_MAC_X86_64,
401            REMOTE_SERVER_LINUX_AARCH64,
402            REMOTE_SERVER_LINUX_X86_64,
403            REMOTE_SERVER_WINDOWS_AARCH64,
404            REMOTE_SERVER_WINDOWS_X86_64,
405        ]
406    }
407}
408
Served at tenant.openagents/omega Member data and write actions are omitted.