Skip to content

Commit

Permalink
fix multiple workflow handling, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MFA-X-AI committed Jan 25, 2024
1 parent c6d1654 commit 36f501f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/run-workflow-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
env:
TEST_XIRCUITS: |
examples/example.xircuits
# path/to/your/workflow.xircuits
# Add more .xircuits files as needed, one per line
steps:
- name: Checkout Repository
Expand All @@ -28,18 +26,17 @@ jobs:
echo "LIBRARY_NAME=$LIBRARY_NAME" >> $GITHUB_ENV
COMPONENT_LIBRARY_PATH="xai_components/${LIBRARY_NAME}"
echo "COMPONENT_LIBRARY_PATH=$COMPONENT_LIBRARY_PATH" >> $GITHUB_ENV
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
else
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
- 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
run: git clone -b ${{ env.BRANCH_NAME }} https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }}

- name: Install Component Library
run: |
Expand All @@ -54,16 +51,20 @@ jobs:
run: |
export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}"
LOG_FILE="${GITHUB_WORKSPACE}/workflow_logs.txt"
IFS=$'\n' read -r -a TEST_FILES <<< "$TEST_XIRCUITS"
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 [ ${#TEST_FILES[@]} -eq 0 ]; then
if [ ${#FILE_ARRAY[@]} -eq 0 ]; then
echo "No .xircuits files specified for testing." | tee -a $LOG_FILE
else
for file in "${TEST_FILES[@]}"; do
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 "Processing $FULL_PATH..." | tee -a $LOG_FILE
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")
Expand Down Expand Up @@ -91,5 +92,5 @@ jobs:
if: always()
uses: actions/upload-artifact@v3
with:
name: workflow-logs
name: ${{ env.LIBRARY_NAME }}-validation-workflow
path: ${{ github.workspace }}/workflow_logs.txt
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ pip install -r requirements.txt
```

To use this component library, simply copy the directory / clone or submodule the repository to your working Xircuits project directory.

## Tests
A github action to test your workflow runs has been provided. Simply add the path of your workflow [here](.github/workflows/run-workflow-tests.yml#L13).

0 comments on commit 36f501f

Please sign in to comment.