Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

fix: Lock file script changes to fail fast (#774)

Chandrasekharan M887dfde0292a
diff --git a/.github/workflows/pdm-lock-automation.yaml b/.github/workflows/pdm-lock-automation.yaml
index bd65e5546..38c54273e 100644
--- a/.github/workflows/pdm-lock-automation.yaml
+++ b/.github/workflows/pdm-lock-automation.yaml
@@ -57,7 +57,7 @@ jobs:
IFS=',' read -r -a dir_array <<< "$dirs"
# Print directories being processed
- echo "Processing specified directories: ${dir_array[@]}"
+ echo "Processing specified directories: ${dir_array[*]}"
# Pass directories as command-line arguments to the script
./scripts/pdm-lock.sh "${dir_array[@]}"
diff --git a/scripts/pdm-lock.sh b/scripts/pdm-lock.sh
index 8cdfcc964..2460ef0be 100755
--- a/scripts/pdm-lock.sh
+++ b/scripts/pdm-lock.sh
@@ -1,4 +1,5 @@
#!/bin/bash
+set -o pipefail
# Function to update the lockfile in a directory
update_lockfile() {
@@ -6,52 +7,65 @@ update_lockfile() {
file_path="$dir/pyproject.toml"
if [[ ! -f "$file_path" ]]; then
- echo "[$dir] No pyproject.toml found in $dir"
- return
+ echo "[$dir] No pyproject.toml found in '$dir'"
+ return 0
fi
- echo "[$dir] Checking $file_path for changes against origin/main..."
+ echo "[$dir] Checking '$file_path' for changes against origin/main..."
if ! git diff --quiet origin/main -- "$file_path"; then
- echo "[$dir] Changes detected in $file_path, updating pdm.lock for $dir ..."
+ echo "[$dir] Changes detected in '$file_path', updating pdm.lock for '$dir' ..."
# Move to the directory if it's not root
if [[ "$dir" != "." ]]; then
- cd "$dir"
+ cd "$dir" || return 1
fi
# Set up virtual environment if not exists
if [[ ! -d ".venv" ]]; then
- echo "[$dir] Creating virtual environment in directory: $dir"
- pdm venv create -w virtualenv --with-pip
+ echo "[$dir] Creating virtual environment in directory: '$dir'"
+ pdm venv create -w virtualenv --with-pip 2>&1 | sed "s|^|[$dir] |" || return 1
else
echo "[$dir] Virtual environment already exists in $dir"
fi
# Activate virtual environment
- source .venv/bin/activate
+ source .venv/bin/activate 2>&1 | sed "s|^|[$dir] |" || return 1
# HACK: https://github.com/pdm-project/pdm/issues/3199
# Replace with checking the exit code directly once above issue is fixed
lock_output=$(pdm lock --check 2>&1)
if echo "$lock_output" | grep -q "WARNING: Lockfile is generated on an older version of PDM"; then
- echo "[$dir] Updating pdm.lock in $dir due to outdated version..."
- pdm lock -G :all -v 2>&1 | sed "s/^/[$dir] /"
+ echo "[$dir] Updating pdm.lock in '$dir' due to outdated version..."
+ pdm lock -G :all -v 2>&1 | sed "s|^|[$dir] |" || return 1
elif [[ $? -ne 0 ]]; then
- echo "[$dir] Updating pdm.lock in $dir due to detected changes..."
- pdm lock -G :all -v 2>&1 | sed "s/^/[$dir] /"
+ echo "[$dir] Updating pdm.lock in '$dir' due to detected changes..."
+ pdm lock -G :all -v 2>&1 | sed "s|^|[$dir] |" || return 1
else
- echo "[$dir] No changes required for pdm.lock in $dir."
+ echo "[$dir] No changes required for pdm.lock in '$dir'."
fi
# Go back to root if moved to a subdirectory
if [[ "$dir" != "." ]]; then
- cd -
+ cd - || return 1
fi
else
- echo "[$dir] No changes detected in $file_path"
+ echo "[$dir] No changes detected in '$file_path'"
fi
}
+# https://unix.stackexchange.com/a/124148
+# Used to list child processes to kill them in case of an error
+list_descendants ()
+{
+ local children=$(ps -o pid= --ppid "$1")
+
+ for pid in $children
+ do
+ list_descendants "$pid"
+ done
+
+ echo "$children"
+}
# Default directories list
directories=(
@@ -75,11 +89,28 @@ fi
# To compare against main branch
git fetch origin main
+# Array to store the job PIDs and directories
+pids=()
+dirs=()
# Run lockfile updates in parallel
for dir in "${directories[@]}"; do
update_lockfile "$dir" &
+ pid=$!
+ pids+=($pid) # Add the PID of the background job to the array
+ dirs+=("$dir") # Add the corresponding directory to the array
done
-# Wait for all background processes to complete
-wait
+# Wait for each background process to complete, exit on the first failure
+for i in "${!pids[@]}"; do
+ pid=${pids[$i]}
+ dir=${dirs[$i]}
+ echo "[$dir] Waiting for child process with PID: $pid..."
+
+ # # Wait for the specific process to finish
+ if ! wait "$pid"; then
+ echo "[$dir] Lock file generation failed. Killing other sub-processes..."
+ kill $(list_descendants $$) 2>/dev/null || true
+ exit 1
+ fi
+done