Have build script modify .env file
This commit is contained in:
parent
de5816a44a
commit
60bec5592a
2 changed files with 19 additions and 3 deletions
2
.github/workflows/build_and_test.yml
vendored
2
.github/workflows/build_and_test.yml
vendored
|
@ -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
|
||||||
|
|
20
build.rs
20
build.rs
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue