Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.12 and improve CI to test several versions of Python #137

Merged
merged 8 commits into from
Sep 28, 2024
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
68 changes: 52 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,57 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

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

- name: Run Ruff
- name: Check `poetry.lock` consistency
run: |
poetry lock --check

- name: Install linting dependencies
run: |
poetry install --only=lint

- name: Run Ruff (linter)
run: |
poetry run pip install ruff
poetry run ruff check --output-format=github .

- uses: psf/black@stable
- name: Run Ruff (formater)
run: |
poetry run ruff format

- name: Execute Mypy
run: |
poetry run pip install mypy
mkdir -p .mypy_cache
poetry run mypy --install-types --non-interactive --hide-error-context sekoia_automation
poetry run mypy

Test:
Test-matrix:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- '3.10'
- '3.11'
- '3.12'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: |
Expand All @@ -59,20 +76,39 @@ jobs:
poetry run python -m pytest --junit-xml=junit.xml --cov-report term --cov-report xml:coverage.xml --cov=sekoia_automation

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
if: always() && matrix.python-version == 3.12
uses: actions/upload-artifact@v4
with:
name: Unit Test Results
path: junit.xml

- name: Code Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
if: matrix.python-version == 3.12
with:
fail_ci_if_error: true
files: coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}

Test:
runs-on: ubuntu-latest
needs:
- Test-matrix
if: always()
steps:
- name: Successful deploy
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0

- name: Failing deploy
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1

EventFile:
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand All @@ -26,4 +26,4 @@ jobs:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish
poetry publish
43 changes: 7 additions & 36 deletions .github/workflows/test_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,16 @@ jobs:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
steps:
- name: 'Download artifact'
uses: actions/[email protected]
- name: Download and Extract Artifacts
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "Unit Test Results"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/Unit Test Results.zip', Buffer.from(download.data));
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "Event File"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/Event File.zip', Buffer.from(download.data));
- name: "Unzip Artifacts"
run: |
unzip 'Unit Test Results.zip'
unzip 'Event File.zip'
run_id: ${{ github.event.workflow_run.id }}
path: artifacts

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: event.json
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
files: "*.xml"
files: "artifacts/**/*.xml"
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.15.0] - 2024-09-28

### Changed

- Make the minimal Python version to 3.10.
- Replace isort, black and autoflake with Ruff.
- Update Mypy configuration.
- Improve CI to test the package with several versions of Python.
- Update some dependencies to their latest version
(`requests-ratelimiter`, `typer`, `prometheus-client`) and some
devel ones (`pytest`, `pytest-asyncio`, `pytest-env`, `faker`).

## [1.14.1] - 2024-09-10

### Fixed
Expand All @@ -22,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Increase number of retries and time between retries when sending requests
- Increase number of retries and time between retries when sending requests

## [1.13.0] - 2024-04-22

Expand Down Expand Up @@ -71,7 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add heartbeat in triggers
- Add heartbeat in triggers
The heartbeat allows to mark the trigger as not alive if no heartbeat was received for a certain amount of time.
To support this feature triggers must:
- Set the `last_heartbeat_threshold` class attribute to a value greater than 0
Expand Down Expand Up @@ -103,7 +115,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add graceful delay on startup where unhandled errors won't trigger a critical exit
- Add graceful delay on startup where unhandled errors won't trigger a critical exit

## [1.7.0] - 2023-11-07

Expand Down Expand Up @@ -147,7 +159,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improve error message when it is not possible to access the data storage
- Remove `chunk_size` parameter from configuration
- Try to take Intake URL from an environment var first
- Try to take Intake URL from an environment var first

### Fixed

Expand Down
Loading