Skip to content

Commit

Permalink
Merge pull request #12 from jpopelka/jirka
Browse files Browse the repository at this point in the history
CI & pre-commit & static types
  • Loading branch information
jpopelka authored Dec 15, 2023
2 parents 5e80735 + ea6efc1 commit feeae2d
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 243 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pytest

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install
run: |
pip3 install -r requirements.txt
pip3 install .
- name: Test with pytest
run: |
pip3 install pytest
pytest --verbose --showlocals tests/
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# HOWTO: https://pre-commit.com/#usage
# dnf install pre-commit
# pre-commit install -t pre-commit -t pre-push

repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff-format
- id: ruff
args: [--exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [types-requests]

ci:
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pipeline {
}
}

post {
post {
success {
script {
if (isPullRequest()) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ commands:

### Note about promoting to production

Merging pull requests to the master branch also triggers a build in CI. However, such images are **not*** automatically promoted and used by the CI pipelines. In order to promote a new image to production, you need to explicitly say so in the [rpmdeplint-pipeline](https://github.com/fedora-ci/rpmdeplint-pipeline/README.md#promoting-new-rpmdeplint-image-to-production) repository.
Merging pull requests to the master branch also triggers a build in CI. However, such images are **not\*** automatically promoted and used by the CI pipelines. In order to promote a new image to production, you need to explicitly say so in the [rpmdeplint-pipeline](https://github.com/fedora-ci/rpmdeplint-pipeline/README.md#promoting-new-rpmdeplint-image-to-production) repository.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests
requests
125 changes: 81 additions & 44 deletions rpmdeplint_runner/run.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,77 @@
#!/bin/python3
#!/usr/bin/python3

import argparse
import sys
import requests
import logging
import sys
from pathlib import Path

from rpmdeplint_runner.outcome import TmtExitCodes, RpmdeplintCodes
from rpmdeplint_runner.utils import run_rpmdeplint
from rpmdeplint_runner.utils.fedora import download_rpms, get_repo_urls, get_cached_rpms, is_prepared

from rpmdeplint_runner.utils.fedora import (
download_rpms,
get_repo_urls,
get_cached_rpms,
is_prepared,
)

logger = logging.getLogger(__name__)


def parse_args():
"""Parse arguments."""
parser = argparse.ArgumentParser(description='Run rpmdeplint tests')
parser = argparse.ArgumentParser(description="Run rpmdeplint tests")

subparsers = parser.add_subparsers(title="commands", dest="command")
prepare_parser = subparsers.add_parser('prepare', help='prepare given workdir for running tests')
prepare_parser.add_argument(
"--task-id", "-t", dest="task_id", required=True,
action="append", type=str, help="a comma-separated list of Koji task IDs"
prepare_parser = subparsers.add_parser(
"prepare", help="prepare given workdir for running tests"
)
prepare_parser.add_argument(
"--release", "-r", dest="release_id", required=True, help="release id, e.g.: f33"
"--task-id",
"-t",
dest="task_id",
required=True,
action="append",
type=str,
help="a comma-separated list of Koji task IDs",
)
prepare_parser.add_argument(
"--arch", dest="arch", required=True, action="append", type=str,
help="a comma-separated list of repository architectures"
"--release",
"-r",
dest="release_id",
required=True,
help="release id, e.g.: f33",
)
prepare_parser.add_argument(
"--os", dest="os", required=False, default='fedora', choices=['fedora'],
help="operating system, e.g.: fedora"
"--arch",
dest="arch",
required=True,
action="append",
type=str,
help="a comma-separated list of repository architectures",
)
prepare_parser.add_argument(
"--workdir", dest="work_dir", required=True,
help="workdir where to store files"
"--workdir", dest="work_dir", required=True, help="workdir where to store files"
)

test_parser = subparsers.add_parser('run-test', help='run the given rpmdeplint test', parents=[prepare_parser], add_help=False)
test_parser = subparsers.add_parser(
"run-test",
help="run the given rpmdeplint test",
parents=[prepare_parser],
add_help=False,
)
test_parser.add_argument(
"--name", "-n", dest="test_name", required=True, choices=['check', 'check-sat', 'check-repoclosure', 'check-conflicts', 'check-upgrade'],
help="rpmdeplint test name"
"--name",
"-n",
dest="test_name",
required=True,
choices=[
"check",
"check-sat",
"check-repoclosure",
"check-conflicts",
"check-upgrade",
],
help="rpmdeplint test name",
)

args = parser.parse_args()
Expand All @@ -52,42 +81,50 @@ def parse_args():
sys.exit(1)

# turn string (a comma-separated list of task ids) into a Python list
# "428432,4535432" -> ["428432", "4535432"]
# ["428432,4535432", "123456"] -> ["428432", "4535432", "123456"]
task_ids = []
for task_id_str in args.task_id:
task_ids.extend([int(x) for x in task_id_str.strip().split(',')])
task_ids.extend(list(task_id_str.strip().split(",")))
args.task_id = task_ids

# turn string (a comma-separated list of arches) into a Python list
# "x86_64,i686" -> ["x86_64", "i686"]
arches = []
for arch_str in args.arch:
arches.extend([x for x in arch_str.strip().split(',')])
arches.extend(list(arch_str.strip().split(",")))
args.arch = arches

args.work_dir = Path(args.work_dir)

return args


def prepare(work_dir, task_ids, arches):
def prepare(work_dir: Path, task_ids: list[str], arches: list[str]) -> None:
"""Run prepare command.
:param work_dir: str, workdir
:param task_ids: list, task ids
:param arches: list, architectures
:param work_dir: workdir
:param task_ids: task ids
:param arches: list of architectures
:return: None
"""
for task_id in task_ids:
download_rpms(task_id, work_dir, arches)


def run_test(work_dir, test_name, release_id, os, task_ids=None, arch=None):
def run_test(
work_dir: Path,
test_name: str,
release_id: str,
task_ids: list[str],
arch: str,
) -> None:
"""Run rpmdeplint test.
:param work_dir: str, workdir
:param test_name: str, name of the rpmdeplint test to run
:param release_id: str, release id, example: f33
:param task_ids: list, task ids
:param arch: str, architecture
:param work_dir: workdir
:param test_name: name of the rpmdeplint test to run
:param release_id: release id, example: f33
:param task_ids: task ids
:param arch: architecture
:return: None
"""
repo_urls = get_repo_urls(release_id, arch)
Expand All @@ -96,19 +133,17 @@ def run_test(work_dir, test_name, release_id, os, task_ids=None, arch=None):
if not is_prepared(work_dir, task_ids, [arch]):
# TODO: stderr
print(
'Error: unable to run the "{test_name}({arch})" test as RPMs for the task id {task_id} were not downloaded.'.format(
test_name=test_name, task_id=str(task_ids), arch=arch
)
f'Error: unable to run the "{test_name}({arch})" test '
f"as RPMs for the task id {task_ids} were not downloaded."
)
sys.exit(TmtExitCodes.ERROR.value)

if not rpms_list:
# skip the test if there are no RPMs for given arch
# TODO: stderr
print(
'Skipping "{test_name}({arch})" test for the task id {task_id} as there are no RPMs for that architecture...'.format(
test_name=test_name, task_id=str(task_ids), arch=arch
)
f'Skipping "{test_name}({arch})" test for the task id {task_ids} '
f"as there are no RPMs for that architecture..."
)
sys.exit(TmtExitCodes.SKIPPED.value)

Expand All @@ -119,13 +154,15 @@ def run_test(work_dir, test_name, release_id, os, task_ids=None, arch=None):

def run(args):
"""Run, Rpmdeplint, run!"""
if args.command == 'prepare':
if args.command == "prepare":
prepare(args.work_dir, args.task_id, args.arch)
elif args.command == 'run-test':
elif args.command == "run-test":
arch = args.arch[0]
run_test(args.work_dir, args.test_name, args.release_id, args.os, args.task_id, arch)
run_test(
args.work_dir, args.test_name, args.release_id, args.os, args.task_id, arch
)


if __name__ == '__main__':
if __name__ == "__main__":
args = parse_args()
run(args)
8 changes: 4 additions & 4 deletions rpmdeplint_runner/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rpmdeplint_runner.utils.common import http_get
from rpmdeplint_runner.utils.common import run_command
from rpmdeplint_runner.utils.common import run_rpmdeplint
from rpmdeplint_runner.utils.common import fix_arches
from rpmdeplint_runner.utils.common import http_get # noqa: F401
from rpmdeplint_runner.utils.common import run_command # noqa: F401
from rpmdeplint_runner.utils.common import run_rpmdeplint # noqa: F401
from rpmdeplint_runner.utils.common import fix_arches # noqa: F401
Loading

0 comments on commit feeae2d

Please sign in to comment.