Skip to content

Commit

Permalink
Remove ExecutionEnvironment::Fake and construct ReleaseMetadata and T…
Browse files Browse the repository at this point in the history
…arball instead
  • Loading branch information
cole-h committed Sep 13, 2024
1 parent 7b65ea3 commit 4024285
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
2 changes: 0 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ impl FlakeHubPushCli {
ExecutionEnvironment::GitHub
} else if std::env::var("GITLAB_CI").ok().is_some() {
ExecutionEnvironment::GitLab
} else if cli.dest_dir.0.is_some() {
ExecutionEnvironment::Fake
} else {
ExecutionEnvironment::LocalGitHub
}
Expand Down
38 changes: 26 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,44 @@ async fn execute() -> Result<std::process::ExitCode> {
let mut cli = cli::FlakeHubPushCli::parse();
cli.instrumentation.setup()?;

let ctx = { PushContext::from_cli_and_env(&mut cli).await? };

if let Some(dest_dir) = cli.dest_dir.0 {
std::fs::create_dir_all(&dest_dir)?;
// NOTE(cole-h): If --dest-dir is passed, we're intentionally avoiding doing any actual
// networking (i.e. for FlakeHub and GitHub)
if let Some(dest_dir) = &cli.dest_dir.0 {
let local_git_root = cli.resolve_local_git_root()?;
let local_rev_info = revision_info::RevisionInfo::from_git_root(&local_git_root)?;
let git_ctx = git_context::GitContext {
spdx_expression: cli.spdx_expression.0.clone(),
repo_topics: vec![],
revision_info: local_rev_info,
};

let release_version = cli.release_version(&git_ctx)?;
let release_tarball_name = format!("{release_version}.tar.gz");
let release_json_name = format!("{release_version}.json");

let (release_metadata, tarball) =
release_metadata::ReleaseMetadata::new(&cli, &git_ctx, None).await?;

std::fs::create_dir_all(dest_dir)?;

{
let dest_file = dest_dir.join(ctx.release_version.clone() + ".tar.gz");
let dest_file = dest_dir.join(release_tarball_name);
tracing::info!("Writing tarball to {}", dest_file.display());
std::fs::write(dest_file, ctx.tarball.bytes)?;
std::fs::write(dest_file, tarball.bytes)?;
}

{
let dest_file = dest_dir.join(ctx.release_version + ".json");
let dest_file = dest_dir.join(release_json_name);
tracing::info!("Writing release metadata to {}", dest_file.display());
std::fs::write(dest_file, serde_json::to_string(&ctx.metadata)?)?;
std::fs::write(dest_file, serde_json::to_string(&release_metadata)?)?;
}

return Ok(ExitCode::SUCCESS);
}

let fhclient = FlakeHubClient::new(
ctx.flakehub_host,
ctx.auth_token.expect("did not get FlakeHub auth token"),
)?;
let ctx = PushContext::from_cli_and_env(&mut cli).await?;

let fhclient = FlakeHubClient::new(ctx.flakehub_host, ctx.auth_token)?;

// "upload.rs" - stage the release
let stage_result = fhclient
Expand Down
17 changes: 4 additions & 13 deletions src/push_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ pub enum ExecutionEnvironment {
GitHub,
GitLab,
LocalGitHub,
Fake,
}

pub(crate) struct PushContext {
pub(crate) flakehub_host: url::Url,
pub(crate) auth_token: Option<String>,
pub(crate) auth_token: String,

// url components
pub(crate) upload_name: String, // {org}/{project}
Expand Down Expand Up @@ -93,7 +92,7 @@ impl PushContext {
.await
.wrap_err("Getting upload bearer token from GitHub")?;

(Some(token), git_ctx)
(token, git_ctx)
}
(ExecutionEnvironment::GitLab, None) => {
// GITLAB CI
Expand All @@ -103,7 +102,7 @@ impl PushContext {

let git_ctx = GitContext::from_cli_and_gitlab(cli, local_rev_info).await?;

(Some(token), git_ctx)
(token, git_ctx)
}
(ExecutionEnvironment::LocalGitHub, Some(u)) => {
// LOCAL, DEV (aka emulating GITHUB)
Expand Down Expand Up @@ -132,15 +131,7 @@ impl PushContext {
github_graphql_data_result,
)
.await?;
(Some(token), git_ctx)
}
(ExecutionEnvironment::Fake, _) => {
let git_ctx = GitContext {
spdx_expression: cli.spdx_expression.0.clone(),
repo_topics: vec![],
revision_info: local_rev_info,
};
(None, git_ctx)
(token, git_ctx)
}
(_, Some(_)) => {
// we're in (GitHub|GitLab) and jwt_issuer_uri was specified, invalid
Expand Down

0 comments on commit 4024285

Please sign in to comment.