Skip to content

Commit 9118e2f

Browse files
committed
Auto merge of #1773 - smarnach:rerun-build-script, r=sgrif
Rerun the build script if `.env` has been changed. Edits to `.env` may alter the value of the `TEST_DATABASE_URL` environment variable, so we should rerun the build script if `.env` was changed. The build script is already configured to be rerun when the value of `TEST_DATABASE_URL` changes, but the current setup does not capture changes performed via `.env`, since the environment file is only loaded at runtime of the build script. This change also removes the redundant `cargo:rerun-if-changed=build.rs`; the build script is always rerun if it is changed.
2 parents 60019d9 + 2653c12 commit 9118e2f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use diesel::prelude::*;
22
use diesel_migrations::run_pending_migrations;
3-
use dotenv::dotenv;
43
use std::env;
54

65
fn main() {
76
println!("cargo:rerun-if-env-changed=TEST_DATABASE_URL");
8-
println!("cargo:rerun-if-changed=build.rs");
7+
println!("cargo:rerun-if-changed=.env");
98
println!("cargo:rerun-if-changed=migrations/");
109
if env::var("PROFILE") == Ok("debug".into()) {
11-
let _ = dotenv();
12-
if let Ok(database_url) = env::var("TEST_DATABASE_URL") {
10+
if let Ok(database_url) = dotenv::var("TEST_DATABASE_URL") {
1311
let connection = PgConnection::establish(&database_url)
1412
.expect("Could not connect to TEST_DATABASE_URL");
1513
run_pending_migrations(&connection).expect("Error running migrations");

0 commit comments

Comments
 (0)