Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

GitHub release #28

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: poetry run coverage xml -o coverage.xml
- name: Read global coverage target
id: coverage-target
run: echo "fail-under=$(python read-target-coverage.py)" >> $GITHUB_OUTPUT
run: echo "fail-under=$(poetry run python scripts/read-target-coverage.py)" >> $GITHUB_OUTPUT
- name: Post coverage comment
if: ${{ github.event_name == 'pull_request' }}
uses: orgoro/coverage@v3
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,39 @@ name: Release Artifacts
on:
push:
tags:
- '*'
- 'v*'
jobs:
wheel-build:
name: Build and Publish Release Artifacts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
name: Install Python
- name: Checkout code
uses: actions/checkout@v2
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- uses: abatilo/actions-poetry@v2
name: Install Poetry
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: '1.3.2'
- name: Install Deps
- name: Install release dependencies
run: pip install -U twine wheel
- name: Build Artifacts
- name: Build packages
run: |
poetry build
shell: bash
- uses: actions/upload-artifact@v2
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
path: ./dist/qiskit*
# - name: Publish to PyPi
# env:
# TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
# TWINE_USERNAME: qiskit
# run: twine upload dist/qiskit*
- name: Extract changelog
run: poetry run python scripts/extract-changelog.py ${{ github.ref }} | tee ${{ github.workspace }}-CHANGELOG.txt
- name: Create Github release
uses: softprops/action-gh-release@v1
with:
files: ./dist/qiskit*
body_path: ${{ github.workspace }}-CHANGELOG.txt
- name: Publish to AQT Package registry
env:
TWINE_PASSWORD: ${{ secrets.AQT_PACKAGE_REGISTRY_WRITE_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ exclude = (?x)(
| ^tools/
)

[mypy-mistletoe.*]
ignore_missing_imports = True

[mypy-numpy.*]
ignore_missing_imports = True

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Fix and improve error handing from individual circuits #24
* Automatically create a Github release when a version tag is pushed #28
* Add `number_of_qubits` to the `quantum_circuit` job payload #29

## qiskit-aqt-provider v0.8.1
Expand Down
37 changes: 35 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ coverage = "^7.2.1"
dirty-equals = "^0.5.0"
isort = "^5.12.0"
jupyter-sphinx = "^0.4.0"
mistletoe = "^1.0.1"
mypy = "=1.0.1"
poethepoet = "^0.18.1"
pre-commit = "^3.1.1"
Expand All @@ -68,6 +69,7 @@ qiskit-sphinx-theme = ">=1.7.0"
qiskit-terra = {version = ">=0.23.2", extras = ["visualization"]}
sphinx = ">=5.3"
sympy = "^1.11.1"
typer = "^0.7.0"
types-requests = "^2.28.11"
types-setuptools = "^65.7.0"
types-tabulate = "^0.9.0.1"
Expand Down
10 changes: 0 additions & 10 deletions read-target-coverage.py

This file was deleted.

70 changes: 70 additions & 0 deletions scripts/extract-changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3

import re
import shlex
import subprocess
import sys
from pathlib import Path
from typing import Dict, Final, Optional

import typer
from mistletoe import Document, block_token
from mistletoe.base_renderer import BaseRenderer

HEADER_REGEX: Final = re.compile(r"([a-z-]+)\s+(v\d+\.\d+\.\d+)")


class Renderer(BaseRenderer):
def render_list_item(self, token: block_token.ListItem) -> str:
return "* " + self.render_inner(token) + "\n"


def default_changelog_path() -> Path:
"""Path to the 'CHANGELOG.md' file at the repository root."""
repo_root = Path(
subprocess.run(shlex.split("git rev-parse --show-toplevel"), capture_output=True)
.stdout.strip()
.decode("utf-8")
)

return repo_root / "CHANGELOG.md"


def main(
version: Optional[str] = typer.Argument(None),
changelog_path: Path = typer.Argument(default_changelog_path),
) -> None:
"""Print the changes for the given version. By default, use the latest version (if any)."""
with open(changelog_path, encoding="utf-8") as fp:
md_ast = Document(fp)

changelogs: Dict[str, str] = {}
current_version: Optional[str] = None

for node in md_ast.children:
if isinstance(node, block_token.Heading) and node.level == 2:
if (match := HEADER_REGEX.search(node.children[0].content)) is not None:
_, revision = match.groups()
current_version = revision
else:
current_version = None

if current_version and isinstance(node, block_token.List):
with Renderer() as renderer:
changelogs[current_version] = renderer.render(node)

if version is None and not changelogs:
print("No version found in changelog.", file=sys.stderr)
sys.exit(1)

target_version = version if version is not None else sorted(changelogs)[-1]

try:
print(changelogs[target_version])
except KeyError:
print(f"Version {target_version} not found in changelog.", file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
typer.run(main)
35 changes: 35 additions & 0 deletions scripts/read-target-coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

"""Extract the coverage target from the pyproject.toml file.

This is used by the Github workflows to write the coverage report comment on PRs."""

import shlex
import subprocess
from pathlib import Path

import tomlkit
import typer


def default_pyproject_path() -> Path:
"""Path to the 'pyproject.toml' file at the repository root."""
repo_root = Path(
subprocess.run(shlex.split("git rev-parse --show-toplevel"), capture_output=True)
.stdout.strip()
.decode("utf-8")
)

return repo_root / "pyproject.toml"


def main(pyproject_path: Path = typer.Argument(default_pyproject_path)) -> None:
"""Read the 'pyproject.toml' file at `pyproject_path` and extract the
'fail_under' field of the 'coverage' tool configuration."""
with open(pyproject_path, encoding="utf-8") as fp:
data = tomlkit.load(fp)
print(float(data["tool"]["coverage"]["report"]["fail_under"]) / 100.0) # type: ignore[index, arg-type]


if __name__ == "__main__":
typer.run(main)