Migrate CI to Github Actions #5055
Workflow file for this run
This file contains 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: Tests | |
on: | |
push: | |
branches: [ main, 'stable/*' ] | |
pull_request: | |
branches: [ main, 'stable/*' ] | |
workflow_call: | |
inputs: | |
test-rust: | |
description: > | |
Decides whether we perform rust tests | |
type: boolean | |
test-images: | |
description: > | |
Decides whether we perform image tests | |
type: boolean | |
install-optionals: | |
description: > | |
Decides whether we install optyional dependencies | |
type: boolean | |
default: false | |
install-from-dist: | |
description: > | |
Decides whether we perform rust tests | |
type: boolean | |
default: false | |
merge_group: | |
concurrency: | |
group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }} | |
cancel-in-progress: true | |
jobs: | |
tests-linux: | |
if: github.repository_owner == 'Qiskit' | |
name: ubuntu-latest-tests-Python-${{ matrix.python-version }} | |
runs-on: ubuntu-latest | |
env: | |
QISKIT_SUPPRESS_PACKAGING_WARNINGS: Y | |
PIP_CACHE_DIR: ${{ github.workspace }}/.pip | |
QISKIT_TEST_CAPTURE_STREAMS: 1 | |
HAVE_VISUAL_TESTS_RUN: false | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.9", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@1.70 | |
if: matrix.python-version == '3.9' | |
- name: Set up Python ${{ matrix.python-version }} | |
id: python-outputs | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache stestr | |
uses: actions/cache@v4 | |
with: | |
key: 'stestr | "${{ runner.os }}" | "${{ matrix.python-version }}" | "${{ github.run_id }}"' | |
restore-keys: | | |
stestr | "${{ runner.os }}" | "${{ matrix.python-version }}" | |
stestr | "${{ runner.os }}" | |
stestr | |
path: .stestr | |
- name: Run Rust Tests | |
if: inputs.test-rust == true | |
# We need to avoid linking our crates into full Python extension libraries during Rust-only | |
# testing because Rust/PyO3 can't handle finding a static CPython interpreter. | |
run: cargo test --no-default-features | |
env: | |
# On Linux we link against `libpython` dynamically, but it isn't written into the rpath | |
# of the test executable (I'm not 100% sure why ---Jake). It's easiest just to forcibly | |
# include the correct place in the `dlopen` search path. | |
LD_LIBRARY_PATH: '${{ steps.python-outputs.outputs.python-path }}/lib:$LD_LIBRARY_PATH' | |
- name: Prepare venv | |
run: | | |
set -e | |
python -m pip install --upgrade pip setuptools wheel virtualenv | |
virtualenv test-job | |
- name: Install Qiskit from sdist | |
if: ${{ inputs.install-from-dist }} | |
run: | | |
set -e | |
# Use stable Rust, rather than MSRV, to spot-check that stable builds properly. | |
rustup override set stable | |
source test-job/bin/activate | |
python -m pip install -U pip | |
python -m pip install -U build | |
python -m build --sdist . | |
python -m pip install -U \ | |
-c constraints.txt \ | |
-r requirements.txt \ | |
-r requirements-dev.txt \ | |
dist/qiskit-*.tar.gz | |
# Build and install both qiskit and qiskit-terra so that any optionals | |
# depending on `qiskit` will resolve correctly. | |
- name: Install QIskit directly | |
if: ${{ !inputs.install-from-dist }} | |
run: | | |
set -e | |
source test-job/bin/activate | |
python -m pip install -U \ | |
-c constraints.txt \ | |
-r requirements.txt \ | |
-r requirements-dev.txt \ | |
-e . | |
# Build and install both qiskit and qiskit-terra so that any optionals | |
# depending on `qiskit` will resolve correctly. | |
- name: Install Optional packages | |
run: | | |
set -e | |
source test-job/bin/activate | |
python -m pip install -r requirements-optional.txt -c constraints.txt | |
python -m pip check | |
if: ${{ inputs.install-optionals }} | |
- name: Install optional non-Python dependencies | |
run: | | |
set -e | |
sudo apt-get update | |
sudo apt-get install -y graphviz | |
if: ${{ inputs.install-optionals }} | |
- name: Run Python tests | |
run: | | |
set -e | |
source test-job/bin/activate | |
python tools/report_numpy_state.py | |
mkdir -p /tmp/terra-tests | |
cp -r test /tmp/terra-tests/. | |
cp .stestr.conf /tmp/terra-tests/. | |
cp -r .stestr /tmp/terra-tests/. || : | |
pushd /tmp/terra-tests | |
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))") | |
echo "PYTHONHASHSEED=$PYTHONHASHSEED" | |
stestr run | |
popd | |
env: | |
QISKIT_PARALLEL: FALSE | |
RUST_BACKTRACE: 1 | |
- name: Install Image dependencies | |
run: | | |
set -e | |
virtualenv image_tests | |
image_tests/bin/python -m pip install -U \ | |
-c constraints.txt \ | |
-r requirements.txt \ | |
-r requirements-dev.txt \ | |
-r requirements-optional.txt \ | |
-e . | |
sudo apt-get update | |
sudo apt-get install -y graphviz pandoc | |
image_tests/bin/pip check | |
if: ${{ inputs.test-images }} | |
- name: Run image tests | |
run: | | |
echo "##vso[task.setvariable variable=HAVE_VISUAL_TESTS_RUN;]true" | |
image_tests/bin/python -m unittest discover -v test/visual | |
if: ${{ inputs.test-images }} | |
env: | |
# Needed to suppress a warning in jupyter-core 5.x by eagerly migrating to | |
# a new internal interface that will be the default in jupyter-core 6.x. | |
# This variable should become redundant on release of jupyter-core 6. | |
JUPYTER_PLATFORM_DIRS: 1 | |
- name: Store image tests diff | |
uses: actions/upload-artifact@v4 | |
if: ${{ inputs.test-images && failure()}} | |
with: | |
name: image-test-failure-img-diffs | |
path: | | |
./test/visual/mpl/graph/graph_results | |
if-no-files-found: error | |
tests: | |
if: github.repository_owner == 'Qiskit' | |
name: macOS-arm64-tests-Python-${{ matrix.python-version }} | |
runs-on: macOS-14 | |
strategy: | |
fail-fast: false | |
matrix: | |
# Normally we test min and max version but we can't run python | |
# 3.9 on arm64 until actions/setup-python#808 is resolved | |
python-version: ["3.10", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@1.70 | |
if: matrix.python-version == '3.10' | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
architecture: arm64 | |
- name: 'Install dependencies' | |
run: | | |
python -m pip install -U -r requirements.txt -c constraints.txt | |
python -m pip install -U -r requirements-dev.txt -c constraints.txt | |
python -m pip install -c constraints.txt -e . | |
if: matrix.python-version == '3.10' | |
env: | |
QISKIT_NO_CACHE_GATES: 1 | |
- name: 'Install dependencies' | |
run: | | |
python -m pip install -U -r requirements.txt -c constraints.txt | |
python -m pip install -U -r requirements-dev.txt -c constraints.txt | |
python -m pip install -c constraints.txt -e . | |
if: matrix.python-version == '3.13' | |
- name: 'Install optionals' | |
run: | | |
python -m pip install -r requirements-optional.txt -c constraints.txt | |
python tools/report_numpy_state.py | |
if: matrix.python-version == '3.10' | |
- name: 'Run tests' | |
run: stestr run |