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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Parameter | Description | Type | Required? | Default
`git-root` | The root directory of your Git repository. | relative path | | `.`
`extra-labels` | `flakehub-push` automatically uses the GitHub repo's topics as labels. This `extra-labels` parameter enables you to add extra labels beyond that as a comma-separated string. Only alphanumeric characters and hyphens are allowed in labels and the maximum length of labels is 50 characters. You can specify a maximum of 20 extra labels, and have a maximum of 25 labels, including those that we retrieve from GitHub. Any labels after the 25th will be ignored. | string | | `""`
`spdx-expression` | A valid SPDX license expression. This will be used in place of what GitHub claims your repository's `spdxIdentifier` is. | string | | `""`
`error-on-conflict` | Whether to error if a release for the same version has already been uploaded. | Boolean | | `false`
`github-token` | The GitHub token for making authenticated GitHub API requests. | `${{ github.token }}`
`host` | The FlakeHub server to use | URL | | `https://api.flakehub.com`
`logger` | The logger to use. Options are `pretty`, `json`, `full` and `compact`. | enum | | `full`
Expand Down
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ inputs:
description: A valid SPDX license expression. This will be used in place of what GitHub claims your repository's `spdxIdentifier` is.
required: false
default: ""
error-on-conflict:
description: Whether to error if a release for the same version has already been uploaded.
required: false
default: 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.
flakehub-push-branch:
Expand Down Expand Up @@ -113,6 +118,7 @@ runs:
FLAKEHUB_PUSH_EXTRA_LABELS: ${{ inputs.extra-labels }}
FLAKEHUB_PUSH_EXTRA_TAGS: ${{ inputs.extra-tags }}
FLAKEHUB_PUSH_SPDX_EXPRESSION: ${{ inputs.spdx-expression }}
FLAKEHUB_PUSH_ERROR_ON_CONFLICT: ${{ inputs.error-on-conflict }}
# 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
23 changes: 20 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_ROLLING_PREFIX: &str = "0.1";

#[derive(Debug, clap::Parser)]
#[clap(version)]
pub(crate) struct NixfrPushCli {
pub(crate) struct FlakeHubPushCli {
#[clap(
long,
env = "FLAKEHUB_PUSH_HOST",
Expand Down Expand Up @@ -91,6 +91,14 @@ pub(crate) struct NixfrPushCli {
)]
pub(crate) spdx_expression: OptionSpdxExpression,

#[clap(
long,
env = "FLAKEHUB_PUSH_ERROR_ON_CONFLICT",
value_parser = EmptyBoolParser,
default_value_t = false
)]
pub(crate) error_on_conflict: bool,

#[clap(flatten)]
pub instrumentation: instrumentation::Instrumentation,
}
Expand Down Expand Up @@ -242,7 +250,7 @@ fn build_http_client() -> reqwest::ClientBuilder {
reqwest::Client::builder().user_agent("flakehub-push")
}

impl NixfrPushCli {
impl FlakeHubPushCli {
#[tracing::instrument(
name = "flakehub_push"
skip_all,
Expand All @@ -266,6 +274,7 @@ impl NixfrPushCli {
extra_labels,
spdx_expression,
extra_tags,
error_on_conflict,
} = self;

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

Expand Down Expand Up @@ -489,6 +499,7 @@ async fn push_new_release(
github_graphql_data_result: GithubGraphqlDataResult,
extra_labels: Vec<String>,
spdx_expression: Option<spdx::Expression>,
error_if_release_conflicts: bool,
) -> color_eyre::Result<()> {
let span = tracing::Span::current();
span.record("upload_name", tracing::field::display(upload_name.clone()));
Expand Down Expand Up @@ -675,7 +686,13 @@ async fn push_new_release(
"Release for revision `{revision}` of {upload_name}/{rolling_prefix_or_tag} already exists; flakehub-push will not upload it again",
revision = release_metadata.revision
);
return Ok(());
if error_if_release_conflicts {
return Err(color_eyre::eyre::eyre!(
"{upload_name}/{rolling_prefix_or_tag} already exists"
));
} else {
return Ok(());
}
} else {
return Err(eyre!(
"\
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> color_eyre::Result<std::process::ExitCode> {
})
.install()?;

let cli = cli::NixfrPushCli::parse();
let cli = cli::FlakeHubPushCli::parse();
cli.instrumentation.setup()?;
cli.execute().await
}
Expand Down