Skip to content

Commit

Permalink
Merge pull request #1 from rabea-al/main
Browse files Browse the repository at this point in the history
Gradio component library maintenance
  • Loading branch information
MFA-X-AI authored Nov 14, 2024
2 parents 425aef4 + cd22005 commit ef8a1bd
Show file tree
Hide file tree
Showing 4 changed files with 1,783 additions and 49 deletions.
113 changes: 73 additions & 40 deletions .github/workflows/run-workflow-tests.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@

name: Run Xircuits Workflows Test

on:
push:
branches: [ main ]
pull_request:
branches: "*"
workflow_dispatch:

jobs:
build-and-run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
env:
TEST_XIRCUITS: |
example.xircuits
examples/DataCollectionInterface.xircuits
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install xircuits
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}


- name: Create virtual environment
run: |
python -m venv venv
echo "${{ github.workspace }}/venv/bin" >> $GITHUB_PATH
- name: Install xircuits in virtual environment
run: pip install xircuits

- name: Set Environment Variables
Expand All @@ -30,10 +50,17 @@ jobs:
fi
- name: List Xircuits
run: xircuits list
run: xircuits list

- name: Clone Repository
run: git clone -b ${{ env.BRANCH_NAME }} https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }}
run: |
rm -rf ${{ env.COMPONENT_LIBRARY_PATH }}
if [ "${{ github.event_name }}" == "pull_request" ]; then
REPO_URL="${{ github.event.pull_request.head.repo.clone_url }}"
else
REPO_URL="https://github.com/${{ github.repository }}"
fi
git clone -b ${{ env.BRANCH_NAME }} $REPO_URL ${{ env.COMPONENT_LIBRARY_PATH }}
- name: Install Component Library
run: |
Expand All @@ -44,50 +71,56 @@ jobs:
echo "requirements.txt not found."
fi
- name: Test .xircuits Workflows
run: |
export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}"
LOG_FILE="${GITHUB_WORKSPACE}/workflow_logs.txt"
TEST_FILES=$(echo "$TEST_XIRCUITS" | tr '\n' ' ')
echo "Repository: $LIBRARY_NAME" > $LOG_FILE
echo "Branch: $BRANCH_NAME" >> $LOG_FILE
echo -e "Testing Files:\n$TEST_FILES" >> $LOG_FILE
IFS=' ' read -r -a FILE_ARRAY <<< "$TEST_FILES"
FAIL=0
if [ ${#FILE_ARRAY[@]} -eq 0 ]; then
echo "No .xircuits files specified for testing." | tee -a $LOG_FILE
echo "Starting Gradio interface test..." > $LOG_FILE
# Compile the Xircuits workflow and log the output
FULL_PATH="${COMPONENT_LIBRARY_PATH}/${TEST_XIRCUITS}"
echo "Compiling Xircuits workflow: ${FULL_PATH}" >> $LOG_FILE
xircuits compile $FULL_PATH "${FULL_PATH%.*}.py" 2>&1 | tee -a $LOG_FILE
# Run the Python script in the background
export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}"
echo "Running Python script: ${FULL_PATH%.*}.py" >> $LOG_FILE
python "${FULL_PATH%.*}.py" 2>&1 | tee -a $LOG_FILE &
PYTHON_PID=$!
# Wait for the Gradio server to start
echo "Waiting 20 seconds for the Gradio server to initialize..." >> $LOG_FILE
sleep 20
# Try to connect to Gradio URL to confirm it's running
echo "Checking if Gradio server is accessible..." >> $LOG_FILE
if curl --fail http://127.0.0.1:7860; then
echo "Gradio server is accessible and running." | tee -a $LOG_FILE
else
for file in "${FILE_ARRAY[@]}"; do
FULL_PATH="${COMPONENT_LIBRARY_PATH}/${file}"
if [ -f "$FULL_PATH" ]; then
WORKFLOW_LOG_FILE="${FULL_PATH%.*}_workflow_log.txt"
echo -e "\n\nProcessing $FULL_PATH..." | tee -a $LOG_FILE
xircuits compile $FULL_PATH "${FULL_PATH%.*}.py" 2>&1 | tee -a $LOG_FILE
python "${FULL_PATH%.*}.py" 2>&1 | tee -a $WORKFLOW_LOG_FILE
LAST_LINE=$(tail -n 1 "$WORKFLOW_LOG_FILE")
if [[ "$LAST_LINE" != "Finished Executing" ]]; then
echo "Error: Workflow $FULL_PATH did not finish as expected" | tee -a $LOG_FILE
FAIL=1
else
echo "$FULL_PATH processed successfully" | tee -a $LOG_FILE
fi
cat "$WORKFLOW_LOG_FILE" | tee -a $LOG_FILE
else
echo "Specified file $FULL_PATH does not exist" | tee -a $LOG_FILE
FAIL=1
fi
done
fi
if [ $FAIL -ne 0 ]; then
echo "One or more workflows failed or did not finish as expected." | tee -a $LOG_FILE
echo "Gradio server did not start or is not accessible." | tee -a $LOG_FILE
echo "Killing Gradio process (PID: $PYTHON_PID)..." >> $LOG_FILE
kill -9 $PYTHON_PID
exit 1
else
echo "Workflow processing completed" | tee -a $LOG_FILE
fi
# Simulate user interactions or wait a fixed amount of time
echo "Simulating user interaction with Gradio interface for 5 seconds..." >> $LOG_FILE
sleep 5
# Check if the Python script is still running, and if so, kill it
if ps -p $PYTHON_PID > /dev/null; then
echo "Gradio interface ran successfully for the duration of the test. Killing the process..." | tee -a $LOG_FILE
kill -9 $PYTHON_PID
else
echo "Gradio interface finished execution before the test completed." | tee -a $LOG_FILE
fi
echo "Gradio interface test completed." >> $LOG_FILE
- name: Upload log file
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.LIBRARY_NAME }}-validation-workflow
name: ${{ env.LIBRARY_NAME }}-validation-workflow-${{ matrix.python-version }}
path: ${{ github.workspace }}/workflow_logs.txt
Loading

0 comments on commit ef8a1bd

Please sign in to comment.