2023-10-30 16:09:49 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-11-01 15:23:44 -04:00
|
|
|
DEST_PATH=$(dirname "$(realpath "$0")")
|
|
|
|
SCRIPT_DIR=$(dirname "$DEST_PATH")
|
2023-10-30 16:09:49 -04:00
|
|
|
cd "$SCRIPT_DIR"/.. || exit 1
|
|
|
|
OUTPUT_FOLDER_NAME=gcs-dest
|
2023-11-02 16:41:56 -05:00
|
|
|
OUTPUT_ROOT=${OUTPUT_ROOT:-$SCRIPT_DIR}
|
|
|
|
OUTPUT_DIR=$OUTPUT_ROOT/structured-output/$OUTPUT_FOLDER_NAME
|
|
|
|
WORK_DIR=$OUTPUT_ROOT/workdir/$OUTPUT_FOLDER_NAME
|
2023-10-30 16:09:49 -04:00
|
|
|
max_processes=${MAX_PROCESSES:=$(python3 -c "import os; print(os.cpu_count())")}
|
2023-11-16 12:13:46 -08:00
|
|
|
BUCKET="utic-test-ingest-fixtures-output"
|
|
|
|
DIRECTORY=$(uuidgen)
|
|
|
|
DESTINATION_GCS="gs://$BUCKET/$DIRECTORY"
|
2023-10-30 16:09:49 -04:00
|
|
|
CI=${CI:-"false"}
|
|
|
|
|
|
|
|
if [ -z "$GCP_INGEST_SERVICE_KEY" ]; then
|
2023-12-18 23:48:21 -08:00
|
|
|
echo "Skipping Google Drive ingest test because the GCP_INGEST_SERVICE_KEY env var is not set."
|
|
|
|
exit 8
|
2023-10-30 16:09:49 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create temporary service key file
|
|
|
|
GCP_INGEST_SERVICE_KEY_FILE=$(mktemp)
|
2023-12-11 20:04:15 -05:00
|
|
|
echo "$GCP_INGEST_SERVICE_KEY" >"$GCP_INGEST_SERVICE_KEY_FILE"
|
2023-10-30 16:09:49 -04:00
|
|
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source "$SCRIPT_DIR"/cleanup.sh
|
|
|
|
function cleanup() {
|
2023-12-18 23:48:21 -08:00
|
|
|
cleanup_dir "$OUTPUT_DIR"
|
|
|
|
cleanup_dir "$WORK_DIR"
|
2023-10-30 16:09:49 -04:00
|
|
|
|
2023-12-18 23:48:21 -08:00
|
|
|
python "$SCRIPT_DIR"/python/test-gcs-output.py down \
|
|
|
|
--service-account-file "$GCP_INGEST_SERVICE_KEY_FILE" \
|
|
|
|
--bucket "$BUCKET" \
|
|
|
|
--blob-path "$DIRECTORY"
|
2023-10-30 16:09:49 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2023-11-02 16:41:56 -05:00
|
|
|
RUN_SCRIPT=${RUN_SCRIPT:-./unstructured/ingest/main.py}
|
|
|
|
PYTHONPATH=${PYTHONPATH:-.} "$RUN_SCRIPT" \
|
2023-12-18 23:48:21 -08:00
|
|
|
local \
|
|
|
|
--num-processes "$max_processes" \
|
|
|
|
--output-dir "$OUTPUT_DIR" \
|
|
|
|
--strategy fast \
|
|
|
|
--verbose \
|
|
|
|
--reprocess \
|
|
|
|
--input-path example-docs/fake-memo.pdf \
|
|
|
|
--work-dir "$WORK_DIR" \
|
|
|
|
gcs \
|
|
|
|
--service-account-key "$GCP_INGEST_SERVICE_KEY_FILE" \
|
|
|
|
--remote-url "$DESTINATION_GCS"
|
2023-10-30 16:09:49 -04:00
|
|
|
|
|
|
|
# Simply check the number of files uploaded
|
2023-11-16 12:13:46 -08:00
|
|
|
python "$SCRIPT_DIR"/python/test-gcs-output.py check \
|
2023-12-18 23:48:21 -08:00
|
|
|
--expected-files 1 \
|
|
|
|
--service-account-file "$GCP_INGEST_SERVICE_KEY_FILE" \
|
|
|
|
--bucket "$BUCKET" \
|
|
|
|
--blob-path "$DIRECTORY"
|