Remove unnecessary determine func
This commit is contained in:
parent
41327e96b5
commit
8ad3089e93
|
@ -11,6 +11,18 @@ pub enum Environment {
|
|||
}
|
||||
|
||||
impl Environment {
|
||||
pub fn determine() -> Self {
|
||||
if env_var_is_true("GITHUB_ACTIONS") {
|
||||
return Environment::GitHubActions;
|
||||
}
|
||||
|
||||
if env_var_is_true("CI") && env_var_is_true("GITLAB_CI") {
|
||||
return Environment::GitLabCI;
|
||||
}
|
||||
|
||||
Environment::Other
|
||||
}
|
||||
|
||||
pub fn is_github_actions(&self) -> bool {
|
||||
matches!(self, Self::GitHubActions)
|
||||
}
|
||||
|
@ -36,18 +48,6 @@ impl Display for Environment {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn determine_environment() -> Environment {
|
||||
if env_var_is_true("GITHUB_ACTIONS") {
|
||||
return Environment::GitHubActions;
|
||||
}
|
||||
|
||||
if env_var_is_true("CI") && env_var_is_true("GITLAB_CI") {
|
||||
return Environment::GitLabCI;
|
||||
}
|
||||
|
||||
Environment::Other
|
||||
}
|
||||
|
||||
fn env_var_is_true(e: &str) -> bool {
|
||||
&env::var(e).unwrap_or(String::from("")) == "true"
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@ use ::attic::nix_store::NixStore;
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use axum::{extract::Extension, routing::get, Router};
|
||||
use clap::Parser;
|
||||
use env::Environment;
|
||||
use error::Error;
|
||||
use tempfile::NamedTempFile;
|
||||
use tokio::process::Command;
|
||||
use tokio::sync::{oneshot, Mutex, RwLock};
|
||||
|
@ -41,8 +39,6 @@ use tracing_subscriber::filter::EnvFilter;
|
|||
|
||||
use gha_cache::Credentials;
|
||||
|
||||
use crate::env::determine_environment;
|
||||
|
||||
type State = Arc<StateInner>;
|
||||
|
||||
/// GitHub Actions-powered Nix binary cache
|
||||
|
@ -118,15 +114,15 @@ struct Args {
|
|||
}
|
||||
|
||||
impl Args {
|
||||
fn validate(&self, environment: Environment) -> Result<(), error::Error> {
|
||||
fn validate(&self, environment: env::Environment) -> Result<(), error::Error> {
|
||||
if environment.is_gitlab_ci() && self.use_gha_cache {
|
||||
return Err(Error::Config(String::from(
|
||||
return Err(error::Error::Config(String::from(
|
||||
"the --use-gha-cache flag should not be applied in GitLab CI",
|
||||
)));
|
||||
}
|
||||
|
||||
if environment.is_gitlab_ci() && !self.use_flakehub {
|
||||
return Err(Error::Config(String::from(
|
||||
return Err(error::Error::Config(String::from(
|
||||
"you must set --use-flakehub in GitLab CI",
|
||||
)));
|
||||
}
|
||||
|
@ -163,7 +159,7 @@ async fn main_cli() -> Result<()> {
|
|||
init_logging();
|
||||
|
||||
let args = Args::parse();
|
||||
let environment = determine_environment();
|
||||
let environment = env::Environment::determine();
|
||||
tracing::debug!("Running in {}", environment.to_string());
|
||||
args.validate(environment.clone())?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue