Skip to content
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
87 changes: 76 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions magic-nix-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ http-body-util = "0.1"
hyper = { version = "1.0.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
xdg = { version = "2.5.2" }
color-eyre = { version = "0.6.3" }

[dependencies.tokio]
version = "1.44.2"
Expand Down
52 changes: 52 additions & 0 deletions magic-nix-cache/src/github.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use serde::{Deserialize, Serialize};

const GITHUB_ACTOR_TYPE_USER: &str = "User";
const GITHUB_ACTOR_TYPE_ORGANIZATION: &str = "Organization";

#[derive(Serialize, Deserialize)]
pub struct WorkflowData {
event: WorkflowDataEvent,
}

#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEvent {
repository: WorkflowDataEventRepo,
}

#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEventRepo {
owner: WorkflowDataEventRepoOwner,
}

#[derive(Serialize, Deserialize)]
pub struct WorkflowDataEventRepoOwner {
login: String,
#[serde(rename = "type")]
kind: String,
}

pub(crate) fn get_actions_event_data() -> color_eyre::Result<WorkflowData> {
let github_context = std::env::var("GITHUB_CONTEXT")?;
let workflow_data: WorkflowData = serde_json::from_str::<WorkflowData>(&github_context)?;

Ok(workflow_data)
}

pub(crate) fn print_unauthenticated_error() {
let mut msg = "::error title=FlakeHub registration required.::Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.".to_string();
if let Ok(workflow_data) = get_actions_event_data() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may not want to print the message if we get None event data, in case people are pinning the action source but not the binary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, this will be correct in that case anyway!

let owner = workflow_data.event.repository.owner;
if owner.kind == GITHUB_ACTOR_TYPE_USER {
msg = format!(
"::error title=FlakeHub registration required.::Please create an account for {} on FlakeHub.com to publish flakes.",
&owner.login
);
} else if owner.kind == GITHUB_ACTOR_TYPE_ORGANIZATION {
msg = format!(
"::error title=FlakeHub registration required.::Please create an organization for {} on FlakeHub.com to publish flakes.",
&owner.login
);
}
};
println!("{}", msg);
}
8 changes: 6 additions & 2 deletions magic-nix-cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod env;
mod error;
mod flakehub;
mod gha;
mod github;
mod pbh;
mod telemetry;
mod util;
Expand Down Expand Up @@ -366,8 +367,11 @@ async fn main_cli() -> Result<()> {
Some(state)
}
Err(err) => {
tracing::error!("FlakeHub cache initialization failed: {}. Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.", err);
println!("::error title={{FlakeHub: Unauthenticated}}::{{Unable to authenticate to FlakeHub. Individuals must register at FlakeHub.com; Organizations must create an organization at FlakeHub.com.}}");
tracing::error!(
"FlakeHub: cache initialized failed: Unauthenticated: {}",
err
);
github::print_unauthenticated_error();
None
}
}
Expand Down
Loading