Skip to content

Commit

Permalink
test integration test coverage [NRP-429] (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyae-cqc authored Jun 6, 2024
1 parent e8eccd1 commit e6ce132
Show file tree
Hide file tree
Showing 41 changed files with 1,698 additions and 112 deletions.
200 changes: 200 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
name: Python package

on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
inputs:
run_integration_tests_only:
type: boolean
description: "Run integration tests only?"
required: false
default: false
schedule:
# everyday at 12:00
- cron: '0 12 * * *'

jobs:

version-matrix-integration:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Cache poetry
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: Set up ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
run: |
pip install pip==22.2.1 poetry==1.6.1
poetry run pip install --upgrade pip
- name: Install dev dependencies
run: |
poetry install --all-extras
check:
name: Check
runs-on: ubuntu-latest
if: (!inputs.run_integration_tests_only || github.event_name != 'schedule')
strategy:
matrix:
python-version: ['3.11']
action: ['lint', 'type', 'format']
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Cache poetry
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup poetry
run: |
pip install pip==22.2.1 poetry==1.6.1
poetry run pip install --upgrade pip
- name: Install dev dependencies
run: |
poetry install --all-extras
- name: Check formatting with black
run: |
poetry run black --check .
if: ${{ matrix.action == 'format' }}

- name: Typecheck with mypy
run: |
poetry run mypy qnexus/
poetry run mypy tests/
poetry run mypy integration/
if: ${{ matrix.action == 'type' }}

- name: Lint with pylint
run: |
poetry run pylint qnexus/
poetry run pylint tests/
poetry run pylint integration/
if: ${{ matrix.action == 'lint' }}

test:
name: Test
runs-on: ubuntu-latest
if: (!inputs.run_integration_tests_only || github.event_name != 'schedule')
strategy:
matrix:
python-version: ['3.10', '3.11']

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Cache poetry
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup poetry
run: |
pip install pip==22.2.1 poetry==1.6.1
poetry run pip install --upgrade pip
- name: Install dev dependencies
run: |
poetry install --all-extras
- name: Test with pytest
run: |
poetry run pytest tests/ --doctest-modules --cov=qnexus --cov-report=html --cov-report=term
- name: Upload pytest test results
uses: actions/upload-artifact@master
with:
name: pytest-results-${{ matrix.python-version }}
path: htmlcov/


test-integration:
name: Integration
needs: [version-matrix-integration]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
env:
NEXUS_QA_USER_EMAIL: ${{ secrets.NEXUS_QA_USER_EMAIL }}
NEXUS_QA_USER_PASSWORD: ${{ secrets.NEXUS_QA_USER_PASSWORD }}
NEXUS_HOST: "staging.myqos.com"
STORE_NEXUS_TOKENS: "false"

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Cache poetry
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-${{ matrix.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup poetry
run: |
pip install pip==22.2.1 poetry==1.6.1
poetry run pip install --upgrade pip
- name: Install dev dependencies
run: |
poetry install --all-extras
- name: Set up qnexus login tokens
run: |
poetry run python integration/setup_tokens.py
- name: Run integration tests
run: |
poetry run pytest integration/ --html=integration-results.html --timeout=600 -ra --reruns 3
- name: Upload integration test results
uses: actions/upload-artifact@master
with:
path: |
./integration-results-*.html
./assets/*.css
name: integration-results
159 changes: 159 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Check Conventional Commits format
# Cribbed from https://github.com/CQCL/hugr/blob/main/.github/workflows/pr-title.yml

on:
pull_request_target:
branches:
- main
types:
- opened
- edited
- synchronize
- labeled
- unlabeled
merge_group:
types: [checks_requested]

permissions:
pull-requests: write

jobs:
main:
name: Validate Conventional Commit PR title
runs-on: ubuntu-latest
# The action does not support running on merge_group events,
# but if the check succeeds in the PR there is no need to check it again.
if: github.event_name == 'pull_request_target'
outputs:
# Whether the PR title indicates a breaking change.
breaking: ${{ steps.breaking.outputs.breaking }}
# Whether the PR body contains a "BREAKING CHANGE:" footer describing the breaking change.
has_breaking_footer: ${{ steps.breaking.outputs.has_breaking_footer }}
steps:
- name: Validate the PR title format
uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed (newline-delimited).
# Default: https://github.com/commitizen/conventional-commit-types
types: |
feat
fix
docs
style
refactor
perf
test
ci
chore
revert
infra
# Configure which scopes are allowed (newline-delimited).
# These are regex patterns auto-wrapped in `^ $`.
#scopes: |
# .*
# Configure that a scope must always be provided.
requireScope: false
# Configure which scopes are disallowed in PR titles (newline-delimited).
# For instance by setting the value below, `chore(release): ...` (lowercase)
# and `ci(e2e,release): ...` (unknown scope) will be rejected.
# These are regex patterns auto-wrapped in `^ $`.
#disallowScopes: |
# release
# [A-Z]+
# Configure additional validation for the subject based on a regex.
# This example ensures the subject doesn't start with an uppercase character.
#subjectPattern: ^(?![A-Z]).+$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
#subjectPatternError: |
# The subject "{subject}" found in the pull request title "{title}"
# didn't match the configured pattern. Please ensure that the subject
# doesn't start with an uppercase character.
# If the PR contains one of these newline-delimited labels, the
# validation is skipped. If you want to rerun the validation when
# labels change, you might want to use the `labeled` and `unlabeled`
# event triggers in your workflow.
ignoreLabels: |
ignore-semantic-pull-request
# `action-semantic-pull-request` does not parse the title, so it cannot
# detect if it is marked as a breaking change.
#
# Since at this point we know the PR title is a valid conventional commit,
# we can use a simple regex that looks for a '!:' sequence. It could be
# more complex, but we don't care about false positives.
- name: Check for breaking change flag
id: breaking
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^.*\!:.*$ ]]; then
echo "breaking=true" >> $GITHUB_OUTPUT
else
echo "breaking=false" >> $GITHUB_OUTPUT
fi
# Check if the PR comment has a "BREAKING CHANGE:" footer describing
# the breaking change.
if [[ "${{ github.event.pull_request.body }}" != *"BREAKING CHANGE:"* ]]; then
echo "has_breaking_footer=false" >> $GITHUB_OUTPUT
else
echo "has_breaking_footer=true" >> $GITHUB_OUTPUT
fi
# Post a help comment if the PR title indicates a breaking change but does
# not contain a "BREAKING CHANGE:" footer.
- name: Require "BREAKING CHANGE:" footer for breaking changes
id: breaking-comment
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
It looks like your proposed title indicates a breaking change. If that's the case,
please make sure to include a "BREAKING CHANGE:" footer in the body of the pull request
describing the breaking change and any migration instructions.
- name: Fail if the footer is required but missing
if: ${{ steps.breaking.outputs.breaking == 'true' && steps.breaking.outputs.has_breaking_footer == 'false' }}
run: exit 1

- name: Post a comment if the PR badly formatted
uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
and it looks like your proposed title needs to be adjusted.
Your title should look like this. The scope field is optional.
```
<type>(<scope>): <description>
```
If the PR includes a breaking change, mark it with an exclamation mark:
```
<type>!: <description>
```
and include a "BREAKING CHANGE:" footer in the body of the pull request.
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete previous comments when the issues have been resolved
# This step doesn't run if any of the previous checks fails.
- name: Delete previous comments
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ __pycache__/
.env

dist/
docs/_build

# IPython
.ipynb_checkpoints
Expand Down
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ disable=raw-checker-failed,
duplicate-code,
too-many-arguments,
too-many-instance-attributes,
fixme,


# Enable the message, report, category or checker with the given id(s). You can
Expand Down
Loading

0 comments on commit e6ce132

Please sign in to comment.