From 63fbe4d9a12077fa2482e547a74604334b6a3574 Mon Sep 17 00:00:00 2001 From: Nathan Probert Date: Fri, 28 Aug 2026 23:30:14 -0400 Subject: [PATCH 1/2] Reuse build artifacts across CI jobs --- .github/workflows/deploy.yml | 52 +++++++++++++++++++----------------- build_scripts/deploy.sh | 37 ++++++++++++++++--------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 67a9841..4f03b92 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,17 +51,26 @@ jobs: restore-keys: | rust-build-${{ runner.os }}- - - name: Compile Rust code - run: make compile + - name: Compile C code + run: make compile_c + + - name: Compile Rust code (Linux Lambda target) + run: cargo build --release --target x86_64-unknown-linux-gnu --manifest-path smartscore/Rust/make_predictions/Cargo.toml + + - name: Install compiled Rust module into venv + run: | + SITE_PACKAGES=$(find .venv -type d -name site-packages | head -1) + cp smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so \ + "$SITE_PACKAGES/make_predictions_rust.so" + uv run python -c "import make_predictions_rust; print('make_predictions_rust import OK')" - name: Upload build artifacts uses: actions/upload-artifact@v5 with: name: build-artifacts path: | - smartscore/Rust/make_predictions/target/release/*.dll - smartscore/Rust/make_predictions/target/release/*.so - smartscore/Rust/make_predictions/target/release/*.dylib + smartscore/compiled_code.so + smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so retention-days: 1 lint: @@ -89,11 +98,6 @@ jobs: - name: Install dependencies run: uv sync --all-groups - - name: Download build artifacts - uses: actions/download-artifact@v6 - with: - name: build-artifacts - - name: Run lint run: uv run make lint @@ -122,17 +126,16 @@ jobs: - name: Install dependencies run: uv sync --all-groups - - name: Cache Rust build - uses: actions/cache@v4 + - name: Download build artifacts + uses: actions/download-artifact@v6 with: - path: | - smartscore/Rust/make_predictions/target - key: rust-build-${{ runner.os }}-${{ hashFiles('smartscore/Rust/make_predictions/Cargo.lock') }} - restore-keys: | - rust-build-${{ runner.os }}- + name: build-artifacts - - name: Compile Rust code - run: make compile_rust + - name: Install compiled Rust module into venv + run: | + SITE_PACKAGES=$(find .venv -type d -name site-packages | head -1) + cp smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so \ + "$SITE_PACKAGES/make_predictions_rust.so" - name: Run tests run: make test @@ -149,6 +152,7 @@ jobs: env_was_dev: ${{ steps.env-detect.outputs.is_dev }} env: ENV: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} + DEPLOY_SKIP_BUILD: "1" steps: - name: Detect environment id: env-detect @@ -157,11 +161,6 @@ jobs: - name: Checkout code uses: actions/checkout@v6 - - name: Install build tools - run: | - sudo apt-get update - sudo apt-get install -y build-essential # Install gcc and make - - name: Set up Python uses: actions/setup-python@v6 with: @@ -173,6 +172,11 @@ jobs: - name: Install dependencies run: uv sync --no-dev + - name: Download build artifacts + uses: actions/download-artifact@v6 + with: + name: build-artifacts + - name: Set environment variables run: | echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" >> $GITHUB_ENV diff --git a/build_scripts/deploy.sh b/build_scripts/deploy.sh index dd510f0..14d7ce7 100755 --- a/build_scripts/deploy.sh +++ b/build_scripts/deploy.sh @@ -280,20 +280,31 @@ if [ $? -ne 0 ]; then fi rm -f $OUTPUT_DIR/requirements.txt -# compile C code -echo "Compiling C code..." -sh build_scripts/compile.sh -if [ $? -ne 0 ]; then - echo "Error: Compilation failed. Ensure docker is running." - exit 1 -fi +# compile C and Rust. When the CI "setup" job has already built the artifacts +# (see DEPLOY_SKIP_BUILD in .github/workflows/deploy.yml), reuse them instead. +if [ "${DEPLOY_SKIP_BUILD:-0}" = "1" ]; then + if [ ! -f "$SOURCE_DIR/compiled_code.so" ] || \ + [ ! -f "$SOURCE_DIR/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so" ]; then + echo "Error: DEPLOY_SKIP_BUILD is set but prebuilt artifacts are missing (compile in setup first)." + exit 1 + fi + echo "Skipping C/Rust compilation (reusing artifacts from CI setup job)..." +else + # compile C code + echo "Compiling C code..." + sh build_scripts/compile.sh + if [ $? -ne 0 ]; then + echo "Error: Compilation failed. Ensure docker is running." + exit 1 + fi -# compile Rust code -echo "Compiling Rust code..." -sh build_scripts/rust_compile.sh -if [ $? -ne 0 ]; then - echo "Error: Compilation failed. Ensure docker is running." - exit 1 + # compile Rust code + echo "Compiling Rust code..." + sh build_scripts/rust_compile.sh + if [ $? -ne 0 ]; then + echo "Error: Compilation failed. Ensure docker is running." + exit 1 + fi fi # update the code From 5ffe4a6accc1291453f4a5c59fe970ed47cba650 Mon Sep 17 00:00:00 2001 From: Nathan Probert Date: Fri, 28 Aug 2026 23:34:37 -0400 Subject: [PATCH 2/2] Fix build artifact root stripping by upload-artifact LCA --- .github/workflows/deploy.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4f03b92..0d15a3f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -64,13 +64,19 @@ jobs: "$SITE_PACKAGES/make_predictions_rust.so" uv run python -c "import make_predictions_rust; print('make_predictions_rust import OK')" + - name: Stage build artifacts + run: | + mkdir -p build_artifacts/smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release + cp smartscore/compiled_code.so build_artifacts/smartscore/compiled_code.so + cp smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so \ + build_artifacts/smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so + - name: Upload build artifacts uses: actions/upload-artifact@v5 with: name: build-artifacts - path: | - smartscore/compiled_code.so - smartscore/Rust/make_predictions/target/x86_64-unknown-linux-gnu/release/libmake_predictions_rust.so + path: build_artifacts/ + if-no-files-found: error retention-days: 1 lint: