Skip to content

Commit 3515e1a

Browse files
committed
feat(github): display oidc as announcement
1 parent c317a02 commit 3515e1a

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

src/logger.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// This target is used exclusively to handle group events.
22
pub const GROUP_TARGET: &str = "codspeed::group";
33
pub const OPENED_GROUP_TARGET: &str = "codspeed::group::opened";
4+
pub const ANNOUNCEMENT_TARGET: &str = "codspeed::announcement";
45

56
#[macro_export]
67
/// Start a new log group. All logs between this and the next `end_group!` will be grouped together.
@@ -43,6 +44,15 @@ macro_rules! end_group {
4344
};
4445
}
4546

47+
#[macro_export]
48+
/// Logs at the announcement level. This is intended for important announcements like new features,
49+
/// that do not require immediate user action.
50+
macro_rules! announcement {
51+
($name:expr) => {
52+
log::log!(target: $crate::logger::ANNOUNCEMENT_TARGET, log::Level::Info, "{}", $name);
53+
};
54+
}
55+
4656
pub enum GroupEvent {
4757
Start(String),
4858
StartOpened(String),
@@ -72,6 +82,14 @@ pub(super) fn get_group_event(record: &log::Record) -> Option<GroupEvent> {
7282
}
7383
}
7484

85+
pub(super) fn get_announcement_event(record: &log::Record) -> Option<String> {
86+
if record.target() != ANNOUNCEMENT_TARGET {
87+
return None;
88+
}
89+
90+
Some(record.args().to_string())
91+
}
92+
7593
#[macro_export]
7694
/// Log a structured JSON output
7795
macro_rules! log_json {

src/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use crate::{end_group, log_json, start_group, start_opened_group};
1+
pub use crate::{announcement, end_group, log_json, start_group, start_opened_group};
22
#[allow(unused_imports)]
33
pub use anyhow::{Context, Error, Result, anyhow, bail, ensure};
44
pub use itertools::Itertools;

src/run/run_environment/buildkite/logger.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
logger::{GroupEvent, get_group_event, get_json_event},
2+
logger::{GroupEvent, get_announcement_event, get_group_event, get_json_event},
33
run::run_environment::logger::should_provider_logger_handle_record,
44
};
55
use log::*;
@@ -53,6 +53,11 @@ impl Log for BuildkiteLogger {
5353
return;
5454
}
5555

56+
if let Some(announcement) = get_announcement_event(record) {
57+
println!("[ANNOUNCEMENT] {announcement}");
58+
return;
59+
}
60+
5661
if level > self.log_level {
5762
return;
5863
}

src/run/run_environment/github_actions/logger.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
logger::{GroupEvent, get_group_event, get_json_event},
2+
logger::{GroupEvent, get_announcement_event, get_group_event, get_json_event},
33
run::run_environment::logger::should_provider_logger_handle_record,
44
};
55
use log::*;
@@ -55,6 +55,13 @@ impl Log for GithubActionLogger {
5555
return;
5656
}
5757

58+
if let Some(announcement) = get_announcement_event(record) {
59+
let escaped_announcement = announcement.replace('\n', "%0A");
60+
// TODO: make the announcement title configurable
61+
println!("::notice title=New CodSpeed Feature::{escaped_announcement}");
62+
return;
63+
}
64+
5865
if get_json_event(record).is_some() {
5966
return;
6067
}

src/run/run_environment/github_actions/provider.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ impl RunEnvironmentProvider for GitHubActionsProvider {
292292
fn check_oidc_configuration(&mut self, config: &Config) -> Result<()> {
293293
// Check if a static token is already set
294294
if config.token.is_some() {
295-
info!(
296-
"CodSpeed now supports OIDC tokens for authentication.\n\
297-
Benefit from enhanced security by adding the `id-token: write` permission to your workflow and removing the static token from your configuration.\n\
298-
Learn more at https://codspeed.io/docs/integrations/ci/github-actions/configuration#oidc-recommended"
295+
announcement!(
296+
"You can now authenticate your CI workflows using OpenID Connect (OIDC) tokens instead of `CODSPEED_TOKEN` secrets.\n\
297+
This makes integrating and authenticating jobs safer and simpler.\n\
298+
Learn more at https://codspeed.io/docs/integrations/ci/github-actions/configuration#oidc-recommended\n"
299299
);
300300

301301
return Ok(());
@@ -320,10 +320,10 @@ impl RunEnvironmentProvider for GitHubActionsProvider {
320320
)
321321
}
322322

323-
info!(
324-
"CodSpeed now supports OIDC tokens for authentication.\n\
325-
Benefit from enhanced security and faster processing times by adding the `id-token: write` permission to your workflow.\n\
326-
Learn more at https://codspeed.io/docs/integrations/ci/github-actions/configuration#oidc-recommended"
323+
announcement!(
324+
"You can now authenticate your CI workflows using OpenID Connect (OIDC).\n\
325+
This makes integrating and authenticating jobs safer and simpler.\n\
326+
Learn more at https://codspeed.io/docs/integrations/ci/github-actions/configuration#oidc-recommended\n"
327327
);
328328

329329
return Ok(());

src/run/run_environment/gitlab_ci/logger.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
};
1212

1313
use crate::{
14-
logger::{GroupEvent, get_group_event, get_json_event},
14+
logger::{GroupEvent, get_announcement_event, get_group_event, get_json_event},
1515
run::run_environment::logger::should_provider_logger_handle_record,
1616
};
1717

@@ -112,6 +112,11 @@ impl Log for GitLabCILogger {
112112
return;
113113
}
114114

115+
if let Some(announcement) = get_announcement_event(record) {
116+
println!("{}", style(announcement).green());
117+
return;
118+
}
119+
115120
if get_json_event(record).is_some() {
116121
return;
117122
}

0 commit comments

Comments
 (0)