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

extra-tags -> extra-labels #68

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
664 changes: 299 additions & 365 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ base64 = "0.21.2"
tracing = { version = "0.1.36", default-features = false, features = [ "std", "attributes" ] }
tracing-error = { version = "0.2.0", default-features = false, features = ["traced-error"] }
tracing-subscriber = { version = "0.3.15", default-features = false, features = [ "std", "registry", "fmt", "json", "ansi", "env-filter" ] }
atty = { version = "0.2.14", default-features = false }
github-actions-oidc-claims = "0.3.0"
spdx = "0.10.2"
uuid = { version = "1.4.0", features = ["serde", "v7", "rand", "std"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Parameter | Description | Type | Required? | Default
`rolling` | For untagged releases, use a rolling versioning scheme. When this is enabled, the default versioning scheme is 0.1.[commit count]+rev-[git sha]. To customize the SemVer minor version, set the `rolling-minor` option. | Boolean | | `false`
`rolling-minor` | Specify the SemVer minor version of your rolling releases. All releases will follow the versioning scheme '0.[rolling-minor].[commit count]+rev-[git sha]' | string | |
`git-root` | The root directory of your Git repository. | relative path | | `.`
`extra-tags` | `flakehub-push` automatically uses the GitHub repo's topics as tags. This `extra-tags` parameter enables you to add extra tags beyond that as a comma-separated string. Only alphanumeric characters and hyphens are allowed in tags and the maximum length of tags is 50 characters. You can specify a maximum of 20 extra tags, and have a maximum of 25 tags, including those that we retrieve from GitHub. Any tags after the 25th will be ignored. | string | | `""`
`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 | | `""`
`github-token` | The GitHub token for making authenticated GitHub API requests. | `${{ github.token }}`
`host` | The FlakeHub server to use | URL | | `https://api.flakehub.com`
Expand Down
7 changes: 6 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ inputs:
description: A GitHub token for making authenticated GitHub API requests.
default: ${{ github.token }}
extra-tags:
description: "DEPRECATED: Please use `extra-labels` instead."
required: false
default: ""
extra-labels:
description: |
`flakehub-push` automatically uses the GitHub repo's topics as tags. This `extra-tags` parameter enables you to add extra tags beyond that as a comma-separated string. Only alphanumeric characters and hyphens are allowed in tags and the maximum length of tags is 50 characters. You can specify a maximum of 20 extra tags, and have a maximum of 25 tags, including those that we retrieve from GitHub. Any tags after the 25th will be ignored.
`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.
required: false
default: ""
spdx-expression:
Expand Down Expand Up @@ -106,6 +110,7 @@ runs:
FLAKEHUB_PUSH_REPOSITORY: ${{ inputs.repository }}
FLAKEHUB_PUSH_DIRECTORY: ${{ inputs.directory }}
FLAKEHUB_PUSH_GIT_ROOT: ${{ inputs.git-root }}
FLAKEHUB_PUSH_EXTRA_LABELS: ${{ inputs.extra-labels }}
FLAKEHUB_PUSH_EXTRA_TAGS: ${{ inputs.extra-tags }}
FLAKEHUB_PUSH_SPDX_EXPRESSION: ${{ inputs.spdx-expression }}
# Also GITHUB_REPOSITORY, GITHUB_REF_NAME, GITHUB_TOKEN, ACTIONS_ID_TOKEN_REQUEST_TOKEN, ACTIONS_ID_TOKEN_REQUEST_URL
Expand Down
11 changes: 5 additions & 6 deletions src/cli/instrumentation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use atty::Stream;
use color_eyre::eyre::WrapErr;
use std::error::Error;
use std::{error::Error, io::IsTerminal};
use tracing_error::ErrorLayer;
use tracing_subscriber::{
filter::Directive, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter,
Expand Down Expand Up @@ -86,7 +85,7 @@ impl<'a> Instrumentation {
S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{
tracing_subscriber::fmt::Layer::new()
.with_ansi(atty::is(Stream::Stderr))
.with_ansi(std::io::stderr().is_terminal())
.with_writer(std::io::stderr)
}

Expand All @@ -95,7 +94,7 @@ impl<'a> Instrumentation {
S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{
tracing_subscriber::fmt::Layer::new()
.with_ansi(atty::is(Stream::Stderr))
.with_ansi(std::io::stderr().is_terminal())
.with_writer(std::io::stderr)
.pretty()
}
Expand All @@ -105,7 +104,7 @@ impl<'a> Instrumentation {
S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{
tracing_subscriber::fmt::Layer::new()
.with_ansi(atty::is(Stream::Stderr))
.with_ansi(std::io::stderr().is_terminal())
.with_writer(std::io::stderr)
.json()
}
Expand All @@ -115,7 +114,7 @@ impl<'a> Instrumentation {
S: tracing::Subscriber + for<'span> tracing_subscriber::registry::LookupSpan<'span>,
{
tracing_subscriber::fmt::Layer::new()
.with_ansi(atty::is(Stream::Stderr))
.with_ansi(std::io::stderr().is_terminal())
.with_writer(std::io::stderr)
.compact()
.without_time()
Expand Down
24 changes: 19 additions & 5 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ pub(crate) struct NixfrPushCli {
#[clap(long, env = "FLAKEHUB_PUSH_JWT_ISSUER_URI", value_parser = StringToNoneParser, default_value = "")]
pub(crate) jwt_issuer_uri: OptionString,

/// User-supplied tags beyond those associated with the GitHub repository.
/// User-supplied labels beyond those associated with the GitHub repository.
#[clap(
long,
short = 'l',
env = "FLAKEHUB_PUSH_EXTRA_LABELS",
use_value_delimiter = true,
default_value = "",
value_delimiter = ','
)]
pub(crate) extra_labels: Vec<String>,

/// DEPRECATED: Please use `extra-labels` instead.
#[clap(
long,
short = 't',
Expand Down Expand Up @@ -254,10 +265,13 @@ impl NixfrPushCli {
mirror,
jwt_issuer_uri,
instrumentation: _,
extra_tags,
mut extra_labels,
spdx_expression,
extra_tags,
} = self;

extra_labels.extend(extra_tags);
cole-h marked this conversation as resolved.
Show resolved Hide resolved

let github_token = if let Some(github_token) = &github_token.0 {
github_token.clone()
} else {
Expand Down Expand Up @@ -417,7 +431,7 @@ impl NixfrPushCli {
rolling,
rolling_minor.0,
github_graphql_data_result,
extra_tags,
extra_labels,
spdx_expression.0,
)
.await?;
Expand Down Expand Up @@ -452,7 +466,7 @@ async fn push_new_release(
rolling: bool,
rolling_minor: Option<u64>,
github_graphql_data_result: GithubGraphqlDataResult,
extra_tags: Vec<String>,
extra_labels: Vec<String>,
spdx_expression: Option<spdx::Expression>,
) -> color_eyre::Result<()> {
let span = tracing::Span::current();
Expand Down Expand Up @@ -565,7 +579,7 @@ async fn push_new_release(
mirror,
visibility,
github_graphql_data_result,
extra_tags,
extra_labels,
spdx_expression,
)
.await
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use color_eyre::eyre::{eyre, WrapErr};
use graphql_client::GraphQLQuery;

pub(crate) const GITHUB_ENDPOINT: &str = "https://api.github.com/graphql";
pub(crate) const MAX_TAG_LENGTH: usize = 50;
pub(crate) const MAX_NUM_TOTAL_TAGS: usize = 25;
pub(crate) const MAX_LABEL_LENGTH: usize = 50;
pub(crate) const MAX_NUM_TOTAL_LABELS: usize = 25;
const MAX_NUM_EXTRA_TOPICS: i64 = 20;

#[derive(GraphQLQuery)]
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, io::IsTerminal};

use clap::Parser;
mod cli;
Expand All @@ -13,7 +13,7 @@ async fn main() -> color_eyre::Result<std::process::ExitCode> {
.add_issue_metadata("version", env!("CARGO_PKG_VERSION"))
.add_issue_metadata("os", std::env::consts::OS)
.add_issue_metadata("arch", std::env::consts::ARCH)
.theme(if !atty::is(atty::Stream::Stderr) {
.theme(if !std::io::stderr().is_terminal() {
color_eyre::config::Theme::new()
} else {
color_eyre::config::Theme::dark()
Expand Down
20 changes: 10 additions & 10 deletions src/release_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use color_eyre::eyre::{eyre, WrapErr};
use std::{collections::HashSet, path::Path};

use crate::{
graphql::{GithubGraphqlDataResult, MAX_NUM_TOTAL_TAGS, MAX_TAG_LENGTH},
graphql::{GithubGraphqlDataResult, MAX_LABEL_LENGTH, MAX_NUM_TOTAL_LABELS},
Visibility,
};

Expand All @@ -27,9 +27,9 @@ pub(crate) struct ReleaseMetadata {
)]
pub(crate) spdx_identifier: Option<spdx::Expression>,

// A result of combining the tags specified on the CLI via the the GitHub Actions config
// and the tags associated with the GitHub repo (they're called "topics" in GitHub parlance).
pub(crate) tags: Vec<String>,
// A result of combining the labels specified on the CLI via the the GitHub Actions config
// and the labels associated with the GitHub repo (they're called "topics" in GitHub parlance).
pub(crate) labels: Vec<String>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -104,7 +104,7 @@ impl ReleaseMetadata {
mirror: bool,
visibility: Visibility,
github_graphql_data_result: GithubGraphqlDataResult,
extra_tags: Vec<String>,
extra_labels: Vec<String>,
spdx_expression: Option<spdx::Expression>,
) -> color_eyre::Result<ReleaseMetadata> {
let span = tracing::Span::current();
Expand Down Expand Up @@ -155,19 +155,19 @@ impl ReleaseMetadata {

tracing::trace!("Collected ReleaseMetadata information");

// Here we merge explicitly user-supplied tags and the tags ("topics")
// 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 tags: Vec<String> = extra_tags
let labels: Vec<String> = extra_labels
.into_iter()
.chain(github_graphql_data_result.topics.into_iter())
.collect::<HashSet<String>>()
.into_iter()
.take(MAX_NUM_TOTAL_TAGS)
.take(MAX_NUM_TOTAL_LABELS)
.map(|s| s.trim().to_lowercase())
.filter(|t: &String| {
!t.is_empty()
&& t.len() <= MAX_TAG_LENGTH
&& t.len() <= MAX_LABEL_LENGTH
&& t.chars().all(|c| c.is_alphanumeric() || c == '-')
})
.collect();
Expand All @@ -191,7 +191,7 @@ impl ReleaseMetadata {
spdx_identifier,
project_id: github_graphql_data_result.project_id,
owner_id: github_graphql_data_result.owner_id,
tags,
labels,
})
}
}
Expand Down