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
10 changes: 7 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pgt_console = { path = "./crates/pgt_console", version = "0.0.0"
pgt_diagnostics = { path = "./crates/pgt_diagnostics", version = "0.0.0" }
pgt_diagnostics_categories = { path = "./crates/pgt_diagnostics_categories", version = "0.0.0" }
pgt_diagnostics_macros = { path = "./crates/pgt_diagnostics_macros", version = "0.0.0" }
pgt_flags = { path = "./crates/pgt_flags", version = "0.0.0" }
pgt_env = { path = "./crates/pgt_env", version = "0.0.0" }
pgt_fs = { path = "./crates/pgt_fs", version = "0.0.0" }
pgt_hover = { path = "./crates/pgt_hover", version = "0.0.0" }
pgt_lexer = { path = "./crates/pgt_lexer", version = "0.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pgt_analyse = { workspace = true }
pgt_configuration = { workspace = true }
pgt_console = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_flags = { workspace = true }
pgt_env = { workspace = true }
pgt_fs = { workspace = true }
pgt_lsp = { workspace = true }
pgt_text_edit = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::commands::daemon::default_pgt_log_path;
use crate::{CliDiagnostic, CliSession};
use pgt_flags::pgt_env;
use pgt_env::pgt_env;
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

Expand Down
6 changes: 1 addition & 5 deletions crates/pgt_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use commands::check::CheckCommandPayload;
use pgt_console::{ColorMode, Console};
use pgt_fs::OsFileSystem;
use pgt_workspace::{App, DynRef, Workspace, WorkspaceRef};
use std::env;

mod changed;
mod cli_options;
Expand All @@ -32,10 +31,7 @@ pub use panic::setup_panic_handler;
pub use reporter::{DiagnosticsPayload, Reporter, ReporterVisitor, TraversalSummary};
pub use service::{SocketTransport, open_transport};

pub(crate) const VERSION: &str = match option_env!("PGT_VERSION") {
Some(version) => version,
None => env!("CARGO_PKG_VERSION"),
};
pub(crate) use pgt_env::VERSION;

/// Global context for an execution of the CLI
pub struct CliSession<'app> {
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pgt_analyse = { workspace = true }
pgt_analyser = { workspace = true }
pgt_console = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_env = { workspace = true }
pgt_text_size = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, features = ["indexmap1"], optional = true }
Expand Down
11 changes: 4 additions & 7 deletions crates/pgt_configuration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This module contains the configuration of `postgrestools.jsonc`
//!
//! The configuration is divided by "tool", and then it's possible to further customise it
//! by language. The language might further options divided by tool.
//! The configuration is divided by "tool".

pub mod analyser;
pub mod database;
Expand Down Expand Up @@ -34,6 +33,7 @@ use files::{FilesConfiguration, PartialFilesConfiguration, partial_files_configu
use migrations::{
MigrationsConfiguration, PartialMigrationsConfiguration, partial_migrations_configuration,
};
use pgt_env::PGT_WEBSITE;
use plpgsql_check::{
PartialPlPgSqlCheckConfiguration, PlPgSqlCheckConfiguration,
partial_pl_pg_sql_check_configuration,
Expand All @@ -44,10 +44,7 @@ pub use typecheck::{
};
use vcs::VcsClientKind;

pub const VERSION: &str = match option_env!("PGT_VERSION") {
Some(version) => version,
None => "0.0.0",
};
pub use pgt_env::VERSION;

/// The configuration that is contained inside the configuration file.
#[derive(Clone, Debug, Default, Deserialize, Eq, Partial, PartialEq, Serialize)]
Expand Down Expand Up @@ -106,7 +103,7 @@ impl PartialConfiguration {
/// Returns the initial configuration.
pub fn init() -> Self {
Self {
schema: Some(format!("https://pgtools.dev/schemas/{VERSION}/schema.json")),
schema: Some(format!("{}/schemas/{VERSION}/schema.json", PGT_WEBSITE)),
extends: Some(StringSet::default()),
files: Some(PartialFilesConfiguration {
ignore: Some(Default::default()),
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_diagnostics_categories/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.0.0"


[dependencies]
pgt_env = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }

Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_flags/Cargo.toml → crates/pgt_env/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
authors.workspace = true
categories.workspace = true
description = "<DESCRIPTION>"
description = "Environment variables and configuration for Postgres Tools"
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
name = "pgt_flags"
name = "pgt_env"
repository.workspace = true
version = "0.0.0"

Expand Down
21 changes: 18 additions & 3 deletions crates/pgt_flags/src/lib.rs → crates/pgt_env/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
//! A simple implementation of feature flags.
//! Environment variables and configuration constants for Postgres Tools.
//!
//! This module provides:
//! - Environment variable definitions for runtime configuration
//! - Static constants like version information and website URL
//! - Helper functions for checking build status

use pgt_console::fmt::{Display, Formatter};
use pgt_console::{DebugDisplay, KeyValuePair, markup};
use std::env;
use std::ops::Deref;
use std::sync::{LazyLock, OnceLock};

/// Returns `true` if this is an unstable build of Postgres Tools
pub fn is_unstable() -> bool {
PGT_VERSION.deref().is_none()
VERSION == "0.0.0"
}

/// The internal version of Postgres Tools. This is usually supplied during the CI build
pub static PGT_VERSION: LazyLock<Option<&str>> = LazyLock::new(|| option_env!("PGT_VERSION"));

/// The version of Postgres Tools with fallback logic
pub const VERSION: &str = match option_env!("PGT_VERSION") {
Some(version) => version,
None => match option_env!("CARGO_PKG_VERSION") {
Some(pkg_version) => pkg_version,
None => "0.0.0",
},
};

pub static PGT_WEBSITE: &str = "https://pgtools.dev";

pub struct PgTEnv {
pub pgt_log_path: PgTEnvVariable,
pub pgt_log_prefix: PgTEnvVariable,
Expand Down
1 change: 1 addition & 0 deletions crates/pgt_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pgt_completions = { workspace = true }
pgt_configuration = { workspace = true }
pgt_console = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_env = { workspace = true }
pgt_fs = { workspace = true, features = ["serde"] }
pgt_hover = { workspace = true }
pgt_lexer = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/pgt_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pgt_configuration::{
VERSION, diagnostics::CantLoadExtendFile, push_to_analyser_rules,
};
use pgt_console::markup;
use pgt_env::PGT_WEBSITE;
use pgt_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions};

use crate::{DynRef, WorkspaceError, settings::Settings};
Expand Down Expand Up @@ -186,9 +187,9 @@ pub fn create_config(
configuration.schema = node_schema_path.to_str().map(String::from);
} else if VERSION == "0.0.0" {
// VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback)
configuration.schema = Some("https://pgtools.dev/latest/schema.json".to_string());
configuration.schema = Some(format!("{}/latest/schema.json", PGT_WEBSITE));
} else {
configuration.schema = Some(format!("https://pgtools.dev/{VERSION}/schema.json"));
configuration.schema = Some(format!("{}/{VERSION}/schema.json", PGT_WEBSITE));
}

let contents = serde_json::to_string_pretty(&configuration)
Expand Down
2 changes: 1 addition & 1 deletion docs/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde_json = { workspace = true }
pulldown-cmark = "0.12.2"

pgt_configuration = { workspace = true, features = ["schema"] }
pgt_flags = { workspace = true }
pgt_env = { workspace = true }
pgt_cli = { workspace = true }
pgt_analyse = { workspace = true }
pgt_analyser = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion docs/codegen/src/env_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn generate_env_variables(docs_dir: &Path) -> Result<()> {

let mut content = vec![];

let env = pgt_flags::pgt_env();
let env = pgt_env::pgt_env();

writeln!(content, "\n",)?;

Expand Down
1 change: 1 addition & 0 deletions xtask/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bpaf = { workspace = true, features = ["derive"] }
pgt_analyse = { workspace = true }
pgt_analyser = { workspace = true }
pgt_diagnostics = { workspace = true }
pgt_env = { workspace = true }
pgt_workspace = { workspace = true, features = ["schema"] }
proc-macro2 = { workspace = true, features = ["span-locations"] }
pulldown-cmark = { version = "0.12.2" }
Expand Down
4 changes: 3 additions & 1 deletion xtask/codegen/src/generate_new_analyser_rule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use biome_string_case::Case;
use bpaf::Bpaf;
use pgt_diagnostics::Severity;
use pgt_env::PGT_WEBSITE;
use std::str::FromStr;
use xtask::project_root;

Expand Down Expand Up @@ -128,7 +129,8 @@ pub fn generate_new_analyser_rule(
// We sort rules to reduce conflicts between contributions made in parallel.
let rule_line = match category {
Category::Lint => format!(
r#" "lint/{group}/{rule_name_camel}": "https://pgtools.dev/latest/rules/{kebab_case_rule}","#
r#" "lint/{group}/{rule_name_camel}": "{}/latest/rules/{kebab_case_rule}","#,
PGT_WEBSITE
),
};
let lint_start = match category {
Expand Down