Have build script modify .env file

This commit is contained in:
Edward Shen 2021-07-09 20:37:15 -04:00
parent de5816a44a
commit 60bec5592a
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 19 additions and 3 deletions

View file

@ -16,8 +16,6 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set env
run: echo "DATABASE_URL=sqlite:./cache/metadata.sqlite" >> $GITHUB_ENV
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
- name: Run tests - name: Run tests

View file

@ -1,5 +1,7 @@
use std::error::Error; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::str::FromStr;
use std::{error::Error, io::Write};
use vergen::{vergen, Config, ShaKind}; use vergen::{vergen, Config, ShaKind};
@ -21,5 +23,21 @@ fn main() -> Result<(), Box<dyn Error>> {
.current_dir(&project_root) .current_dir(&project_root)
.output()?; .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(()) Ok(())
} }