Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
frankharkins committed Dec 5, 2024
1 parent 4c806c6 commit 9c4b89b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
45 changes: 24 additions & 21 deletions .github/workflows/notebook-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions scripts/ci/pr-execute-notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 9c4b89b

Please sign in to comment.