Skip to content

Commit e796230

Browse files
committed
misc(ci): Adding a basic pipeline to run linters and test
1 parent 0170ca3 commit e796230

3 files changed

Lines changed: 109 additions & 9 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Pull Request Checks
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
ruff:
11+
name: Lint with ruff
12+
uses: ./.github/workflows/python-job.yml
13+
with:
14+
run: |
15+
ruff check --show-fixes
16+
ruff format --check --diff
17+
18+
secrets: inherit
19+
20+
test:
21+
name: Run tests
22+
uses: ./.github/workflows/python-job.yml
23+
with:
24+
run: |
25+
set -o pipefail
26+
mkdir reports
27+
pytest --junit-xml=reports/pytest.xml --cov --cov-report=term-missing:skip-covered | tee reports/coverage.txt
28+
artifact: pytest-results
29+
artifact_path: reports/
30+
secrets: inherit
31+
32+
report-coverage:
33+
name: Report tests coverage
34+
runs-on: ubuntu-latest
35+
if: ${{ github.event_name == 'pull_request' }}
36+
needs: [test]
37+
steps:
38+
- name: Download Pytest results
39+
uses: actions/download-artifact@v4
40+
with:
41+
name: pytest-results
42+
path: reports
43+
44+
- name: Add PR comment
45+
uses: MishaKav/pytest-coverage-comment@main
46+
with:
47+
junitxml-path: reports/pytest.xml
48+
pytest-coverage-path: reports/coverage.txt
49+
report-only-changed-files: true

.github/workflows/python-job.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Python Job
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
python-version:
7+
type: string
8+
default: "3.9"
9+
run:
10+
required: true
11+
type: string
12+
artifact:
13+
type: string
14+
default: ''
15+
required: false
16+
artifact_path:
17+
type: string
18+
default: ''
19+
required: false
20+
21+
jobs:
22+
run:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout source code
26+
uses: actions/checkout@v4
27+
with:
28+
ref: "${{ github.head_ref || github.ref }}"
29+
30+
- name: Set up Python ${{ inputs.python-version }}
31+
uses: actions/setup-python@v5
32+
with:
33+
cache: 'pip'
34+
python-version: ${{ inputs.python-version }}
35+
36+
- name: Install project dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install .[dev,test]
40+
41+
- name: Run Command
42+
run: |
43+
${{ inputs.run }}
44+
45+
- name: Upload artifacts
46+
uses: actions/upload-artifact@v4
47+
if: ${{ github.event.inputs.artifact == '' || github.event.inputs.artifact_path == '' }}
48+
with:
49+
name: ${{ inputs.artifact }}
50+
path: ${{ inputs.artifact_path }}
51+
if-no-files-found: ignore
52+

dk-installer.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import urllib.request
2828
import urllib.parse
2929
import zipfile
30-
31-
30+
import typing
3231
#
3332
# Initial setup
3433
#
@@ -288,7 +287,7 @@ def console_tee(text, skip_logging=False):
288287
@dataclasses.dataclass
289288
class Requirement:
290289
key: str
291-
cmd: tuple[str, ...]
290+
cmd: tuple[typing.Union[str, pathlib.Path], ...]
292291
fail_msg: tuple[str, ...]
293292

294293
def check_availability(self, action, args):
@@ -316,9 +315,9 @@ class CommandFailed(Exception):
316315

317316
def __init__(
318317
self,
319-
idx: int | None = None,
320-
cmd: str | None = None,
321-
ret_code: int | None = None,
318+
idx: typing.Union[int, None] = None,
319+
cmd: typing.Union[str, None] = None,
320+
ret_code: typing.Union[int, None] = None,
322321
):
323322
if any((idx, cmd, ret_code)) and not all((idx, cmd)):
324323
raise ValueError(f"{self.__class__.__name__} requires 'idx' and 'cmd' to be set unless all args are None.")
@@ -344,7 +343,7 @@ def __init__(self, action, args):
344343
self.action = action
345344
self.args = args
346345

347-
def _hash_value(self, value: bytes | str, digest_size: int = 8) -> str:
346+
def _hash_value(self, value: typing.Union[bytes, str], digest_size: int = 8) -> str:
348347
if isinstance(value, str):
349348
value = value.encode()
350349
return hashlib.blake2b(value, salt=self.get_instance_id().encode(), digest_size=digest_size).hexdigest()
@@ -527,7 +526,7 @@ def configure_logging(self, debug=False):
527526

528527
def _get_failed_cmd_log_file_path(
529528
self, exception: Exception
530-
) -> tuple[CommandFailed, pathlib.Path] | tuple[None, None]:
529+
) -> typing.Union[tuple[CommandFailed, pathlib.Path], tuple[None, None]]:
531530
while exception:
532531
if isinstance(exception, CommandFailed):
533532
break
@@ -2439,7 +2438,7 @@ def run_installer(args):
24392438
"Disable sending analytics data",
24402439
key="send_analytics_data",
24412440
value="--no-analytics",
2442-
msg="Sending analytcs data has been disabled for this session.",
2441+
msg="Sending analytics data has been disabled for this session.",
24432442
)
24442443
cfg_menu.add_option(
24452444
"Enable sending analytics data",

0 commit comments

Comments
 (0)