diff --git a/.github/workflows/notebook-test.yml b/.github/workflows/notebook-test.yml index e81ac4cae61..839f97e62f2 100644 --- a/.github/workflows/notebook-test.yml +++ b/.github/workflows/notebook-test.yml @@ -25,39 +25,42 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Get all changed notebooks - id: all-changed-notebooks + - name: Get relevant changed files + id: all-changed uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1 with: - files: "docs/**/*.ipynb" + files: "{docs/**/*.ipynb,scripts/nb-tester/**/*}" separator: "\n" write_output_files: true - - name: Get changed config files - id: changed-config - uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1 - with: - files: "scripts/nb-tester/**/*" - write_output_files: true - - - name: Check for notebooks that require Linux - id: linux-changed-files - uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1 - with: + - name: Check if extra linux deps needed + id: check-deps + shell: python + run: | # Add your notebook to this list if it needs latex or graphviz to run - files: | - docs/guides/visualize-circuits.ipynb - docs/guides/custom-backend.ipynb - docs/guides/transpiler-stages.ipynb - docs/guides/represent-quantum-computers.ipynb - docs/guides/common-parameters.ipynb + EXTRA_DEPS_NOTEBOOKS = """\ + docs/guides/visualize-circuits.ipynb + docs/guides/custom-backend.ipynb + docs/guides/transpiler-stages.ipynb + docs/guides/represent-quantum-computers.ipynb + docs/guides/common-parameters.ipynb + """.strip().split("\n") + import os + github_output = os.getenv("GITHUB_OUTPUT") + all_files = "${{ steps.all-changed.outputs.all_changed_files }}".split("\n") + + config_changed = any(path.startswith("scripts/") for path in all_files) + extra_deps = config_changed or any(path in EXTRA_DEPS_NOTEBOOKS for path in all_files) + + with open(github_output, "a") as output: + output.write(f"NEEDS_EXTRA_DEPS={str(extra_deps).lower()}") - name: Setup environment uses: ./.github/actions/set-up-notebook-testing with: # Install Linux deps if the specific guides were changed, or # if all files are being tested. - install-linux-deps: ${{ steps.linux-changed-files.outputs.any_changed == 'true' || steps.changed-config.outputs.any_changed == 'true' }} + install-linux-deps: ${{ steps.check-deps.outputs.NEEDS_EXTRA_DEPS }} ibm-quantum-token: ${{ secrets.IBM_QUANTUM_TEST_TOKEN }} - name: Execute notebooks diff --git a/scripts/ci/pr-execute-notebooks.py b/scripts/ci/pr-execute-notebooks.py index ebc0851b377..d87404e87d6 100644 --- a/scripts/ci/pr-execute-notebooks.py +++ b/scripts/ci/pr-execute-notebooks.py @@ -32,16 +32,16 @@ import subprocess from pathlib import Path -changed_notebooks = Path(".github/outputs/all_changed_files.txt").read_text().split("\n") -print(changed_notebooks) -changed_config = Path(".github/outputs/changed-config.txt").read_text().split("\n") +all_changed_files = Path(".github/outputs/all_changed_files.txt").read_text().split("\n") -print(changed_notebooks) -print() -print(changed_config) +changed_notebooks = [ + path for path in all_changed_files + if path.startswith("docs/") +] +config_changed = any(path.startswith("scripts/") for path in all_changed_files) args = ["tox", "--", "--write"] -if changed_notebooks and not changed_config: +if changed_notebooks and not config_changed: args.extend(changed_notebooks.split("\n")) is_fork = os.environ["PR_REPOSITORY"] != os.environ["GITHUB_REPOSITORY"]