From 60bec5592ac93de525800d1b2d51f6d977644fa8 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Fri, 9 Jul 2021 20:37:15 -0400 Subject: [PATCH] Have build script modify .env file --- .github/workflows/build_and_test.yml | 2 -- build.rs | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index a486301..a1fe685 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -16,8 +16,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set env - run: echo "DATABASE_URL=sqlite:./cache/metadata.sqlite" >> $GITHUB_ENV - name: Build run: cargo build --verbose - name: Run tests diff --git a/build.rs b/build.rs index f7069f7..dc485ae 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,7 @@ -use std::error::Error; +use std::path::PathBuf; use std::process::Command; +use std::str::FromStr; +use std::{error::Error, io::Write}; use vergen::{vergen, Config, ShaKind}; @@ -21,5 +23,21 @@ fn main() -> Result<(), Box> { .current_dir(&project_root) .output()?; + let env_var_regex = "^DATABASE_URL=sqlite:./cache/metadata.sqlite$"; + if !Command::new("grep") + .args([env_var_regex, ".env"]) + .current_dir(&project_root) + .output()? + .status + .success() + { + let mut path = PathBuf::from_str(&project_root)?; + path.push(".env"); + + let mut file = std::fs::OpenOptions::new().append(true).open(path)?; + file.write_all(b"\nDATABASE_URL=sqlite:./cache/metadata.sqlite\n")?; + file.sync_all()?; + } + Ok(()) }