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

Register flake output paths with FlakeHub #95

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ inputs:
flakehub-push-url:
description: A URL pointing to a `flakehub-push` binary. Overrides all other `flakehub-push-*` options.
required: false
include-output-paths:
edolstra marked this conversation as resolved.
Show resolved Hide resolved
description: Whether to register the output paths of each flake output with FlakeHub.
required: false

# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions
runs:
Expand All @@ -119,6 +122,7 @@ runs:
FLAKEHUB_PUSH_EXTRA_TAGS: ${{ inputs.extra-tags }}
FLAKEHUB_PUSH_SPDX_EXPRESSION: ${{ inputs.spdx-expression }}
FLAKEHUB_PUSH_ERROR_ON_CONFLICT: ${{ inputs.error-on-conflict }}
FLAKEHUB_PUSH_INCLUDE_OUTPUT_PATHS: ${{ inputs.include-output-paths }}
Hoverbear marked this conversation as resolved.
Show resolved Hide resolved
# Also GITHUB_REPOSITORY, GITHUB_REF_NAME, GITHUB_TOKEN, ACTIONS_ID_TOKEN_REQUEST_TOKEN, ACTIONS_ID_TOKEN_REQUEST_URL
run: |
if [ "${RUNNER_OS}" == "Linux" ]; then
Expand Down
8 changes: 7 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pub(crate) struct FlakeHubPushCli {

#[clap(flatten)]
pub instrumentation: instrumentation::Instrumentation,

#[clap(long, env = "FLAKEHUB_PUSH_INCLUDE_OUTPUT_PATHS", value_parser = EmptyBoolParser, default_value_t = false)]
pub(crate) include_output_paths: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -275,6 +278,7 @@ impl FlakeHubPushCli {
spdx_expression,
extra_tags,
error_on_conflict,
include_output_paths,
} = self;

let mut extra_labels: Vec<_> = extra_labels.into_iter().filter(|v| !v.is_empty()).collect();
Expand Down Expand Up @@ -457,6 +461,7 @@ impl FlakeHubPushCli {
extra_labels,
spdx_expression.0,
error_on_conflict,
include_output_paths,
)
.await?;

Expand Down Expand Up @@ -493,6 +498,7 @@ async fn push_new_release(
extra_labels: Vec<String>,
spdx_expression: Option<spdx::Expression>,
error_if_release_conflicts: bool,
include_output_paths: bool,
) -> color_eyre::Result<()> {
let span = tracing::Span::current();
span.record("upload_name", tracing::field::display(upload_name.clone()));
Expand Down Expand Up @@ -552,7 +558,7 @@ async fn push_new_release(
.pointer("/resolved/dir")
.and_then(serde_json::Value::as_str);

let flake_outputs = get_flake_outputs(flake_locked_url).await?;
let flake_outputs = get_flake_outputs(flake_locked_url, include_output_paths).await?;
tracing::debug!("Got flake outputs: {:?}", flake_outputs);

let source = match flake_metadata_value_resolved_dir {
Expand Down
22 changes: 17 additions & 5 deletions src/flake_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,28 @@ pub(crate) async fn get_flake_metadata(directory: &Path) -> color_eyre::Result<s
}

#[tracing::instrument(skip_all, fields(flake_url,))]
pub(crate) async fn get_flake_outputs(flake_url: &str) -> color_eyre::Result<serde_json::Value> {
pub(crate) async fn get_flake_outputs(
flake_url: &str,
include_output_paths: bool,
) -> color_eyre::Result<serde_json::Value> {
let tempdir = tempfile::Builder::new()
.prefix("flakehub_push_outputs")
.tempdir()
.wrap_err("Creating tempdir")?;

let flake_contents = include_str!("mixed-flake.nix").replace(
FLAKE_URL_PLACEHOLDER_UUID,
&flake_url.escape_default().to_string(),
);
let flake_contents = include_str!("mixed-flake.nix")
.replace(
FLAKE_URL_PLACEHOLDER_UUID,
&flake_url.escape_default().to_string(),
)
.replace(
"INCLUDE_OUTPUT_PATHS",
if include_output_paths {
"true"
} else {
"false"
},
);

let mut flake = tokio::fs::File::create(tempdir.path().join("flake.nix")).await?;
flake.write_all(flake_contents.as_bytes()).await?;
Expand Down
30 changes: 29 additions & 1 deletion src/mixed-flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
inputs.flake.url = "c9026fc0-ced9-48e0-aa3c-fc86c4c86df1";
outputs = inputs:
{
includeOutputPaths = INCLUDE_OUTPUT_PATHS;

contents =
let
getFlakeOutputs = flake:
Expand Down Expand Up @@ -69,7 +71,33 @@
shortDescription = attrs.shortDescription or null;
what = attrs.what or null;
#evalChecks = attrs.evalChecks or {};
}
} // (
if inputs.self.includeOutputPaths then
{
derivation =
if attrs ? derivation
then builtins.unsafeDiscardStringContext attrs.derivation.drvPath
else null;
outputs =
if attrs ? derivation
then
builtins.listToAttrs
(
builtins.map
(outputName:
{
name = outputName;
value = attrs.derivation.${outputName}.outPath;
}
)
attrs.derivation.outputs
)
else
null;
}
else
{ }
)
else
{ };
in
Expand Down