Skip to content

Commit

Permalink
Merge pull request #95 from DeterminateSystems/edolstra/fh-1-upload-o…
Browse files Browse the repository at this point in the history
…utput-paths

Register flake output paths with FlakeHub
  • Loading branch information
edolstra authored Nov 17, 2023
2 parents 44fa52f + e20706f commit ee6c7aa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ inputs:
description: Whether to error if a release for the same version has already been uploaded.
required: false
default: false
include-output-paths:
description: Whether to register the output paths of each flake output with FlakeHub.
required: false

flakehub-push-binary:
description: Run a version of the `flakehub-push` binary from somewhere already on disk. Conflicts with all other `flakehub-push-*` options.
Expand Down Expand Up @@ -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 }}
# 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

0 comments on commit ee6c7aa

Please sign in to comment.