Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inputs for scheduled Nightly workflow #11708

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
19 changes: 19 additions & 0 deletions build/build/src/ci/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ydoc> 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.",
Expand Down
15 changes: 10 additions & 5 deletions build/build/src/ci_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -489,22 +491,25 @@ pub fn changelog() -> Result<Workflow> {
}

pub fn nightly() -> Result<Workflow> {
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 * * *")?],
..default()
};

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)
}
Expand Down
19 changes: 18 additions & 1 deletion build/ci_utils/src/actions/workflow/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) -> String {
format!("inputs.{}", name.into())
}

/// Get expression that gets input from the workflow dispatch. See:
/// <https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#providing-inputs>
pub fn get_input_expression(name: impl Into<String>) -> 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.
Expand Down Expand Up @@ -397,6 +402,18 @@ pub enum WorkflowDispatchInputType {
},
}

impl WorkflowDispatchInputType {
pub fn default(&self) -> Option<String> {
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 }
Expand Down
Loading