diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c7f1deccac9e..d0e38fe639d3 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -15,20 +15,14 @@ on: options: - nodejs - polyglot - workflow_call: - inputs: - ydoc: - description: What kind of Ydoc image to build. - required: false - type: string - default: nodejs jobs: promote-nightly: name: Promote nightly uses: ./.github/workflows/promote.yml with: designator: nightly - ydoc: ${{ inputs.ydoc }} + ydoc: ${{ env.ENV_INPUTS_YDOC }} secrets: inherit env: ENSO_BUILD_SKIP_VERSION_CHECK: "true" + ENV_INPUTS_YDOC: ${{ inputs.ydoc || nodejs }} diff --git a/build/build/src/ci/input.rs b/build/build/src/ci/input.rs index 88c99be7af0a..7caf757bac5a 100644 --- a/build/build/src/ci/input.rs +++ b/build/build/src/ci/input.rs @@ -12,6 +12,25 @@ pub mod name { pub const YDOC: &str = "ydoc"; } +pub mod env { + use ide_ci::env::accessor::RawVariable; + + #[derive(Clone, Copy, Debug, Default)] + pub struct Ydoc; + + impl RawVariable for Ydoc { + fn name(&self) -> &str { + "ENV_INPUTS_YDOC" + } + } + + impl From for String { + fn from(val: Ydoc) -> Self { + val.name().to_owned() + } + } +} + pub fn designator() -> WorkflowDispatchInput { WorkflowDispatchInput::new_choice( "What kind of release should be promoted.", diff --git a/build/build/src/ci_gen.rs b/build/build/src/ci_gen.rs index 47a3f58152e6..08130b089610 100644 --- a/build/build/src/ci_gen.rs +++ b/build/build/src/ci_gen.rs @@ -11,6 +11,8 @@ use crate::version::ENSO_RELEASE_MODE; use crate::version::ENSO_VERSION; use ide_ci::actions::workflow::definition::checkout_repo_step; +use ide_ci::actions::workflow::definition::env_expression; +use ide_ci::actions::workflow::definition::get_input; use ide_ci::actions::workflow::definition::get_input_expression; use ide_ci::actions::workflow::definition::is_non_windows_runner; use ide_ci::actions::workflow::definition::is_windows_runner; @@ -489,11 +491,10 @@ pub fn changelog() -> Result { } pub fn nightly() -> Result { - let workflow_dispatch = - WorkflowDispatch::default().with_input(input::name::YDOC, input::ydoc()); - let workflow_call = WorkflowCall::try_from(workflow_dispatch.clone())?; + let input_ydoc = input::ydoc(); + let input_ydoc_default = input_ydoc.r#type.default().expect("Default Ydoc input is expected."); + let workflow_dispatch = WorkflowDispatch::default().with_input(input::name::YDOC, input_ydoc); let on = Event { - workflow_call: Some(workflow_call), workflow_dispatch: Some(workflow_dispatch), // 2am (UTC) every day. schedule: vec![Schedule::new("0 2 * * *")?], @@ -501,10 +502,14 @@ pub fn nightly() -> Result { }; let mut workflow = Workflow { on, name: "Nightly Release".into(), ..default() }; + // Scheduled workflows do not support input parameters. Instead we provide env variable + // expression with default. Feature request is tracked by https://github.com/orgs/community/discussions/74698 + let input_env_ydoc = format!("{} || {}", get_input(input::name::YDOC), input_ydoc_default); + workflow.env(input::env::Ydoc, wrap_expression(input_env_ydoc)); let job = workflow_call_job("Promote nightly", PROMOTE_WORKFLOW_PATH) .with_with(input::name::DESIGNATOR, Designation::Nightly.as_ref()) - .with_with(input::name::YDOC, get_input_expression(input::name::YDOC)); + .with_with(input::name::YDOC, env_expression(&input::env::Ydoc)); workflow.add_job(job); Ok(workflow) } diff --git a/build/ci_utils/src/actions/workflow/definition.rs b/build/ci_utils/src/actions/workflow/definition.rs index ede82b57ebc9..ec5deda8d4a3 100644 --- a/build/ci_utils/src/actions/workflow/definition.rs +++ b/build/ci_utils/src/actions/workflow/definition.rs @@ -61,10 +61,15 @@ pub fn env_expression(environment_variable: &impl RawVariable) -> String { wrap_expression(format!("env.{}", environment_variable.name())) } +/// Get string that gets input from the workflow dispatch. +pub fn get_input(name: impl Into) -> String { + format!("inputs.{}", name.into()) +} + /// Get expression that gets input from the workflow dispatch. See: /// pub fn get_input_expression(name: impl Into) -> String { - wrap_expression(format!("inputs.{}", name.into())) + wrap_expression(get_input(name)) } /// GH Actions expression piece that evaluates to `true` if run on a GitHub-hosted runner. @@ -397,6 +402,18 @@ pub enum WorkflowDispatchInputType { }, } +impl WorkflowDispatchInputType { + pub fn default(&self) -> Option { + let res = match self { + WorkflowDispatchInputType::String { default, .. } => default, + WorkflowDispatchInputType::Choice { default, .. } => default, + WorkflowDispatchInputType::Boolean { default, .. } => &default.map(|v| v.to_string()), + WorkflowDispatchInputType::Environment { default, .. } => default, + }; + res.clone() + } +} + impl Default for WorkflowDispatchInputType { fn default() -> Self { Self::String { default: None }