From 36f501f208509a7cb0e93309c58385095c29c71a Mon Sep 17 00:00:00 2001 From: MFA-X-AI Date: Thu, 25 Jan 2024 13:52:26 +0800 Subject: [PATCH] fix multiple workflow handling, update readme --- .github/workflows/run-workflow-tests.yml | 29 ++++++++++++------------ README.md | 3 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/run-workflow-tests.yml b/.github/workflows/run-workflow-tests.yml index 864f0fa..77cfe56 100644 --- a/.github/workflows/run-workflow-tests.yml +++ b/.github/workflows/run-workflow-tests.yml @@ -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 @@ -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: | @@ -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") @@ -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 diff --git a/README.md b/README.md index 8da7e29..7f1657d 100644 --- a/README.md +++ b/README.md @@ -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). \ No newline at end of file