Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .clabot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contributors": "https://api.infrasonar.com/contributors"
}
38 changes: 18 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
permissions:
contents: read
name: CI
on:
push:
branches:
- main
- main
pull_request:
branches:
- main
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pycodestyle pyright
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with PyCodeStyle
run: |
find . -name \*.py -exec pycodestyle {} +
- name: Type checking with PyRight
run: |
pyright
- uses: actions/checkout@v6
- name: Set up Python 3.14
uses: actions/setup-python@v6
with:
python-version: 3.14
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pycodestyle pyright
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with PyCodeStyle
run: |
find . -name \*.py -exec pycodestyle {} +
- name: Type checking with PyRight
run: |
pyright
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v6

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/infrasonar/selenium-probe

Expand All @@ -38,7 +38,7 @@ jobs:
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v7
env:
PAT: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v6

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/infrasonar/selenium-probe

Expand All @@ -39,7 +39,7 @@ jobs:
run: echo "VERSION=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v7
env:
PAT: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/infrasonar/python:3.12.9
FROM ghcr.io/infrasonar/python:3.14.3
ADD . /code
WORKDIR /code
RUN pip install --no-cache-dir -r requirements.txt
Expand Down
123 changes: 64 additions & 59 deletions lib/check/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
from selenium import webdriver
from libprobe.asset import Asset
from libprobe.check import Check
from libprobe.exceptions import IncompleteResultException, Severity
from ..module import get_module

Expand All @@ -10,70 +11,74 @@
COMMAND_EXECUTER = os.getenv("COMMAND_EXECUTER", "http://localhost:4444")


async def check_selenium(
asset: Asset,
asset_config: dict,
config: dict) -> dict:
exc = None
items = []
password = asset_config.get('password')
secret = asset_config.get('secret')
file_ids: list[int] = config.get('file_ids', [])
for file_id in file_ids:
async with _lock:
if password:
os.environ['PASSWORD'] = password
if secret:
os.environ['SECRET'] = secret
try:
try:
module = await get_module(file_id=file_id)
except Exception as e:
exc = e
continue
class CheckSelenium(Check):
key = 'selenium'
unchanged_eol = 0

options = webdriver.ChromeOptions()
driver = webdriver.Remote(
options=options,
command_executor=COMMAND_EXECUTER)
@staticmethod
async def run(asset: Asset, local_config: dict, config: dict) -> dict:

exc = None
items = []
password = local_config.get('password')
secret = local_config.get('secret')
file_ids: list[int] = config.get('file_ids', [])
for file_id in file_ids:
async with _lock:
if password:
os.environ['PASSWORD'] = password
if secret:
os.environ['SECRET'] = secret
try:
item = module.export.run(name=str(file_id), driver=driver)
except Exception as e:
# When `run() is correct, it can't fail` as potential
# errors will be part of the result
msg = str(e) or type(e).__name__
raise Exception(
f'The `export` in file ID {file_id} is not a valid '
f'subclass of `TestBase` (error: {msg})')
else:
item['file_id'] = file_id # int
items.append(item)
finally:
os.environ.pop('PASSWORD', None)
os.environ.pop('SECRET', None)
try:
module = await get_module(file_id=file_id)
except Exception as e:
exc = e
continue

options = webdriver.ChromeOptions()
driver = webdriver.Remote(
options=options,
command_executor=COMMAND_EXECUTER)

try:
item = module.export.run(name=str(file_id),
driver=driver)
except Exception as e:
# When `run() is correct, it can't fail` as potential
# errors will be part of the result
msg = str(e) or type(e).__name__
raise Exception(
f'The `export` in file ID {file_id} is not a valid'
f' subclass of `TestBase` (error: {msg})')
else:
item['file_id'] = file_id # int
items.append(item)
finally:
os.environ.pop('PASSWORD', None)
os.environ.pop('SECRET', None)

if exc is not None and not items:
raise exc
if exc is not None and not items:
raise exc

total = {
'name': 'total', # str
'success_count': sum(i['success'] for i in items), # int
'failed_count': sum(not i['success'] for i in items), # int
'num_checks': len(items), # int
'total_duration': sum(i['duration'] for i in items), # float
}
total = {
'name': 'total', # str
'success_count': sum(i['success'] for i in items), # int
'failed_count': sum(not i['success'] for i in items), # int
'num_checks': len(items), # int
'total_duration': sum(i['duration'] for i in items), # float
}

state = {
'total': [total], # single item
'tests': items, # multi item
}
state = {
'total': [total], # single item
'tests': items, # multi item
}

if exc is not None:
msg = str(exc) or type(exc).__name__
raise IncompleteResultException(
msg=msg,
result=state,
severity=Severity.LOW)
if exc is not None:
msg = str(exc) or type(exc).__name__
raise IncompleteResultException(
msg=msg,
result=state,
severity=Severity.LOW)

return state
return state
2 changes: 1 addition & 1 deletion lib/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# Function to dynamically import a module given its full path
def import_module_from_path(path):
def import_module_from_path(path: str):
# Create a module spec from the given path
spec = importlib.util.spec_from_file_location("module_name", path)
if spec is None or spec.loader is None:
Expand Down
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from libprobe.probe import Probe
from lib.check.selenium import check_selenium
from lib.check.selenium import CheckSelenium
from lib.version import __version__ as version
from lib.probe import register_probe

if __name__ == '__main__':
checks = {
'selenium': check_selenium
}
checks = (
CheckSelenium,
)

probe = Probe("selenium", version, checks)
register_probe(probe)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
libprobe==1.0.1
libprobe==2.0.6
infrasonar_selenium==1.0.2
Loading