Skip to content

Commit

Permalink
Merge pull request #24 from fluentci-io/feat/with-env-variable
Browse files Browse the repository at this point in the history
feat: add withEnvVariable query
  • Loading branch information
tsirysndr authored Apr 28, 2024
2 parents f17b900 + 0345e10 commit e8567de
Show file tree
Hide file tree
Showing 39 changed files with 830 additions and 57 deletions.
Binary file added .github/assets/baselime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
set-safe-directory: false
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,5 @@ FluentCI Engine supports OpenTelemetry tracing. To enable it, set the `OTEL_EXPO
## 📑 Logging

FluentCI Engine supports sending logs to [Baselime](https://baselime.io). To enable it, set the `BASELIME_API_KEY` environment variable to the desired API key.

![baselime](./.github/assets/baselime.png)
8 changes: 4 additions & 4 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ license = "MPL-2.0"
name = "fluentci-engine"
readme = "../../README.md"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.0"
version = "0.3.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
clap = "3.2.20"
extism = "1.2.0"
fluentci-core = {path = "../core", version = "0.2.0"}
fluentci-core = {path = "../core", version = "0.2.1"}
fluentci-ext = {path = "../ext", version = "0.2.0"}
fluentci-server = {path = "../server", version = "0.2.0"}
fluentci-shared = {path = "../shared", version = "0.1.8"}
fluentci-server = {path = "../server", version = "0.2.1"}
fluentci-shared = {path = "../shared", version = "0.1.9"}
get-port = "4.0.0"
md5 = "0.7.0"
regex = "1.10.3"
Expand Down
4 changes: 2 additions & 2 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-common"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.1.7"
version = "0.1.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
dirs = "5.0.1"
fluentci-core = {path = "../core", version = "0.2.0"}
fluentci-core = {path = "../core", version = "0.2.1"}
fluentci-ext = {path = "../ext", version = "0.2.0"}
fluentci-types = {path = "../types", version = "0.1.6"}
regex = "1.10.4"
Expand Down
6 changes: 6 additions & 0 deletions crates/common/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,9 @@ pub fn with_service(graph: Arc<Mutex<Graph>>, service_id: String) -> Result<(),
None => Err(Error::msg("Service not found")),
}
}

pub fn with_env_variable(graph: Arc<Mutex<Graph>>, key: &str, value: &str) -> Result<(), Error> {
let mut graph = graph.lock().unwrap();
graph.execute(GraphCommand::AddEnvVariable(key.into(), value.into()));
Ok(())
}
2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-core"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.0"
version = "0.2.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
9 changes: 8 additions & 1 deletion crates/core/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use opentelemetry::{
Context, KeyValue,
};
use owo_colors::OwoColorize;
use std::env::current_dir;
use std::env::{self, current_dir};
use std::sync::mpsc::{self, Sender};
use std::sync::Arc;
use std::{path::Path, thread};
Expand Down Expand Up @@ -63,6 +63,7 @@ pub enum GraphCommand {
Vec<String>,
Arc<Box<dyn Extension + Send + Sync>>,
),
AddEnvVariable(String, String),
EnableService(String),
AddEdge(usize, usize),
Execute(Output),
Expand Down Expand Up @@ -227,6 +228,9 @@ impl Graph {
GraphCommand::AddEdge(from, to) => {
self.edges.push(Edge { from, to });
}
GraphCommand::AddEnvVariable(key, value) => {
env::set_var(key, value);
}
GraphCommand::Execute(Output::Stdout) => {
self.execute_graph(Output::Stdout);
}
Expand All @@ -241,6 +245,9 @@ impl Graph {
}

pub fn execute_services(&mut self, ctx: &Context) -> Result<(), Error> {
if self.enabled_services.is_empty() {
return Ok(());
}
let tracer_provider = global::tracer_provider();
let tracer = tracer_provider.versioned_tracer(
"fluentci-core",
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn set_git_repo_metadata() -> Result<(), Error> {
let child = Command::new("sh")
.arg("-c")
.arg("git log -1 --pretty=%h")
.stdout(std::process::Stdio::piped())
.spawn()?;
let output = child.wait_with_output()?;
let commit_hash = String::from_utf8(output.stdout)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-graphql"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.0"
version = "0.2.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -16,8 +16,8 @@ anyhow = "1.0.80"
async-graphql = "7.0.2"
async-graphql-actix-web = "7.0.2"
dirs = "5.0.1"
fluentci-common = {path = "../common", version = "0.1.7"}
fluentci-core = {path = "../core", version = "0.2.0"}
fluentci-common = {path = "../common", version = "0.1.8"}
fluentci-core = {path = "../core", version = "0.2.1"}
fluentci-ext = {path = "../ext", version = "0.2.0"}
fluentci-types = {path = "../types", version = "0.1.6"}
regex = "1.10.3"
Expand Down
11 changes: 11 additions & 0 deletions crates/graphql/src/schema/objects/devbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ impl Devbox {
let service = common::as_service(graph.clone(), name)?;
Ok(service.into())
}

async fn with_env_variable(
&self,
ctx: &Context<'_>,
name: String,
value: String,
) -> Result<&Devbox, Error> {
let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
common::with_env_variable(graph.clone(), &name, &value)?;
Ok(self)
}
}

impl From<types::Devbox> for Devbox {
Expand Down
11 changes: 11 additions & 0 deletions crates/graphql/src/schema/objects/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ impl Devenv {
let service = common::as_service(graph.clone(), name)?;
Ok(service.into())
}

async fn with_env_variable(
&self,
ctx: &Context<'_>,
name: String,
value: String,
) -> Result<&Devenv, Error> {
let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
common::with_env_variable(graph.clone(), &name, &value)?;
Ok(self)
}
}

impl From<types::Devenv> for Devenv {
Expand Down
11 changes: 11 additions & 0 deletions crates/graphql/src/schema/objects/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ impl Directory {
let service = common::as_service(graph.clone(), name)?;
Ok(service.into())
}

async fn with_env_variable(
&self,
ctx: &Context<'_>,
name: String,
value: String,
) -> Result<&Directory, Error> {
let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
common::with_env_variable(graph.clone(), &name, &value)?;
Ok(self)
}
}

impl From<types::Directory> for Directory {
Expand Down
11 changes: 11 additions & 0 deletions crates/graphql/src/schema/objects/envhub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ impl Envhub {
let service = common::as_service(graph.clone(), name)?;
Ok(service.into())
}

async fn with_env_variable(
&self,
ctx: &Context<'_>,
name: String,
value: String,
) -> Result<&Envhub, Error> {
let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
common::with_env_variable(graph.clone(), &name, &value)?;
Ok(self)
}
}

impl From<types::Envhub> for Envhub {
Expand Down
Loading

0 comments on commit e8567de

Please sign in to comment.