Skip to content
Open
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
44 changes: 44 additions & 0 deletions .github/actions/test-with-poetry/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test with poetry
description: Test an automation module with Poetry project manager

inputs:
module:
description: "The module to test"
required: true

runs:
using: "composite"
steps:
- name: Install Poetry
shell: bash
run: |
pip install poetry
poetry config virtualenvs.in-project true

- name: Install Dependencies
id: install-dependencies
shell: bash
run: |
poetry install
working-directory: ${{ inputs.module }}

- name: Execute Black
uses: psf/black@stable
with:
options: "--check --verbose"
src: ./"${{ inputs.module }}"

- name: Execute Mypy
shell: bash
run: |
poetry run pip install mypy
mkdir -p .mypy_cache
poetry run mypy --install-types --non-interactive --ignore-missing-imports --show-column-numbers --hide-error-context .
working-directory: "${{ inputs.module }}"

- name: Execute Python tests
id: execute-tests
shell: bash
run: |
poetry run python -m pytest --junit-xml=junit.xml --cov-report term --cov-report xml:coverage.xml --cov . --cov-config pyproject.toml
working-directory: "${{ inputs.module }}"
44 changes: 44 additions & 0 deletions .github/actions/test-with-uv/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test with uv
description: Test an automation module with uv project manager

inputs:
module:
description: "The module to test"
required: true

runs:
using: "composite"
steps:
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
activate-environment: true

- name: Install Dependencies
id: install-dependencies
shell: bash
run: |
uv sync --frozen
working-directory: ${{ inputs.module }}

- name: Execute Black
uses: psf/black@stable
with:
options: "--check --verbose"
src: ./"${{ inputs.module }}"

- name: Execute Mypy
shell: bash
run: |
uv pip install mypy
mkdir -p .mypy_cache
uv run mypy --install-types --non-interactive --ignore-missing-imports --show-column-numbers --hide-error-context .
working-directory: ${{ inputs.module }}

- name: Execute Python tests
id: execute-tests
shell: bash
run: |
uv run pytest --junit-xml=junit.xml --cov-report term --cov-report xml:coverage.xml --cov . --cov-config pyproject.toml
working-directory: ${{ inputs.module }}
64 changes: 29 additions & 35 deletions .github/workflows/build-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Modules

on:
pull_request:
types: [ opened, synchronize, reopened ]
types: [opened, synchronize, reopened]
push:
branches:
- main
Expand All @@ -15,7 +15,6 @@ env:
IMAGE_PREFIX_NAME: sekoia-io

jobs:

find-modules:
name: Find modules in repo
runs-on: ubuntu-latest
Expand Down Expand Up @@ -59,37 +58,32 @@ jobs:
uses: actions/setup-python@v4
id: setup-python
with:
python-version: '3.11'

- name: Install Poetry
run: |
pip install poetry
poetry config virtualenvs.in-project true
python-version: "3.11"

- name: Install Dependencies
id: install-dependencies
- name: Detect package manager
id: detect-pm
run: |
poetry install
working-directory: ${{ matrix.module }}
if [ -f "${MODULE_PATH}/uv.lock" ]; then
echo "package_manager=uv" >> $GITHUB_OUTPUT
echo "Detected uv project"
else
echo "package_manager=poetry" >> $GITHUB_OUTPUT
echo "Defaulting to Poetry"
fi
env:
MODULE_PATH: ${{ matrix.module }}

- name: Execute Black
uses: psf/black@stable
- name: Test with Poetry
if: steps.detect-pm.outputs.package_manager == 'poetry'
uses: ./.github/actions/test-with-poetry
with:
options: "--check --verbose"
src: ./"${{ matrix.module }}"
module: ${{ matrix.module }}

- name: Execute Mypy
run: |
poetry run pip install mypy
mkdir -p .mypy_cache
poetry run mypy --install-types --non-interactive --ignore-missing-imports --show-column-numbers --hide-error-context .
working-directory: "${{ matrix.module }}"

- name: Execute Python tests
id: execute-tests
run: |
poetry run python -m pytest --junit-xml=junit.xml --cov-report term --cov-report xml:coverage.xml --cov . --cov-config pyproject.toml
working-directory: "${{ matrix.module }}"
- name: Test with uv
if: steps.detect-pm.outputs.package_manager == 'uv'
uses: ./.github/actions/test-with-uv
with:
module: ${{ matrix.module }}

- name: Upload Event
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -192,13 +186,13 @@ jobs:
if: always()

steps:
- name: Success
if: ${{ !(contains(needs.*.result, 'failure')) || needs.find-modules.outputs.matrix == '[]' }}
run: exit 0
- name: Failure
if: ${{ contains(needs.*.result, 'failure') && needs.find-modules.outputs.matrix != '[]' }}
run: |
exit 1
- name: Success
if: ${{ !(contains(needs.*.result, 'failure')) || needs.find-modules.outputs.matrix == '[]' }}
run: exit 0
- name: Failure
if: ${{ contains(needs.*.result, 'failure') && needs.find-modules.outputs.matrix != '[]' }}
run: |
exit 1

deploy-module:
name: Deploy modules
Expand Down