add additional workflow for testing #52
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Xircuits Workflows Test | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: "*" | |
jobs: | |
build-and-run: | |
runs-on: ubuntu-latest | |
env: | |
TEST_XIRCUITS: | | |
examples/example.xircuits | |
examples/example2.xircuits | |
# path/to/your/workflow.xircuits | |
# Add more .xircuits files as needed, one per line | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Install xircuits | |
run: pip install xircuits | |
- name: Set Environment Variables | |
run: | | |
LIBRARY_NAME=$(echo "${GITHUB_REPOSITORY##*/}" | sed 's/-/_/g') | |
echo "LIBRARY_NAME=$LIBRARY_NAME" >> $GITHUB_ENV | |
COMPONENT_LIBRARY_PATH="xai_components/${LIBRARY_NAME}" | |
echo "COMPONENT_LIBRARY_PATH=$COMPONENT_LIBRARY_PATH" >> $GITHUB_ENV | |
- name: List Xircuits | |
run: xircuits list | |
- name: Clone Repository | |
run: | | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
git clone https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }} | |
else | |
PR_BRANCH=${{ github.event.pull_request.head.ref }} | |
git clone -b $PR_BRANCH https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }} | |
fi | |
- name: Install Component Library | |
run: | | |
if [ -f "${{ env.COMPONENT_LIBRARY_PATH }}/requirements.txt" ]; then | |
echo "requirements.txt found, installing dependencies..." | |
pip install -r ${{ env.COMPONENT_LIBRARY_PATH }}/requirements.txt | |
else | |
echo "requirements.txt not found." | |
fi | |
- name: Test .xircuits Workflows | |
run: | | |
export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}" | |
LOG_FILE="${GITHUB_WORKSPACE}/workflow_logs.txt" | |
echo "TEST_XIRCUITS: $TEST_XIRCUITS" | |
IFS=$'\n' read -r -a TEST_FILES <<< "$TEST_XIRCUITS" | |
echo "TEST_FILES: ${TEST_FILES[@]}" | |
FAIL=0 | |
if [ ${#TEST_FILES[@]} -eq 0 ]; then | |
echo "No .xircuits files specified for testing." | tee -a $LOG_FILE | |
else | |
for file in "${TEST_FILES[@]}"; do | |
echo "Starting to process $file" | |
FULL_PATH="${COMPONENT_LIBRARY_PATH}/${file}" | |
if [ -f "$FULL_PATH" ]; then | |
WORKFLOW_LOG_FILE="${FULL_PATH%.*}_workflow_log.txt" | |
echo "Processing $FULL_PATH..." | tee -a $LOG_FILE | |
echo "Compiling Xircuits workflow: $FULL_PATH" | |
xircuits compile $FULL_PATH "${FULL_PATH%.*}.py" 2>&1 | tee -a $LOG_FILE | |
echo "Finished compiling: $FULL_PATH" | |
echo "Running compiled Python script for: $FULL_PATH" | |
python "${FULL_PATH%.*}.py" 2>&1 | tee -a $WORKFLOW_LOG_FILE | |
echo "Finished running script for: $FULL_PATH" | |
echo "Checking if workflow executed successfully." | |
LAST_LINE=$(tail -n 1 "$WORKFLOW_LOG_FILE") | |
tail -n 5 "$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 | |
echo "Finished processing $file" | |
done | |
fi | |
if [ $FAIL -ne 0 ]; then | |
echo "One or more workflows failed or did not finish as expected." | tee -a $LOG_FILE | |
echo "Exiting with failure." | |
exit 1 | |
else | |
echo "Workflow processing completed successfully." | tee -a $LOG_FILE | |
fi | |
- name: Upload log file | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: workflow-logs | |
path: ${{ github.workspace }}/workflow_logs.txt |