From f0f13b301640c6e8fd882ce6169ebf170180d44b Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:11:06 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=A7=20Add=20pytest-cov,=20test=20p?= =?UTF-8?q?eppers,=20schema=20and=20zizmor=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- .pre-commit-config.yaml | 16 +++++++++++++++- pyproject.toml | 8 +++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b15639c..b50f15c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,4 +45,18 @@ repos: entry: pdm run python -m pylint bqp_api/ language: system always_run: true - pass_filenames: false \ No newline at end of file + pass_filenames: false + + ## Check GitHub workflow and Renovate schemas + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.39.0 + hooks: + - id: check-github-workflows + - id: check-renovate + additional_dependencies: [json5] + + ## Check for security issues in GitHub Actions workflows + - repo: https://github.com/zizmorcore/zizmor-pre-commit + rev: v1.33.0 + hooks: + - id: zizmor diff --git a/pyproject.toml b/pyproject.toml index 8febf98..240e1ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ dev = [ test = [ "pytest>=7.4.0", "pytest-env>=0.8.2", + "pytest-cov>=6.0.0", ] [tool.pylint.'MESSAGES CONTROL'] @@ -50,6 +51,11 @@ env = [ "QUANTUM_DB_FILENAME=test_db.sqlite", "QUANTUM_DB_USER=", "QUANTUM_DB_PASS=", - "QUANTUM_DB_HOST=" + "QUANTUM_DB_HOST=", + "D:QUANTUM_DB_PEPPER=test-pepper", + "D:QUANTUM_DB_TOKEN_PEPPER=test-token-pepper", ] + +[tool.coverage.run] +source = ["bqp_api"] pythonpath = ["."] From ce7195b0182fe6e53d5271dbb128738073c6a164 Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:11:27 +0100 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=A7=20Add=20Renovate=20and=20Relea?= =?UTF-8?q?se=20Drafter=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- .github/release-drafter.yml | 52 ++++++++++++++++++++++++++++++++++ .github/renovate.json5 | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/renovate.json5 diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..6723ebc --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,52 @@ +name-template: "MQP API $RESOLVED_VERSION Release" +tag-template: "v$RESOLVED_VERSION" +categories: + - title: "๐Ÿš€ Features and Enhancements" + labels: + - "enhancement" + - "feature" + - "refactor" + - "usability" + - title: "๐Ÿ› Bug Fixes" + labels: + - "bug" + - "fix" + - title: "๐Ÿ“„ Documentation" + labels: + - "documentation" + - title: "๐Ÿค– CI" + labels: + - "continuous integration" + - title: "๐Ÿ“ฆ Packaging" + labels: + - "packaging" + - title: "๐Ÿงน Code Quality" + labels: + - "code quality" + - title: "โฌ†๏ธ Dependencies" + collapse-after: 5 + labels: + - "dependencies" + - "github-actions" + - "pre-commit" + - "submodules" +change-template: "- $TITLE ([#$NUMBER]($URL)) (**@$AUTHOR**)" +change-title-escapes: '\<*_&' +version-resolver: + major: + labels: + - "major" + minor: + labels: + - "minor" + patch: + labels: + - "patch" + default: patch + +template: | + ## ๐Ÿ‘€ What Changed + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..65e8921 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,56 @@ +{ + $schema: "https://docs.renovatebot.com/renovate-schema.json", + extends: [ + "config:recommended", + ":gitSignOff", + "helpers:pinGitHubActionDigestsToSemver", + ":automergeDigest", + ":automergeStableNonMajor", + ":combinePatchMinorReleases", + ":configMigration", + ":enablePreCommit", + ":prConcurrentLimitNone", + ":prHourlyLimitNone", + ], + enabledManagers: ["dockerfile", "github-actions", "pep621", "pre-commit"], + lockFileMaintenance: { + enabled: true, + automerge: true, + }, + labels: ["dependencies"], + schedule: ["every weekend"], + packageRules: [ + { + matchManagers: ["dockerfile"], + addLabels: ["docker"], + commitMessagePrefix: "โฌ†\uFE0F\uD83D\uDC33", + }, + { + matchManagers: ["github-actions"], + addLabels: ["github-actions"], + commitMessagePrefix: "โฌ†\uFE0F\uD83D\uDC68\u200D\uD83D\uDCBB", + }, + { + matchManagers: ["pep621"], + addLabels: ["python"], + commitMessagePrefix: "โฌ†\uFE0F\uD83D\uDC0D", + }, + { + matchManagers: ["pre-commit"], + addLabels: ["pre-commit"], + commitMessagePrefix: "โฌ†\uFE0F\uD83E\uDE9D", + versioning: "pep440", + }, + { + matchUpdateTypes: ["lockFileMaintenance"], + commitMessagePrefix: "โฌ†\uFE0F\uD83D\uDD12\uFE0F", + }, + { + description: "Group and automerge all patch updates", + groupName: "patch updates", + groupSlug: "all-patch", + matchUpdateTypes: ["patch"], + automerge: true, + }, + ], +} From a7d5cf6f971882eae193ddbe9bd19c2a5bb7057f Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:11:48 +0100 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=91=B7=20Add=20CI=20workflow;=20pin?= =?UTF-8?q?=20and=20scope=20Jira=20sync=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- .github/workflows/ci.yml | 97 +++++++++++++++++++++++++++ .github/workflows/jira-sync.yml | 25 ++++--- .github/workflows/release-drafter.yml | 17 +++++ 3 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d3c030c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,97 @@ +name: CI +on: + push: + branches: + - develop + pull_request: + merge_group: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + lint: + name: ๐Ÿ Lint + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 + with: + python-version: "3.11" + - name: Install PDM and the project + run: | + python -m pip install pdm + pdm install -G dev -G test + # Runs the hooks in .pre-commit-config.yaml: black, isort, mypy, pylint, + # file checks and the zizmor workflow security check. + - name: Run pre-commit + run: pdm run pre-commit run --all-files --show-diff-on-failure + + tests: + name: ๐Ÿ Test (Python ${{ matrix.python-version }}) + runs-on: ubuntu-26.04 + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11"] + permissions: + contents: read + id-token: write # Codecov upload via OIDC + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install PDM and the project + run: | + python -m pip install pdm + pdm install -G test + - name: Run tests + run: pdm run pytest --cov --cov-report=xml --cov-report=term + - name: Upload coverage to Codecov + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + fail_ci_if_error: true + flags: python + use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }} + + docker: + name: ๐Ÿณ Docker image + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + - name: Build image (not pushed) + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: . + push: false + tags: bqp-api:ci + + required-checks-pass: # This job does nothing and is only used for branch protection + name: ๐Ÿšฆ Check + if: always() + needs: + - lint + - tests + - docker + runs-on: ubuntu-26.04 + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@b5b5b37504aa4183270bd3d855c52a67f212be35 # v1.3.0 + with: + jobs: ${{ toJSON(needs) }} diff --git a/.github/workflows/jira-sync.yml b/.github/workflows/jira-sync.yml index 4ef9d56..c5eef7e 100644 --- a/.github/workflows/jira-sync.yml +++ b/.github/workflows/jira-sync.yml @@ -2,16 +2,17 @@ on: issues: types: [opened, closed] -permissions: - issues: write +permissions: {} jobs: create-jira-issue: if: github.event.action == 'opened' + permissions: + issues: write # comment the Jira key on the GitHub issue runs-on: ubuntu-latest steps: - name: Log in to Jira - uses: atlassian/gajira-login@v3 + uses: atlassian/gajira-login@45fd029b9f1d6d8926c6f04175aa80c0e42c9026 # v3.0.1 env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} @@ -19,7 +20,7 @@ jobs: - name: Create Issue in Jira id: create_jira - uses: atlassian/gajira-create@v3 + uses: atlassian/gajira-create@59e177c4f6451399df5b4911c2211104f171e669 # v3.0.1 with: project: QSI issuetype: Task @@ -31,23 +32,29 @@ jobs: ${{ github.event.issue.body }} - name: Comment Jira Key on GitHub Issue - uses: actions/github-script@v7 + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 + env: + JIRA_ISSUE: ${{ steps.create_jira.outputs.issue }} + JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} with: script: | + const { JIRA_ISSUE, JIRA_BASE_URL } = process.env; github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - body: `Tracked in Jira: [${{ steps.create_jira.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create_jira.outputs.issue }})` + body: `Tracked in Jira: [${JIRA_ISSUE}](${JIRA_BASE_URL}/browse/${JIRA_ISSUE})` }) close-jira-issue: if: github.event.action == 'closed' + permissions: + issues: read # read the Jira key from the issue comments runs-on: ubuntu-latest steps: - name: Find Jira key in issue comments id: key - uses: actions/github-script@v7 + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 with: script: | const comments = await github.paginate(github.rest.issues.listComments, { @@ -62,14 +69,14 @@ jobs: core.setFailed('No Jira key found in the issue comments'); - name: Login to Jira - uses: atlassian/gajira-login@v3 + uses: atlassian/gajira-login@45fd029b9f1d6d8926c6f04175aa80c0e42c9026 # v3.0.1 env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - name: Move Jira item to Done - uses: atlassian/gajira-transition@v3 + uses: atlassian/gajira-transition@38fc9cd61b03d6a53dd35fcccda172fe04b36de3 # v3.0.1 with: issue: ${{ steps.key.outputs.key }} transition: Done diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..e27147e --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,17 @@ +name: Release Drafter + +on: + push: + branches: + - develop + +permissions: {} + +jobs: + update_release_draft: + name: Run + permissions: + contents: write + runs-on: ubuntu-26.04 + steps: + - uses: release-drafter/release-drafter@d1a19e60e81a7e650d00a7de9277f87e439117ea # v7.11.0 From 2c73f1ad44789185aa8e54811481c1b38e986cca Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:12:08 +0100 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20isort=20order=20and=20?= =?UTF-8?q?pylint=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- bqp_api/version_1/__init__.py | 2 +- bqp_api/version_1/job_metrics.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bqp_api/version_1/__init__.py b/bqp_api/version_1/__init__.py index f7fcc92..9319f54 100644 --- a/bqp_api/version_1/__init__.py +++ b/bqp_api/version_1/__init__.py @@ -1,6 +1,6 @@ from flask import Blueprint -from . import hamiltonian_jobs, jobs, resources, job_metrics +from . import hamiltonian_jobs, job_metrics, jobs, resources blueprint = Blueprint("version_1", __name__, url_prefix="/v1") blueprint.register_blueprint(resources.blueprint) diff --git a/bqp_api/version_1/job_metrics.py b/bqp_api/version_1/job_metrics.py index 4e70b96..9d8fd68 100644 --- a/bqp_api/version_1/job_metrics.py +++ b/bqp_api/version_1/job_metrics.py @@ -1,8 +1,6 @@ -from typing import Optional - import bqp_database_access as database # type: ignore from eliot import log_call # type: ignore -from flask import Blueprint, g, request +from flask import Blueprint blueprint = Blueprint("job_metrics", __name__) @@ -11,8 +9,11 @@ @log_call def job_metrics(uuid): try: + # TODO: bqp_database_access has no job_metrics module yet, so this lookup + # always raises and the endpoint returns 404. + # pylint: disable-next=no-member _job_metrics = database.job_metrics.fetch_timestamp_data_by_job_id(uuid)[0] - except Exception as e: + except Exception: return "JOB METRICS NOT FOUND", 404 if _job_metrics is None: From 55a4b88e7d5ec07f0d421554bd233d4336bbb88b Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:12:33 +0100 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=85=20Fix=20job=20creation=20test=20(?= =?UTF-8?q?target,=20budget,=20201=20Created)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- tests/conftest.py | 22 ++++++++++++++++++++++ tests/test_jobs.py | 12 ++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0d957ce..0e0aa80 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,8 @@ from bqp_api import create_app +TEST_TARGET = "test_target" + def generate_token() -> str: return "".join( @@ -44,6 +46,26 @@ def create_local_database(token: str) -> None: "test_user", "test_password", "BASIC", "test@lrz.de", "LRZ", "quantum" ) + # A target specification and a budget reachable through a user group are + # required before a circuit job can be created (see test_jobs.py). + quantum_db = open_database() + quantum_db.TargetSpecification( + name=TEST_TARGET, specification_type="resource", resource_name=TEST_TARGET + ) + test_user = quantum_db.User.get(identity="test_user") + test_group = quantum_db.UserGroup( + name="test_group", owner=test_user, cost_modifier=1.0, users=[test_user] + ) + quantum_db.Budget( + name="temp_budget", + owner=test_user, + credits=MAX_BUDGET_USAGE, + user_groups=[test_group], + ) + # open_database() returns a new connection on every call, so commit here + # to release the SQLite write lock before the token is added. + quantum_db.commit() + database_access.tokens.add_new_token( name="test_token", owner="test_user", diff --git a/tests/test_jobs.py b/tests/test_jobs.py index c9e1c1a..22d8068 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -1,11 +1,19 @@ from http import HTTPStatus +from conftest import TEST_TARGET + def test_job_creation(client) -> None: """Test if it is possible to create a circuit job.""" - job_data = {"shots": 1000, "circuit": "", "circuit_format": "", "resource_name": ""} + job_data = { + "shots": 1000, + "circuit": 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[1];\ncreg c[1];\nh q[0];\nmeasure q[0] -> c[0];\n', + "circuit_format": "qasm", + "resource_name": TEST_TARGET, + } response = client.post("/v1/job", json=job_data, headers=client.headers) - assert response.status_code == HTTPStatus.OK + assert response.status_code == HTTPStatus.CREATED + assert "uuid" in response.get_json() From cfb99c55a8fef0fc2c2501f11b4713a2ec407198 Mon Sep 17 00:00:00 2001 From: Marco De Pascale Date: Fri, 27 Nov 2026 10:18:07 +0100 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=91=B7=20Don't=20fail=20on=20Codecov?= =?UTF-8?q?=20upload=20until=20the=20repo=20is=20registered?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco De Pascale --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3c030c..fcfbe55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,8 +61,10 @@ jobs: run: pdm run pytest --cov --cov-report=xml --cov-report=term - name: Upload coverage to Codecov uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + # Do not fail the build while the repository is not yet registered with + # Codecov; switch to true (as in QDMI) once the Codecov app is installed. with: - fail_ci_if_error: true + fail_ci_if_error: false flags: python use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}