Change standard gates examples to have main outputs #1952
This file contains hidden or 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: "Test Library CI (main)" | |
| # This workflow always run in the context of Classiq/classiq-library (base repo) but might use a branch from a fork to test its contribution | |
| # PRs from users (should be from a fork) need to targePrint repository namet `main` branch which runs against `prod` environment | |
| on: | |
| push: # Trigger the workflow on push to the specific branch | |
| branches: | |
| - main | |
| pull_request_target: # Trigger the workflow on pull requests targeting the specific branch | |
| # Note: `pull_request_target` ensures that the tests run in the context of the `main` branch, not in the user's fork. | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| test: | |
| permissions: | |
| id-token: write | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| # | |
| # Setup Repository | |
| # | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Checkout the target branch | |
| id: checkout | |
| run: | | |
| set -ex | |
| # Debugging: initial git status | |
| echo "==== Git status before checkout ====" | |
| git status | |
| # Handle different GitHub Actions events | |
| if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then | |
| echo "Handling pull_request_target event" | |
| echo "SHOULD_TEST_ALL_FILES=false" >> $GITHUB_ENV | |
| if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then | |
| echo "PR from a fork detected. Checking out the fork's branch." | |
| git remote add fork 'https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git' | |
| git fetch fork '${{ github.event.pull_request.head.ref }}' | |
| git checkout -B ci-testing-branch FETCH_HEAD # Tested code is comming from this branch (contributer's) | |
| else | |
| echo "PR from the same repository detected. Checking out the branch." | |
| git fetch origin '${{ github.event.pull_request.head.ref }}' | |
| git checkout '${{ github.event.pull_request.head.ref }}' | |
| fi | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "Handling workflow_dispatch event: No checkout needed" | |
| echo "SHOULD_TEST_ALL_FILES=true" >> $GITHUB_ENV | |
| echo "list_of_ipynb_changed=**/*.ipynb" >> $GITHUB_ENV | |
| elif [[ "${{ github.event_name }}" == "push" ]]; then | |
| echo "Handling push event: No checkout needed" | |
| else | |
| echo "Unsupported event type: ${github.event_name}. Exiting." | |
| exit 1 | |
| fi | |
| # Debugging: final git status | |
| echo "==== Git status after checkout ====" | |
| git status | |
| # | |
| # Setup Python | |
| # | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Get latest classiq version for cache key | |
| id: classiq-version | |
| run: | | |
| echo "LATEST_CLASSIQ_VERSION=$(pip index versions classiq 2>/dev/null | grep classiq | cut -d '(' -f2 | cut -d ')' -f1)" >> $GITHUB_OUTPUT | |
| # The caching we do follows from | |
| # https://stackoverflow.com/questions/59127258/how-can-i-use-pip-cache-in-github-actions | |
| - uses: actions/cache@v4 | |
| id: cache-pip | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }}-classiq-${{steps.classiq-version.outputs.LATEST_CLASSIQ_VERSION}} | |
| restore-keys: | | |
| ${{ runner.os }}-venv- | |
| # Configure AWS credentials | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/[email protected] | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE }} | |
| aws-region: us-east-1 | |
| mask-aws-account-id: true | |
| - name: Install dependencies | |
| run: | | |
| set -e | |
| python -m pip install -U pip | |
| python -m pip install -U -r requirements.txt | |
| python -m pip install -U -r requirements_tests.txt | |
| - name: Install couenne solver | |
| env: | |
| COIN_DIST_URL: https://github.com/ampl/coin/releases/download/v20191215/coin-linux64.tar.gz | |
| LOCAL_BIN: ${{ runner.temp }}/.local/bin | |
| run: | | |
| set -eux | |
| mkdir -p "$LOCAL_BIN" | |
| echo "$LOCAL_BIN" >>"$GITHUB_PATH" | |
| wget -nv -O- "$COIN_DIST_URL" | tar -C "$RUNNER_TEMP" -xvz | |
| cp "${RUNNER_TEMP}/couenne" "${LOCAL_BIN}/couenne" | |
| chmod ugo+x "${LOCAL_BIN}/couenne" | |
| - name: Download and install Qmod parser | |
| env: | |
| WHL_FILE_NAME: qmod_parser-0.0.0-cp311-cp311-linux_x86_64.whl | |
| S3_BUCKET_SOURCE: s3://public-library-resources | |
| run: | | |
| set -eux | |
| classiq_version=$(pip show classiq | awk '/Version:/ {print $2}') | |
| mkdir qmod_parser | |
| aws s3 cp "$S3_BUCKET_SOURCE/qmod_parser/$classiq_version/$WHL_FILE_NAME" "qmod_parser/$WHL_FILE_NAME" | |
| python -m pip install "qmod_parser/$WHL_FILE_NAME" | |
| # | |
| # Setup Environment | |
| # | |
| # Set authentication with M2M token | |
| - name: Set authentication | |
| run: .github/scripts/get_m2m_token.sh | |
| env: | |
| IS_DEV: "false" | |
| M2M_SECRET_ARN: "${{ secrets.PROD_M2M_SECRET_ARN }}" | |
| # | |
| # Propagate CI information to python tests | |
| # | |
| - name: Get changed notebook files | |
| id: changed-files-ipynb | |
| uses: tj-actions/[email protected] | |
| with: | |
| files: | | |
| **/*.ipynb | |
| - name: Get changed notebook test files | |
| id: changed-files-tests | |
| uses: tj-actions/[email protected] | |
| with: | |
| files: | | |
| **/notebooks/**/test_*.py | |
| - name: Get changed Qmod files | |
| id: changed-files-qmod | |
| uses: tj-actions/[email protected] | |
| with: | |
| files: | | |
| **/*.qmod | |
| # Run Tests | |
| - name: Run Notebooks (quick tests) | |
| run: python -m pytest -c tests/config_quick_tests.ini | |
| env: | |
| # to disable a warning in Jupyter notebooks | |
| JUPYTER_PLATFORM_DIRS: "1" | |
| # Passing which notebooks changed | |
| SHOULD_TEST_ALL_FILES: "true" # quick tests should run all files | |
| LIST_OF_IPYNB_CHANGED: "${{ steps.changed-files-ipynb.outputs.all_changed_files }}" | |
| LIST_OF_IPYNB_TESTS_CHANGED: "${{ steps.changed-files-tests.outputs.all_changed_files }}" | |
| # Altering test behavior | |
| LIMIT_TEST_LINKS_TO_FILES_ONLY: "true" | |
| - name: Run Notebooks (executing notebooks and testing content) | |
| run: python -m pytest -c tests/config_notebook_execute_tests.ini | |
| env: | |
| # to disable a warning in Jupyter notebooks | |
| JUPYTER_PLATFORM_DIRS: "1" | |
| # Passing which notebooks changed | |
| SHOULD_TEST_ALL_FILES: "${{ env.SHOULD_TEST_ALL_FILES }}" | |
| LIST_OF_IPYNB_CHANGED: "${{ steps.changed-files-ipynb.outputs.all_changed_files }}" | |
| LIST_OF_IPYNB_TESTS_CHANGED: "${{ steps.changed-files-tests.outputs.all_changed_files }}" | |
| LIST_OF_QMOD_CHANGED: "${{ steps.changed-files-qmod.outputs.all_changed_files }}" | |
| # Altering test behavior | |
| LIMIT_TEST_LINKS_TO_FILES_ONLY: "false" |