From ab2c147a10a6e5f4aaa05d2d122a8e160d8bd10c Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 12:10:33 -0800 Subject: [PATCH 01/16] Revert "Revert "Less GitHub dependence"" --- src/cli/mod.rs | 76 +++++++++++++++++++++++++++++++---- src/push.rs | 45 ++++++++++++++------- src/release_metadata.rs | 88 +++++++++++++---------------------------- 3 files changed, 127 insertions(+), 82 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index baddb80..070432b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -2,13 +2,17 @@ mod instrumentation; use color_eyre::eyre::{eyre, WrapErr}; use std::{ + collections::HashSet, path::{Path, PathBuf}, process::ExitCode, }; use crate::{ build_http_client, - github::{get_actions_id_bearer_token, graphql::GithubGraphqlDataQuery}, + github::{ + get_actions_id_bearer_token, + graphql::{GithubGraphqlDataQuery, MAX_LABEL_LENGTH, MAX_NUM_TOTAL_LABELS}, + }, push::push_new_release, release_metadata::RevisionInfo, }; @@ -247,9 +251,27 @@ impl FlakeHubPushCli { #[tracing::instrument( name = "flakehub_push" skip_all, + fields( + host = self.host, + visibility = ?self.visibility, + name = self.name.0, + tag = tracing::field::Empty, + rolling_minor = tracing::field::Empty, + rolling = self.rolling, + directory = tracing::field::Empty, + repository = tracing::field::Empty, + git_root = tracing::field::Empty, + mirror = self.mirror, + jwt_issuer_uri = tracing::field::Empty, + extra_labels = self.extra_labels.join(","), + spdx_identifier = tracing::field::Empty, + error_on_conflict = self.error_on_conflict, + include_output_paths = self.include_output_paths, + ) )] pub(crate) async fn execute(self) -> color_eyre::Result { - tracing::trace!(?self, "Executing"); + let span = tracing::Span::current(); + tracing::trace!("Executing"); let Self { host, visibility, @@ -390,6 +412,7 @@ impl FlakeHubPushCli { let github_api_client = build_http_client().build()?; let revision_info = RevisionInfo::from_git_root(&git_root)?; + let github_graphql_data_result = GithubGraphqlDataQuery::get( &github_api_client, &github_token, @@ -434,24 +457,63 @@ impl FlakeHubPushCli { } }; + let commit_count = match revision_info.local_revision_count { + Some(n) => n as i64, + None => { + tracing::debug!( + "Getting revision count locally failed, using data from github instead" + ); + github_graphql_data_result.rev_count + } + }; + + let spdx_identifier = if spdx_expression.0.is_some() { + spdx_expression.0 + } else if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier { + let parsed = spdx::Expression::parse(spdx_string) + .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; + span.record("spdx_identifier", tracing::field::display(&parsed)); + Some(parsed) + } else { + None + }; + + // Here we merge explicitly user-supplied labels and the labels ("topics") + // associated with the repo. Duplicates are excluded and all + // are converted to lower case. + let labels: Vec = extra_labels + .into_iter() + .chain(github_graphql_data_result.topics.into_iter()) + .collect::>() + .into_iter() + .take(MAX_NUM_TOTAL_LABELS) + .map(|s| s.trim().to_lowercase()) + .filter(|t: &String| { + !t.is_empty() + && t.len() <= MAX_LABEL_LENGTH + && t.chars().all(|c| c.is_alphanumeric() || c == '-') + }) + .collect(); + push_new_release( &host, &upload_bearer_token, &git_root, &subdir, - revision_info, - &repository, + revision_info.revision, + commit_count, upload_name, mirror, visibility, tag, rolling, rolling_minor.0, - github_graphql_data_result, - extra_labels, - spdx_expression.0, + labels, + spdx_identifier, error_on_conflict, include_output_paths, + github_graphql_data_result.project_id, + github_graphql_data_result.owner_id, ) .await?; diff --git a/src/push.rs b/src/push.rs index d584a0b..188602b 100644 --- a/src/push.rs +++ b/src/push.rs @@ -11,8 +11,7 @@ use crate::{ build_http_client, error::Error, flake_info::{check_flake_evaluates, get_flake_metadata, get_flake_outputs, get_flake_tarball}, - github::graphql::GithubGraphqlDataResult, - release_metadata::{ReleaseMetadata, RevisionInfo}, + release_metadata::ReleaseMetadata, Visibility, }; @@ -21,12 +20,25 @@ const DEFAULT_ROLLING_PREFIX: &str = "0.1"; #[tracing::instrument( skip_all, fields( - repository = %repository, - upload_name = tracing::field::Empty, - mirror = %mirror, - tag = tracing::field::Empty, - source = tracing::field::Empty, - mirrored = tracing::field::Empty, + host, + flake_root, + subdir, + revision, + revision_count, + repository, + upload_name, + mirror, + %visibility, + tag, + rolling, + rolling_minor, + labels = labels.join(","), + mirror, + spdx_expression, + error_if_release_conflicts, + include_output_paths, + project_id, + owner_id, ) )] #[allow(clippy::too_many_arguments)] @@ -35,19 +47,20 @@ pub(crate) async fn push_new_release( upload_bearer_token: &str, flake_root: &Path, subdir: &Path, - revision_info: RevisionInfo, - repository: &str, + revision: String, + revision_count: i64, upload_name: String, mirror: bool, visibility: Visibility, tag: Option, rolling: bool, rolling_minor: Option, - github_graphql_data_result: GithubGraphqlDataResult, - extra_labels: Vec, + labels: Vec, spdx_expression: Option, error_if_release_conflicts: bool, include_output_paths: bool, + project_id: i64, + owner_id: i64, ) -> color_eyre::Result<()> { let span = tracing::Span::current(); span.record("upload_name", tracing::field::display(upload_name.clone())); @@ -202,15 +215,17 @@ pub(crate) async fn push_new_release( let release_metadata = ReleaseMetadata::build( &source, subdir, - revision_info, + revision, + revision_count, flake_metadata, flake_outputs, upload_name.clone(), mirror, visibility, - github_graphql_data_result, - extra_labels, + labels, spdx_expression, + project_id, + owner_id, ) .await .wrap_err("Building release metadata")?; diff --git a/src/release_metadata.rs b/src/release_metadata.rs index 7f39f28..e545e51 100644 --- a/src/release_metadata.rs +++ b/src/release_metadata.rs @@ -1,10 +1,7 @@ use color_eyre::eyre::{eyre, WrapErr}; -use std::{collections::HashSet, path::Path}; +use std::path::Path; -use crate::{ - github::graphql::{GithubGraphqlDataResult, MAX_LABEL_LENGTH, MAX_NUM_TOTAL_LABELS}, - Visibility, -}; +use crate::Visibility; const README_FILENAME_LOWERCASE: &str = "readme.md"; @@ -90,92 +87,63 @@ impl ReleaseMetadata { subdir = %subdir.display(), description = tracing::field::Empty, readme_path = tracing::field::Empty, - revision = tracing::field::Empty, - revision_count = tracing::field::Empty, - commit_count = tracing::field::Empty, + %revision, + %commit_count, spdx_identifier = tracing::field::Empty, visibility = ?visibility, + %project_id, + %owner_id ))] pub(crate) async fn build( flake_store_path: &Path, subdir: &Path, - revision_info: RevisionInfo, + revision: String, + commit_count: i64, flake_metadata: serde_json::Value, flake_outputs: serde_json::Value, upload_name: String, mirror: bool, visibility: Visibility, - github_graphql_data_result: GithubGraphqlDataResult, - extra_labels: Vec, - spdx_expression: Option, + labels: Vec, + spdx_identifier: Option, + project_id: i64, + owner_id: i64, ) -> color_eyre::Result { let span = tracing::Span::current(); - span.record("revision_string", &revision_info.revision); + if let Some(spdx_identifier) = &spdx_identifier { + span.record("spdx_identifier", tracing::field::display(spdx_identifier)); + } assert!(subdir.is_relative()); - let revision_count = match revision_info.local_revision_count { - Some(n) => n as i64, - None => { - tracing::debug!( - "Getting revision count locally failed, using data from github instead" - ); - github_graphql_data_result.rev_count - } - }; - span.record("revision_count", revision_count); - let description = if let Some(description) = flake_metadata.get("description") { - Some(description + let description_value = description .as_str() .ok_or_else(|| { eyre!("`nix flake metadata --json` does not have a string `description` field") })? - .to_string()) + .to_string(); + span.record("description", tracing::field::display(&description_value)); + Some(description_value) } else { None }; - let readme = get_readme(flake_store_path).await?; - - let spdx_identifier = if spdx_expression.is_some() { - spdx_expression - } else if let Some(spdx_string) = github_graphql_data_result.spdx_identifier { - let parsed = spdx::Expression::parse(&spdx_string) - .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; - span.record("spdx_identifier", tracing::field::display(&parsed)); - Some(parsed) - } else { - None - }; + let readme_path = get_readme(flake_store_path).await?; + if let Some(readme_path) = &readme_path { + span.record("readme_path", tracing::field::display(readme_path)); + } tracing::trace!("Collected ReleaseMetadata information"); - // Here we merge explicitly user-supplied labels and the labels ("topics") - // associated with the repo. Duplicates are excluded and all - // are converted to lower case. - let labels: Vec = extra_labels - .into_iter() - .chain(github_graphql_data_result.topics.into_iter()) - .collect::>() - .into_iter() - .take(MAX_NUM_TOTAL_LABELS) - .map(|s| s.trim().to_lowercase()) - .filter(|t: &String| { - !t.is_empty() - && t.len() <= MAX_LABEL_LENGTH - && t.chars().all(|c| c.is_alphanumeric() || c == '-') - }) - .collect(); - Ok(ReleaseMetadata { description, repo: upload_name.to_string(), raw_flake_metadata: flake_metadata.clone(), - readme, - revision: revision_info.revision, - commit_count: github_graphql_data_result.rev_count, + readme: readme_path, + revision, + commit_count, visibility, outputs: flake_outputs, source_subdirectory: Some( @@ -186,8 +154,8 @@ impl ReleaseMetadata { ), mirrored: mirror, spdx_identifier, - project_id: github_graphql_data_result.project_id, - owner_id: github_graphql_data_result.owner_id, + project_id, + owner_id, labels, }) } From 97921ea720f7cc223dc7c720f30b1bc25c9ebe87 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 12:15:08 -0800 Subject: [PATCH 02/16] No longer use a local revcount for now --- src/cli/mod.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 070432b..5fea499 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -457,15 +457,7 @@ impl FlakeHubPushCli { } }; - let commit_count = match revision_info.local_revision_count { - Some(n) => n as i64, - None => { - tracing::debug!( - "Getting revision count locally failed, using data from github instead" - ); - github_graphql_data_result.rev_count - } - }; + let commit_count = github_graphql_data_result.rev_count; let spdx_identifier = if spdx_expression.0.is_some() { spdx_expression.0 From f8bd9d32cbb5ce521fa07313e0df96020d69bc7a Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 12:33:13 -0800 Subject: [PATCH 03/16] Restore instrumentation --- src/cli/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 5fea499..db03697 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -261,6 +261,7 @@ impl FlakeHubPushCli { directory = tracing::field::Empty, repository = tracing::field::Empty, git_root = tracing::field::Empty, + commit_count = tracing::field::Empty, mirror = self.mirror, jwt_issuer_uri = tracing::field::Empty, extra_labels = self.extra_labels.join(","), @@ -458,6 +459,7 @@ impl FlakeHubPushCli { }; let commit_count = github_graphql_data_result.rev_count; + span.record("commit_count", commit_count); let spdx_identifier = if spdx_expression.0.is_some() { spdx_expression.0 From f5fdb3d7998d5ebef763ac82319800926d7e9a75 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 13:22:07 -0800 Subject: [PATCH 04/16] Remove non-token dependencies on GitHub Actions --- src/cli/mod.rs | 218 +++++++++++++++++++++++----------------- src/push.rs | 6 +- src/release_metadata.rs | 18 +--- 3 files changed, 129 insertions(+), 113 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index db03697..17829cb 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -248,6 +248,32 @@ impl clap::builder::TypedValueParser for U64ToNoneParser { } impl FlakeHubPushCli { + pub(crate) fn populate_missing_from_github(&mut self) { + if self.git_root.0.is_none() { + let env_key = "GITHUB_WORKSPACE"; + if let Ok(env_val) = std::env::var(env_key) { + tracing::debug!(git_root = %env_val, "Set via `${env_key}`"); + self.git_root.0 = Some(PathBuf::from(env_val)); + } + } + + if self.repository.0.is_none() { + let env_key = "GITHUB_REPOSITORY"; + if let Ok(env_val) = std::env::var(env_key) { + tracing::debug!(repository = %env_val, "Set via `${env_key}`"); + self.repository.0 = Some(env_val); + } + } + + if self.tag.0.is_none() { + let env_key = "GITHUB_REF_NAME"; + if let Ok(env_val) = std::env::var(env_key) { + tracing::debug!(repository = %env_val, "Set via `${env_key}`"); + self.tag.0 = Some(env_val); + } + } + } + #[tracing::instrument( name = "flakehub_push" skip_all, @@ -270,9 +296,16 @@ impl FlakeHubPushCli { include_output_paths = self.include_output_paths, ) )] - pub(crate) async fn execute(self) -> color_eyre::Result { + pub(crate) async fn execute(mut self) -> color_eyre::Result { let span = tracing::Span::current(); tracing::trace!("Executing"); + + let is_github_actions = std::env::var("GITHUB_ACTION").ok().is_some(); + if is_github_actions { + tracing::debug!("Running inside Github Actions, enriching from environment"); + self.populate_missing_from_github() + } + let Self { host, visibility, @@ -294,10 +327,9 @@ impl FlakeHubPushCli { include_output_paths, } = self; - let mut extra_labels: Vec<_> = extra_labels.into_iter().filter(|v| !v.is_empty()).collect(); - let extra_tags: Vec<_> = extra_tags.into_iter().filter(|v| !v.is_empty()).collect(); + let mut labels: HashSet<_> = extra_labels.into_iter().filter(|v| !v.is_empty()).collect(); + let extra_tags: HashSet<_> = extra_tags.into_iter().filter(|v| !v.is_empty()).collect(); - let is_github_actions = std::env::var("GITHUB_ACTION").ok().is_some(); if !extra_tags.is_empty() { let message = "`extra-tags` is deprecated and will be removed in the future. Please use `extra-labels` instead."; tracing::warn!("{message}"); @@ -306,8 +338,8 @@ impl FlakeHubPushCli { println!("::warning::{message}"); } - if extra_labels.is_empty() { - extra_labels = extra_tags; + if labels.is_empty() { + labels = extra_tags; } else { let message = "Both `extra-tags` and `extra-labels` were set; `extra-tags` will be ignored."; @@ -319,20 +351,10 @@ impl FlakeHubPushCli { } } - let github_token = if let Some(github_token) = &github_token.0 { - github_token.clone() - } else { - std::env::var("GITHUB_TOKEN") - .wrap_err("Could not determine Github token, pass `--github-token`, or set either `FLAKEHUB_PUSH_GITHUB_TOKEN` or `GITHUB_TOKEN`")? - }; - - let git_root = if let Some(git_root) = &git_root.0 { + let git_root = if let Some(git_root) = git_root.0 { git_root.clone() - } else if let Ok(github_workspace) = std::env::var("GITHUB_WORKSPACE") { - tracing::trace!(%github_workspace, "Got `GITHUB_WORKSPACE`"); - PathBuf::from(github_workspace) } else { - std::env::current_dir().map(PathBuf::from).wrap_err("Could not determine current git_root. Pass `--git-root` or set `FLAKEHUB_PUSH_GIT_ROOT`")? + std::env::current_dir().map(PathBuf::from).wrap_err("Could not determine current `git_root`. Pass `--git-root` or set `FLAKEHUB_PUSH_GIT_ROOT`, or run `flakehub-push` with the git root as the current working directory")? }; let git_root = git_root @@ -361,16 +383,7 @@ impl FlakeHubPushCli { PathBuf::new() }; - let repository = if let Some(repository) = &repository.0 { - tracing::trace!(%repository, "Got `--repository` argument"); - repository.clone() - } else if let Ok(github_repository) = std::env::var("GITHUB_REPOSITORY") { - tracing::trace!( - %github_repository, - "Got `GITHUB_REPOSITORY` environment" - ); - github_repository - } else { + let Some(repository) = repository.0 else { return Err(eyre!("Could not determine repository name, pass `--repository` or the `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`")); }; @@ -392,12 +405,6 @@ impl FlakeHubPushCli { repository.clone() }; - let tag = if let Some(tag) = &tag.0 { - Some(tag.clone()) - } else { - std::env::var("GITHUB_REF_NAME").ok() - }; - let mut repository_split = repository.split('/'); let project_owner = repository_split .next() @@ -410,75 +417,94 @@ impl FlakeHubPushCli { Err(eyre!("Could not determine the owner/project, pass `--repository` or `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`. The passed value has too many slashes (/) to be a valid repository"))?; } - let github_api_client = build_http_client().build()?; + #[allow(unused_assignments)] + // Since we return an error outside github actions right now, throws an unused warning. + let mut spdx_identifier = spdx_expression.0; - let revision_info = RevisionInfo::from_git_root(&git_root)?; + let RevisionInfo { + mut commit_count, + revision, + } = RevisionInfo::from_git_root(&git_root)?; - let github_graphql_data_result = GithubGraphqlDataQuery::get( - &github_api_client, - &github_token, - &project_owner, - &project_name, - &revision_info.revision, - ) - .await?; + let upload_bearer_token = if is_github_actions { + let github_token = if let Some(github_token) = &github_token.0 { + github_token.clone() + } else { + std::env::var("GITHUB_TOKEN") + .wrap_err("Could not determine Github token, pass `--github-token`, or set either `FLAKEHUB_PUSH_GITHUB_TOKEN` or `GITHUB_TOKEN`")? + }; + let github_api_client = build_http_client().build()?; + + // Take the opportunity to be able to populate/encrich data from the GitHub API since we need it for project/owner_id anywys + let github_graphql_data_result = GithubGraphqlDataQuery::get( + &github_api_client, + &github_token, + &project_owner, + &project_name, + &revision, + ) + .await?; + + commit_count = commit_count.or(Some(github_graphql_data_result.rev_count as usize)); + spdx_identifier = if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier + { + let parsed = spdx::Expression::parse(spdx_string) + .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; + span.record("spdx_identifier", tracing::field::display(&parsed)); + Some(parsed) + } else { + None + }; + + labels = labels + .into_iter() + .chain(github_graphql_data_result.topics.into_iter()) + .collect::>(); - let upload_bearer_token = match jwt_issuer_uri.0 { - None => get_actions_id_bearer_token() - .await - .wrap_err("Getting upload bearer token from GitHub")?, - - Some(jwt_issuer_uri) => { - let client = build_http_client().build()?; - let mut claims = github_actions_oidc_claims::Claims::make_dummy(); - // FIXME: we should probably fill in more of these claims. - claims.aud = "flakehub-localhost".to_string(); - claims.iss = "flakehub-push-dev".to_string(); - claims.repository = repository.clone(); - claims.repository_owner = project_owner.to_string(); - claims.repository_id = github_graphql_data_result.project_id.to_string(); - claims.repository_owner_id = github_graphql_data_result.owner_id.to_string(); - - let response = client - .post(jwt_issuer_uri) - .header("Content-Type", "application/json") - .json(&claims) - .send() + match jwt_issuer_uri.0 { + None => get_actions_id_bearer_token() .await - .wrap_err("Sending request to JWT issuer")?; - #[derive(serde::Deserialize)] - struct Response { - token: String, + .wrap_err("Getting upload bearer token from GitHub")?, + + Some(jwt_issuer_uri) => { + let client = build_http_client().build()?; + let mut claims = github_actions_oidc_claims::Claims::make_dummy(); + // FIXME: we should probably fill in more of these claims. + claims.aud = "flakehub-localhost".to_string(); + claims.iss = "flakehub-push-dev".to_string(); + claims.repository = repository.clone(); + claims.repository_owner = project_owner.to_string(); + claims.repository_id = github_graphql_data_result.project_id.to_string(); + claims.repository_owner_id = github_graphql_data_result.owner_id.to_string(); + + let response = client + .post(jwt_issuer_uri) + .header("Content-Type", "application/json") + .json(&claims) + .send() + .await + .wrap_err("Sending request to JWT issuer")?; + #[derive(serde::Deserialize)] + struct Response { + token: String, + } + let response_deserialized: Response = response + .json() + .await + .wrap_err("Getting token from JWT issuer's response")?; + response_deserialized.token } - let response_deserialized: Response = response - .json() - .await - .wrap_err("Getting token from JWT issuer's response")?; - response_deserialized.token } - }; - - let commit_count = github_graphql_data_result.rev_count; - span.record("commit_count", commit_count); - - let spdx_identifier = if spdx_expression.0.is_some() { - spdx_expression.0 - } else if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier { - let parsed = spdx::Expression::parse(spdx_string) - .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; - span.record("spdx_identifier", tracing::field::display(&parsed)); - Some(parsed) } else { - None + return Err(eyre!( + "`flakehub-push` currently only runs inside Github Actions" + )); }; // Here we merge explicitly user-supplied labels and the labels ("topics") // associated with the repo. Duplicates are excluded and all // are converted to lower case. - let labels: Vec = extra_labels - .into_iter() - .chain(github_graphql_data_result.topics.into_iter()) - .collect::>() + let labels: Vec = labels .into_iter() .take(MAX_NUM_TOTAL_LABELS) .map(|s| s.trim().to_lowercase()) @@ -489,25 +515,27 @@ impl FlakeHubPushCli { }) .collect(); + let Some(commit_count) = commit_count else { + return Err(eyre!("Did not get `commit_count`")) + }; + push_new_release( &host, &upload_bearer_token, &git_root, &subdir, - revision_info.revision, + revision, commit_count, upload_name, mirror, visibility, - tag, + tag.0, rolling, rolling_minor.0, labels, spdx_identifier, error_on_conflict, include_output_paths, - github_graphql_data_result.project_id, - github_graphql_data_result.owner_id, ) .await?; diff --git a/src/push.rs b/src/push.rs index 188602b..f344c94 100644 --- a/src/push.rs +++ b/src/push.rs @@ -48,7 +48,7 @@ pub(crate) async fn push_new_release( flake_root: &Path, subdir: &Path, revision: String, - revision_count: i64, + revision_count: usize, upload_name: String, mirror: bool, visibility: Visibility, @@ -59,8 +59,6 @@ pub(crate) async fn push_new_release( spdx_expression: Option, error_if_release_conflicts: bool, include_output_paths: bool, - project_id: i64, - owner_id: i64, ) -> color_eyre::Result<()> { let span = tracing::Span::current(); span.record("upload_name", tracing::field::display(upload_name.clone())); @@ -224,8 +222,6 @@ pub(crate) async fn push_new_release( visibility, labels, spdx_expression, - project_id, - owner_id, ) .await .wrap_err("Building release metadata")?; diff --git a/src/release_metadata.rs b/src/release_metadata.rs index e545e51..5478a48 100644 --- a/src/release_metadata.rs +++ b/src/release_metadata.rs @@ -7,7 +7,7 @@ const README_FILENAME_LOWERCASE: &str = "readme.md"; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub(crate) struct ReleaseMetadata { - pub(crate) commit_count: i64, + pub(crate) commit_count: usize, pub(crate) description: Option, pub(crate) outputs: serde_json::Value, pub(crate) raw_flake_metadata: serde_json::Value, @@ -17,8 +17,6 @@ pub(crate) struct ReleaseMetadata { pub(crate) visibility: Visibility, pub(crate) mirrored: bool, pub(crate) source_subdirectory: Option, - pub(crate) project_id: i64, - pub(crate) owner_id: i64, #[serde( deserialize_with = "option_string_to_spdx", @@ -33,7 +31,7 @@ pub(crate) struct ReleaseMetadata { #[derive(Clone)] pub(crate) struct RevisionInfo { - pub(crate) local_revision_count: Option, + pub(crate) commit_count: Option, pub(crate) revision: String, } @@ -65,7 +63,7 @@ impl RevisionInfo { } }; - let local_revision_count = gix_repository + let commit_count = gix_repository .rev_walk([revision]) .all() .map(|rev_iter| rev_iter.count()) @@ -73,7 +71,7 @@ impl RevisionInfo { let revision = revision.to_hex().to_string(); Ok(Self { - local_revision_count, + commit_count, revision, }) } @@ -91,14 +89,12 @@ impl ReleaseMetadata { %commit_count, spdx_identifier = tracing::field::Empty, visibility = ?visibility, - %project_id, - %owner_id ))] pub(crate) async fn build( flake_store_path: &Path, subdir: &Path, revision: String, - commit_count: i64, + commit_count: usize, flake_metadata: serde_json::Value, flake_outputs: serde_json::Value, upload_name: String, @@ -106,8 +102,6 @@ impl ReleaseMetadata { visibility: Visibility, labels: Vec, spdx_identifier: Option, - project_id: i64, - owner_id: i64, ) -> color_eyre::Result { let span = tracing::Span::current(); @@ -154,8 +148,6 @@ impl ReleaseMetadata { ), mirrored: mirror, spdx_identifier, - project_id, - owner_id, labels, }) } From 468fbd3f36fa884b79fef1637114a11c061806e9 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Thu, 15 Feb 2024 14:25:00 -0800 Subject: [PATCH 05/16] Slightly better heuristic --- src/cli/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 17829cb..d28e769 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -300,7 +300,8 @@ impl FlakeHubPushCli { let span = tracing::Span::current(); tracing::trace!("Executing"); - let is_github_actions = std::env::var("GITHUB_ACTION").ok().is_some(); + let is_github_actions = + self.github_token.0.is_some() || std::env::var("GITHUB_ACTION").ok().is_some(); if is_github_actions { tracing::debug!("Running inside Github Actions, enriching from environment"); self.populate_missing_from_github() From a05a1bce15f4e3bfa2221570c1ea232cb10a08ed Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 13:19:51 -0800 Subject: [PATCH 06/16] Further clarify/document Github API enrichment --- src/cli/mod.rs | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index d28e769..eb0dee9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -291,7 +291,7 @@ impl FlakeHubPushCli { mirror = self.mirror, jwt_issuer_uri = tracing::field::Empty, extra_labels = self.extra_labels.join(","), - spdx_identifier = tracing::field::Empty, + spdx_expression = tracing::field::Empty, error_on_conflict = self.error_on_conflict, include_output_paths = self.include_output_paths, ) @@ -418,10 +418,10 @@ impl FlakeHubPushCli { Err(eyre!("Could not determine the owner/project, pass `--repository` or `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`. The passed value has too many slashes (/) to be a valid repository"))?; } - #[allow(unused_assignments)] - // Since we return an error outside github actions right now, throws an unused warning. - let mut spdx_identifier = spdx_expression.0; + let mut spdx_expression = spdx_expression.0; + #[allow(unused_assignments)] + // Since we return an error outside github actions right now, `commit_count` throws an unused warning since we don't actually use it. let RevisionInfo { mut commit_count, revision, @@ -446,17 +446,39 @@ impl FlakeHubPushCli { ) .await?; - commit_count = commit_count.or(Some(github_graphql_data_result.rev_count as usize)); - spdx_identifier = if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier - { - let parsed = spdx::Expression::parse(spdx_string) - .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; - span.record("spdx_identifier", tracing::field::display(&parsed)); - Some(parsed) + // On GitHub Actions, typically shallow clones are used which would report 1 for the commit count. Override it with the result from the API. + // Since users can't set this as a command line flag, that's fine. + tracing::trace!( + "Updating `commit_count` from {} to {} via GitHub API", + commit_count + .map(|v| v.to_string()) + .unwrap_or_else(|| "".into()), + github_graphql_data_result.rev_count as usize + ); + commit_count = Some(github_graphql_data_result.rev_count as usize); + + // If the user didn't pass `--spdx-expression` from command line, enrich it with Github's data. + spdx_expression = if spdx_expression.is_none() { + if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier { + tracing::debug!("Recieved SPDX identifier `{}` from GitHub API", spdx_string); + let parsed = spdx::Expression::parse(spdx_string) + .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; + span.record("spdx_expression", tracing::field::display(&parsed)); + Some(parsed) + } else { + None + } } else { - None + // Provide the user notice if the SPDX expression passed differs from the one detected on GitHub -- It's probably something they care about. + if github_graphql_data_result.spdx_identifier + != spdx_expression.map(|v| v.to_string()) + { + tracing::debug!("Inferred SPDX identifier from GitHub API was `{}` while `{}` was passed via argument", github_graphql_data_result.spdx_identifier.unwrap_or_else(|| "None".to_string()), spdx_expression.unwrap_or_else(|| "None".to_string())) + } + spdx_expression }; + // Extend the labels provided by the user with those from GitHub. labels = labels .into_iter() .chain(github_graphql_data_result.topics.into_iter()) @@ -517,7 +539,7 @@ impl FlakeHubPushCli { .collect(); let Some(commit_count) = commit_count else { - return Err(eyre!("Did not get `commit_count`")) + return Err(eyre!("Did not get `commit_count`")); }; push_new_release( @@ -534,7 +556,7 @@ impl FlakeHubPushCli { rolling, rolling_minor.0, labels, - spdx_identifier, + spdx_expression, error_on_conflict, include_output_paths, ) From f9573f09593805f0d25adbed8c537126dde4bb25 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 13:32:42 -0800 Subject: [PATCH 07/16] Fix lints --- src/cli/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index eb0dee9..0ca6be9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -471,9 +471,13 @@ impl FlakeHubPushCli { } else { // Provide the user notice if the SPDX expression passed differs from the one detected on GitHub -- It's probably something they care about. if github_graphql_data_result.spdx_identifier - != spdx_expression.map(|v| v.to_string()) + != spdx_expression.as_ref().map(|v| v.to_string()) { - tracing::debug!("Inferred SPDX identifier from GitHub API was `{}` while `{}` was passed via argument", github_graphql_data_result.spdx_identifier.unwrap_or_else(|| "None".to_string()), spdx_expression.unwrap_or_else(|| "None".to_string())) + tracing::debug!( + "Inferred SPDX identifier from GitHub API was `{}` while `{}` was passed via argument", + github_graphql_data_result.spdx_identifier.unwrap_or_else(|| "None".to_string()), + spdx_expression.as_ref().map(|v| v.to_string()).unwrap_or_else(|| "None".to_string()) + ) } spdx_expression }; From daa7d45e100afa3e4a56f8908898a17896eb5027 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 16 Feb 2024 14:26:29 -0800 Subject: [PATCH 08/16] Small tweaks --- src/cli/mod.rs | 8 ++++---- src/release_metadata.rs | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 0ca6be9..41a6533 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -303,7 +303,7 @@ impl FlakeHubPushCli { let is_github_actions = self.github_token.0.is_some() || std::env::var("GITHUB_ACTION").ok().is_some(); if is_github_actions { - tracing::debug!("Running inside Github Actions, enriching from environment"); + tracing::debug!("Running inside Github Actions, will enrich with GitHub API data and push with authorized Github bearer token"); self.populate_missing_from_github() } @@ -473,10 +473,10 @@ impl FlakeHubPushCli { if github_graphql_data_result.spdx_identifier != spdx_expression.as_ref().map(|v| v.to_string()) { - tracing::debug!( - "Inferred SPDX identifier from GitHub API was `{}` while `{}` was passed via argument", + tracing::warn!( + "SPDX identifier `{}` was passed via argument, but GitHub's API suggests it may be `{}`", + spdx_expression.as_ref().map(|v| v.to_string()).unwrap_or_else(|| "None".to_string()), github_graphql_data_result.spdx_identifier.unwrap_or_else(|| "None".to_string()), - spdx_expression.as_ref().map(|v| v.to_string()).unwrap_or_else(|| "None".to_string()) ) } spdx_expression diff --git a/src/release_metadata.rs b/src/release_metadata.rs index 5478a48..9725762 100644 --- a/src/release_metadata.rs +++ b/src/release_metadata.rs @@ -84,7 +84,7 @@ impl ReleaseMetadata { flake_store_path = %flake_store_path.display(), subdir = %subdir.display(), description = tracing::field::Empty, - readme_path = tracing::field::Empty, + readme = tracing::field::Empty, %revision, %commit_count, spdx_identifier = tracing::field::Empty, @@ -124,9 +124,12 @@ impl ReleaseMetadata { None }; - let readme_path = get_readme(flake_store_path).await?; - if let Some(readme_path) = &readme_path { - span.record("readme_path", tracing::field::display(readme_path)); + let readme = get_readme(flake_store_path).await?; + if readme.is_some() { + span.record( + "readme", + tracing::field::display(flake_store_path.join("README.md").display()), + ); } tracing::trace!("Collected ReleaseMetadata information"); @@ -135,7 +138,7 @@ impl ReleaseMetadata { description, repo: upload_name.to_string(), raw_flake_metadata: flake_metadata.clone(), - readme: readme_path, + readme, revision, commit_count, visibility, From 5699eb41c135a78d349b14bf951d6d90e828d4c3 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 20 Feb 2024 10:21:44 -0800 Subject: [PATCH 09/16] Rework get_readme --- src/cli/mod.rs | 1 + src/release_metadata.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 41a6533..cbf234f 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -248,6 +248,7 @@ impl clap::builder::TypedValueParser for U64ToNoneParser { } impl FlakeHubPushCli { + #[tracing::instrument(skip_all)] pub(crate) fn populate_missing_from_github(&mut self) { if self.git_root.0.is_none() { let env_key = "GITHUB_WORKSPACE"; diff --git a/src/release_metadata.rs b/src/release_metadata.rs index 9725762..ce90559 100644 --- a/src/release_metadata.rs +++ b/src/release_metadata.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::{eyre, WrapErr}; -use std::path::Path; +use std::path::{Path, PathBuf}; use crate::Visibility; @@ -124,13 +124,13 @@ impl ReleaseMetadata { None }; - let readme = get_readme(flake_store_path).await?; - if readme.is_some() { - span.record( - "readme", - tracing::field::display(flake_store_path.join("README.md").display()), - ); - } + let readme_path = get_readme(flake_store_path).await?; + let readme = if let Some(readme_path) = readme_path { + span.record("readme", tracing::field::display(readme_path.display())); + Some(tokio::fs::read_to_string(&readme_path).await?) + } else { + None + }; tracing::trace!("Collected ReleaseMetadata information"); @@ -186,12 +186,13 @@ where } } -async fn get_readme(readme_dir: &Path) -> color_eyre::Result> { +#[tracing::instrument(skip_all, fields(readme_dir))] +async fn get_readme(readme_dir: &Path) -> color_eyre::Result> { let mut read_dir = tokio::fs::read_dir(readme_dir).await?; while let Some(entry) = read_dir.next_entry().await? { if entry.file_name().to_ascii_lowercase() == README_FILENAME_LOWERCASE { - return Ok(Some(tokio::fs::read_to_string(entry.path()).await?)); + return Ok(Some(entry.path())); } } From 2e992f2dde07968f11ecfd42195865ebadcf13f5 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 20 Feb 2024 11:00:01 -0800 Subject: [PATCH 10/16] Tunable audience --- src/cli/mod.rs | 2 +- src/github/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index cbf234f..6147d30 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -490,7 +490,7 @@ impl FlakeHubPushCli { .collect::>(); match jwt_issuer_uri.0 { - None => get_actions_id_bearer_token() + None => get_actions_id_bearer_token(&host) .await .wrap_err("Getting upload bearer token from GitHub")?, diff --git a/src/github/mod.rs b/src/github/mod.rs index d8c5f98..47b79e0 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -5,7 +5,7 @@ use color_eyre::eyre::{eyre, WrapErr}; use crate::build_http_client; #[tracing::instrument(skip_all)] -pub(crate) async fn get_actions_id_bearer_token() -> color_eyre::Result { +pub(crate) async fn get_actions_id_bearer_token(audience: &str) -> color_eyre::Result { let actions_id_token_request_token = std::env::var("ACTIONS_ID_TOKEN_REQUEST_TOKEN") // We do want to preserve the whitespace here .wrap_err("\ @@ -26,7 +26,7 @@ jobs: let actions_id_token_client = build_http_client().build()?; let response = actions_id_token_client .get(format!( - "{actions_id_token_request_url}&audience=api.flakehub.com" + "{actions_id_token_request_url}&audience={audience}" )) .bearer_auth(actions_id_token_request_token) .send() From 0a5b958bb14985f89817468a52377861d5ef7caf Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 20 Feb 2024 11:22:27 -0800 Subject: [PATCH 11/16] Use a URL for host --- Cargo.lock | 2 ++ Cargo.toml | 1 + src/cli/mod.rs | 4 ++-- src/github/mod.rs | 8 ++++++-- src/push.rs | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81342b7..465a59d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -524,6 +524,7 @@ dependencies = [ "tracing", "tracing-error", "tracing-subscriber", + "url", "uuid", ] @@ -2709,6 +2710,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 364f8b3..84c7657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ spdx = "0.10.2" uuid = { version = "1.4.0", features = ["serde", "v7", "rand", "std"] } semver = { version = "1.0.18", features = ["serde"] } thiserror = "1.0.56" +url = { version = "2.5.0", features = ["serde"] } [profile.release] strip = true # Automatically strip symbols from the binary. diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 6147d30..a0d5f2f 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -25,7 +25,7 @@ pub(crate) struct FlakeHubPushCli { env = "FLAKEHUB_PUSH_HOST", default_value = "https://api.flakehub.com" )] - pub(crate) host: String, + pub(crate) host: url::Url, #[clap(long, env = "FLAKEHUB_PUSH_VISIBLITY")] pub(crate) visibility: crate::Visibility, // Will also detect `GITHUB_REF_NAME` @@ -279,7 +279,7 @@ impl FlakeHubPushCli { name = "flakehub_push" skip_all, fields( - host = self.host, + host = %self.host, visibility = ?self.visibility, name = self.name.0, tag = tracing::field::Empty, diff --git a/src/github/mod.rs b/src/github/mod.rs index 47b79e0..826cf9a 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -4,8 +4,12 @@ use color_eyre::eyre::{eyre, WrapErr}; use crate::build_http_client; -#[tracing::instrument(skip_all)] -pub(crate) async fn get_actions_id_bearer_token(audience: &str) -> color_eyre::Result { +#[tracing::instrument(skip_all, fields(audience = tracing::field::Empty))] +pub(crate) async fn get_actions_id_bearer_token(host: &url::Url) -> color_eyre::Result { + let span = tracing::Span::current(); + let audience = host.host_str().ok_or_else(|| eyre!("`host` must contain a valid host (eg `https://api.flakehub.com` contains `api.flakehub.com`)"))?; + span.record("audience", audience); + let actions_id_token_request_token = std::env::var("ACTIONS_ID_TOKEN_REQUEST_TOKEN") // We do want to preserve the whitespace here .wrap_err("\ diff --git a/src/push.rs b/src/push.rs index f344c94..77a0789 100644 --- a/src/push.rs +++ b/src/push.rs @@ -20,7 +20,7 @@ const DEFAULT_ROLLING_PREFIX: &str = "0.1"; #[tracing::instrument( skip_all, fields( - host, + %host, flake_root, subdir, revision, @@ -43,7 +43,7 @@ const DEFAULT_ROLLING_PREFIX: &str = "0.1"; )] #[allow(clippy::too_many_arguments)] pub(crate) async fn push_new_release( - host: &str, + host: &url::Url, upload_bearer_token: &str, flake_root: &Path, subdir: &Path, From 4d88e4c9d9f696bcc656c6355bb202806095caee Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 20 Feb 2024 11:34:51 -0800 Subject: [PATCH 12/16] Don't do string joins on url --- src/push.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/push.rs b/src/push.rs index 77a0789..7325370 100644 --- a/src/push.rs +++ b/src/push.rs @@ -237,11 +237,9 @@ pub(crate) async fn push_new_release( rolling_prefix_or_tag.to_string() // This will always be the tag since `self.rolling_prefix` was empty. }; - let release_metadata_post_url = format!( - "{host}/upload/{upload_name}/{rolling_minor_with_postfix_or_tag}/{flake_tarball_len}/{flake_tarball_hash_base64}" - ); + let release_metadata_post_url = host.join(&format!("upload/{upload_name}/{rolling_minor_with_postfix_or_tag}/{flake_tarball_len}/{flake_tarball_hash_base64}"))?; tracing::debug!( - url = release_metadata_post_url, + url = %release_metadata_post_url, "Computed release metadata POST URL" ); From 045cde28d7ccb75afffeab34b95a20c258f194bd Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 20 Feb 2024 13:19:00 -0800 Subject: [PATCH 13/16] Use url over strings on post URL too --- src/push.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/push.rs b/src/push.rs index 7325370..c840751 100644 --- a/src/push.rs +++ b/src/push.rs @@ -353,8 +353,8 @@ pub(crate) async fn push_new_release( } // Make the release we just uploaded visible. - let publish_post_url = format!("{host}/publish/{}", release_metadata_post_result.uuid); - tracing::debug!(url = publish_post_url, "Computed publish POST URL"); + let publish_post_url = host.join(&format!("publish/{}", release_metadata_post_result.uuid))?; + tracing::debug!(url = %publish_post_url, "Computed publish POST URL"); let publish_response = flakehub_client .post(publish_post_url) From ea9f19d8e00964fe705073ce498785e3971ab1b4 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 21 Feb 2024 10:03:51 -0800 Subject: [PATCH 14/16] Remove github specifics from some errors --- src/cli/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index a0d5f2f..57d442f 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -60,7 +60,7 @@ pub(crate) struct FlakeHubPushCli { #[clap(long, env = "FLAKEHUB_PUSH_JWT_ISSUER_URI", value_parser = StringToNoneParser, default_value = "")] pub(crate) jwt_issuer_uri: OptionString, - /// User-supplied labels beyond those associated with the GitHub repository. + /// User-supplied labels, merged with any associated with GitHub repository (if possible) #[clap( long, short = 'l', @@ -80,7 +80,7 @@ pub(crate) struct FlakeHubPushCli { )] pub(crate) extra_tags: Vec, - /// An SPDX expression that overrides that which is returned from GitHub. + /// An SPDX identifier from https://spdx.org/licenses/, inferred from GitHub (if possible) #[clap( long, env = "FLAKEHUB_PUSH_SPDX_EXPRESSION", @@ -386,7 +386,7 @@ impl FlakeHubPushCli { }; let Some(repository) = repository.0 else { - return Err(eyre!("Could not determine repository name, pass `--repository` or the `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`")); + return Err(eyre!("Could not determine repository name, pass `--repository` formatted like `determinatesystems/flakehub-push`")); }; // If the upload name is supplied by the user, ensure that it contains exactly @@ -399,7 +399,7 @@ impl FlakeHubPushCli { || !name.is_ascii() || name.contains(char::is_whitespace) { - return Err(eyre!("The `upload-name` must be in the format of `owner-name/repo-name` and cannot contain whitespace or other special characters")); + return Err(eyre!("The argument `--name` must be in the format of `owner-name/repo-name` and cannot contain whitespace or other special characters")); } else { name } @@ -410,13 +410,13 @@ impl FlakeHubPushCli { let mut repository_split = repository.split('/'); let project_owner = repository_split .next() - .ok_or_else(|| eyre!("Could not determine owner, pass `--repository` or the `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`"))? + .ok_or_else(|| eyre!("Could not determine owner, pass `--repository` formatted like `determinatesystems/flakehub-push`"))? .to_string(); let project_name = repository_split.next() - .ok_or_else(|| eyre!("Could not determine project, pass `--repository` or `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`"))? + .ok_or_else(|| eyre!("Could not determine project, pass `--repository` formatted like `determinatesystems/flakehub-push`"))? .to_string(); if repository_split.next().is_some() { - Err(eyre!("Could not determine the owner/project, pass `--repository` or `GITHUB_REPOSITORY` formatted like `determinatesystems/flakehub-push`. The passed value has too many slashes (/) to be a valid repository"))?; + Err(eyre!("Could not determine the owner/project, pass `--repository` formatted like `determinatesystems/flakehub-push`. The passed value has too many slashes (/) to be a valid repository"))?; } let mut spdx_expression = spdx_expression.0; @@ -433,7 +433,7 @@ impl FlakeHubPushCli { github_token.clone() } else { std::env::var("GITHUB_TOKEN") - .wrap_err("Could not determine Github token, pass `--github-token`, or set either `FLAKEHUB_PUSH_GITHUB_TOKEN` or `GITHUB_TOKEN`")? + .wrap_err("Could not determine Github token, pass `--github-token`")? }; let github_api_client = build_http_client().build()?; From 84c7280bfe591654dea2971d7e7eb2451573848e Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 21 Feb 2024 10:15:31 -0800 Subject: [PATCH 15/16] Fixup error message --- src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 57d442f..7549ae7 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -544,7 +544,7 @@ impl FlakeHubPushCli { .collect(); let Some(commit_count) = commit_count else { - return Err(eyre!("Did not get `commit_count`")); + return Err(eyre!("Could not determine commit count, this is normally determined via the `--git-root` argument or via the GitHub API")); }; push_new_release( From 6272f7421d689dba61359275fb2306d73abd565b Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Wed, 21 Feb 2024 10:19:44 -0800 Subject: [PATCH 16/16] `--host` not `host` --- src/github/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github/mod.rs b/src/github/mod.rs index 826cf9a..e4d23bd 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -7,7 +7,7 @@ use crate::build_http_client; #[tracing::instrument(skip_all, fields(audience = tracing::field::Empty))] pub(crate) async fn get_actions_id_bearer_token(host: &url::Url) -> color_eyre::Result { let span = tracing::Span::current(); - let audience = host.host_str().ok_or_else(|| eyre!("`host` must contain a valid host (eg `https://api.flakehub.com` contains `api.flakehub.com`)"))?; + let audience = host.host_str().ok_or_else(|| eyre!("`--host` must contain a valid host (eg `https://api.flakehub.com` contains `api.flakehub.com`)"))?; span.record("audience", audience); let actions_id_token_request_token = std::env::var("ACTIONS_ID_TOKEN_REQUEST_TOKEN")