Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
self-hosted-runner:
labels:
- namespace-profile-gitar
- namespace-profile-gitar-macos
7 changes: 4 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI
on:
pull_request:
branches: [main]
push:
branches:
- main
Expand Down Expand Up @@ -39,11 +40,11 @@ jobs:
- name: Rename existing rust toolchain (Windows)
if: matrix.os == 'windows-latest'
run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old

- name: Instal libssl (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install libssl-dev

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -54,7 +55,7 @@ jobs:

- name: Cache Dependencies
uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72

- name: Generate client
working-directory: integration-tests
run: cargo prisma generate
Expand Down
94 changes: 74 additions & 20 deletions .github/workflows/compatibility.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Compatibility binaries
on:
push:
branches: [gitar-0.6.11, gitar-rustls-engines]
pull_request:
branches: [gitar-0.6.11, gitar-rustls-engines]
workflow_dispatch:
permissions:
contents: read
Expand All @@ -15,12 +17,15 @@ jobs:
- target: aarch64-apple-darwin
runner: namespace-profile-gitar-macos
features: postgresql,mocking
platform: darwin
- target: x86_64-unknown-linux-gnu
runner: namespace-profile-gitar
features: postgresql,mocking
platform: linux/amd64
- target: aarch64-unknown-linux-gnu
runner: namespace-profile-gitar
features: postgresql,mocking
platform: linux/arm64
runs-on: ${{ matrix.runner }}
steps:
- uses: namespacelabs/nscloud-checkout-action@v8
Expand Down Expand Up @@ -60,27 +65,62 @@ jobs:
zip "prisma-cli-$TARGET.zip" "prisma-cli-$TARGET" source-sha.txt
- name: Test archive verification
if: matrix.target == 'aarch64-apple-darwin'
run: cargo test --locked -p prisma-client-rust-cli --no-default-features --features postgresql,mocking --lib binaries::tests
- name: Test x86 binary on Debian 12 with an empty engine cache
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: cargo test --locked -p prisma-client-rust-cli --no-default-features --features postgresql,mocking --lib binaries
- name: Check runner formatting and lints
if: matrix.target == 'aarch64-apple-darwin'
run: |
cargo fmt --check -p prisma-client-rust-cli
cargo clippy --locked -p prisma-client-rust-cli -p prisma-cli \
--no-default-features --features postgresql,mocking --all-targets
- name: Download the previous generator baseline
env:
TARGET: ${{ matrix.target }}
run: |
python3 tests/compatibility/baseline.py "$TARGET"
- name: Test macOS runner with an empty cache
if: matrix.target == 'aarch64-apple-darwin'
run: |
cp artifacts/prisma-cli-x86_64-unknown-linux-gnu tests/compatibility/prisma
docker run --rm -v "$PWD/tests/compatibility:/work" debian:bookworm-slim sh -ec '
apt-get update -qq
apt-get install -y -qq ca-certificates rustfmt
# Fail if the wrapper regresses to invoking OpenSSL for engine selection.
printf "#!/bin/sh\nexit 99\n" > /work/openssl
chmod +x /work/openssl
export PATH=/work:$PATH
export DATABASE_URL=postgresql://postgres@localhost:5432/postgres
prisma generate --schema /work/schema.prisma
test -s /work/prisma.rs
prisma --version
if prisma generate --schema /work/does-not-exist.prisma; then
echo "Invalid Prisma commands must fail"
exit 1
fi
'
python3 tests/compatibility/runner.py target/${{ matrix.target }}/release/prisma \
--baseline baseline/prisma --work-dir runner-results
- uses: docker/setup-qemu-action@v3
if: matrix.target == 'aarch64-unknown-linux-gnu'
with:
platforms: arm64
- name: Test Linux runner with disposable PostgreSQL
if: matrix.target != 'aarch64-apple-darwin'
env:
TARGET: ${{ matrix.target }}
PLATFORM: ${{ matrix.platform }}
run: |
docker network create runner-test
trap 'docker rm -f runner-db; docker network rm runner-test' EXIT
docker run -d --name runner-db --network runner-test --network-alias fixture-db \
-e POSTGRES_PASSWORD=fixture -e POSTGRES_DB=runner_fixture postgres:17
for attempt in $(seq 1 30); do
if docker exec runner-db pg_isready -U postgres; then break; fi
sleep 1
done
docker run --rm --platform "$PLATFORM" --network runner-test \
-v "$PWD:/work" -e TARGET="$TARGET" -w /work debian:bookworm-slim sh -ec '
apt-get update -qq
apt-get install -y -qq ca-certificates openssl rustfmt python3
python3 tests/compatibility/runner.py "target/$TARGET/release/prisma" \
--baseline baseline/prisma --work-dir runner-results \
--database-url postgresql://postgres:fixture@fixture-db:5432/runner_fixture
'
- uses: actions/upload-artifact@v4
if: always()
with:
name: runner-results-${{ matrix.target }}
path: |
runner-results/results.json
runner-results/*.stdout
runner-results/*.stderr
runner-results/schema-*/*.stdout
runner-results/schema-*/*.stderr
runner-results/database/*.stdout
runner-results/database/*.stderr
retention-days: 7
- uses: actions/upload-artifact@v4
with:
name: prisma-cli-${{ matrix.target }}-${{ github.sha }}
Expand Down Expand Up @@ -142,3 +182,17 @@ jobs:
if grep -E '^(native-tls|openssl|openssl-sys|postgres-native-tls) v' /tmp/quaint-dependencies.txt; then
exit 1
fi
ci-success:
if: always()
needs: [build, driver-tests, quaint-tests]
runs-on: ubuntu-latest
steps:
- name: Require every compatibility job
env:
JOB_RESULTS: ${{ toJson(needs) }}
run: |
python3 - <<'PYTHON'
import json, os
results = json.loads(os.environ["JOB_RESULTS"])
assert all(job["result"] == "success" for job in results.values()), results
PYTHON
49 changes: 41 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ mongodb = ["prisma-client-rust-sdk/mongodb"]

[dependencies]
sha2 = "0.10"
tar = "0.4"
tempfile = "3"
serde_json.workspace = true
serde.workspace = true
serde_path_to_error = "0.1.7"
Expand Down
61 changes: 16 additions & 45 deletions cli/src/binaries/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pub mod platform;
mod runner;

use directories::BaseDirs;
use flate2::read::GzDecoder;
use reqwest::blocking as reqwest;
use sha2::{Digest, Sha256};
use std::collections::BTreeMap;
use std::fs::{create_dir_all, metadata, File};
use std::fs::{create_dir_all, File};
use std::io;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -38,67 +39,37 @@ pub const ENGINES: [Engine; 4] = [
},
];

pub fn prisma_cli_name() -> String {
let variation = platform::name();
let arch = platform::arch();

format!("prisma-cli-{variation}-{arch}")
}

pub fn global_cache_dir() -> PathBuf {
let base_dirs = BaseDirs::new().unwrap();
pub fn global_cache_dir() -> Result<PathBuf, String> {
if let Some(path) = std::env::var_os("PRISMA_CLI_CACHE_DIR") {
let path = PathBuf::from(path);
if !path.is_absolute() {
return Err("PRISMA_CLI_CACHE_DIR must be absolute".into());
}
return Ok(path);
}
let base_dirs = BaseDirs::new().ok_or("Cannot resolve the Prisma cache directory")?;
let cache_dir = base_dirs.cache_dir();

cache_dir
Ok(cache_dir
.join(BASE_DIR_NAME)
.join("cli")
.join(PRISMA_CLI_VERSION)
.join(PRISMA_CLI_VERSION))
}

pub fn fetch_native(to_dir: &PathBuf) -> Result<(), String> {
pub fn fetch_native(to_dir: &Path) -> Result<runner::Runner, String> {
if !to_dir.is_absolute() {
Err("to_dir must be absolute".to_string())?;
}

download_cli(to_dir)?;
let runner = runner::install(to_dir)?;

for e in &ENGINES {
if std::env::var_os(e.env).is_none() {
download_engine(e.name, to_dir)?;
}
}

Ok(())
}

pub fn download_cli(to_dir: &PathBuf) -> Result<(), String> {
let cli = prisma_cli_name();

let to = platform::check_for_extension(&platform::name(), &to_dir.join(cli).to_str().unwrap());

let url = platform::check_for_extension(
&platform::name(),
&format!(
"https://prisma-photongo.s3-eu-west-1.amazonaws.com/{}-{}-{}-{}.gz",
"prisma-cli",
PRISMA_CLI_VERSION,
platform::name(),
platform::arch()
),
);

match metadata(&to) {
Err(_) => (),
Ok(_) => {
return Ok(());
}
};

println!("Downloading {} to {}", url, to);

download(&url, Path::new(&to), None)?;

Ok(())
Ok(runner)
}

#[derive(serde::Deserialize)]
Expand Down
Loading
Loading