Skip to content

Commit

Permalink
fix(ci): add sanity check to build.rs scripts, fixed "detected dubiou…
Browse files Browse the repository at this point in the history
…s ownership in repository" errors on `git` (#4986)

* feat: add sanity check to build.rs scripts on crates compiled natively

* fix(ci): fix build on linux-musl and linux-static architectures

* chore: trigger [integration]

* chore: trigger [integration], allow COLLABORATOR roles
  • Loading branch information
jkomyno authored Aug 26, 2024
1 parent de1356e commit 5fe2181
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-engines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'CONTRIBUTOR' ||
github.event.pull_request.author_association == 'COLLABORATOR'
)
run: |
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/utils/constructDockerBuildCommand.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#!/bin/bash
set -eux;

# full command
DOCKER_WORKSPACE="/root/build"

# Full command, Docker + Bash.
# In Bash, we use `git config` to avoid "fatal: detected dubious ownership in repository at /root/build" panic messages
# that can occur when Prisma Engines' `build.rs` scripts run `git rev-parse HEAD` to extract the current commit hash.
# See: https://www.kenmuse.com/blog/avoiding-dubious-ownership-in-dev-containers/.
command="docker run \
-e SQLITE_MAX_VARIABLE_NUMBER=250000 \
-e SQLITE_MAX_EXPR_DEPTH=10000 \
-e LIBZ_SYS_STATIC=1 \
-w /root/build \
-v \"$(pwd)\":/root/build \
-w ${DOCKER_WORKSPACE} \
-v \"$(pwd)\":${DOCKER_WORKSPACE} \
-v \"$HOME\"/.cargo/bin:/root/cargo/bin \
-v \"$HOME\"/.cargo/registry/index:/root/cargo/registry/index \
-v \"$HOME\"/.cargo/registry/cache:/root/cargo/registry/cache \
-v \"$HOME\"/.cargo/git/db:/root/cargo/git/db \
$IMAGE \
bash -c \
\" \
cargo clean \
git config --global --add safe.directory ${DOCKER_WORKSPACE} \
&& cargo clean \
&& cargo build --release -p query-engine --manifest-path query-engine/query-engine/Cargo.toml $TARGET_STRING $FEATURES_STRING \
&& cargo build --release -p query-engine-node-api --manifest-path query-engine/query-engine-node-api/Cargo.toml $TARGET_STRING $FEATURES_STRING \
&& cargo build --release -p schema-engine-cli --manifest-path schema-engine/cli/Cargo.toml $TARGET_STRING $FEATURES_STRING \
Expand Down
10 changes: 10 additions & 0 deletions query-engine/query-engine-node-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
Expand Down
10 changes: 10 additions & 0 deletions query-engine/query-engine/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
Expand Down
10 changes: 10 additions & 0 deletions schema-engine/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ use std::process::Command;

fn store_git_commit_hash() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();

// Sanity check on the output.
if !output.status.success() {
panic!(
"Failed to get git commit hash.\nstderr: \n{}\nstdout {}\n",
String::from_utf8(output.stderr).unwrap_or_default(),
String::from_utf8(output.stdout).unwrap_or_default(),
);
}

let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={git_hash}");
}
Expand Down

0 comments on commit 5fe2181

Please sign in to comment.