Skip to content

Commit

Permalink
Fix test CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
ostefano committed Dec 16, 2024
1 parent a4a59a7 commit a978171
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 13 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/python-ci-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: cti-python-stix2 release
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.12
- name: Install and update essential dependencies
run: |
pip install -U pip setuptools
pip install tox-gh-actions
pip install codecov
- name: Test with Tox
run: |
tox
- name: Upload coverage information to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
runs-on: ubuntu-latest
needs: build

permissions:
id-token: write

steps:
- name: Download dist files
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
35 changes: 28 additions & 7 deletions .github/workflows/python-ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ name: cti-python-stix2 test harness
on: [push, pull_request]

jobs:
build:
test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']

name: Python ${{ matrix.python-version }} Build
steps:
Expand All @@ -26,9 +26,30 @@ jobs:
- name: Test with Tox
run: |
tox
- name: Upload coverage information to Codecov
uses: codecov/[email protected]
- name: Upload package artifact
if: ${{ matrix.python-version == '3.12' }}
uses: actions/upload-artifact@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false # optional (default = false)
verbose: true # optional (default = false)
name: python-package-distributions
path: dist/

publish-to-test-pypi:
runs-on: ubuntu-latest
needs: test

permissions:
id-token: write

steps:
- name: Download dist files
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

- name: Publish to Test PyPI
if: ${{ github.event_name == 'push' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
repository-url: https://test.pypi.org/legacy/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
Expand All @@ -9,7 +9,7 @@ repos:
hooks:
- id: add-trailing-comma
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
rev: 7.0.0
hooks:
- id: flake8
name: Check project styling
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
from codecs import open
from importlib import metadata
import os.path
import sys

from setuptools import find_packages, setup

Expand All @@ -22,6 +24,13 @@ def get_long_description():
return f.read()


try:
metadata.version("stix2")
sys.exit("Error: 'stix2' is installed. Uninstall it before proceeding.")
except metadata.PackageNotFoundError:
pass


setup(
name='misp-lib-stix2',
version=get_version(),
Expand Down
2 changes: 2 additions & 0 deletions stix2/test/v21/test_datastore_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_filesystem_source_bad_stix_file(fs_source, bad_stix_files):
except STIXError as e:
assert "Can't parse object with no 'type' property" in str(e)


def test_filesystem_sink_add_pretty_true(fs_sink, fs_source):
"""Test adding a STIX object with pretty=True."""
camp1 = stix2.v21.Campaign(
Expand All @@ -169,6 +170,7 @@ def test_filesystem_sink_add_pretty_true(fs_sink, fs_source):

os.remove(filepath)


def test_filesystem_sink_add_pretty_false(fs_sink, fs_source):
"""Test adding a STIX object with pretty=False."""
camp1 = stix2.v21.Campaign(
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38,py39,py310,py311,py312,packaging,pre-commit-check
envlist = py39,py310,py311,py312,packaging,pre-commit-check

[testenv]
deps =
Expand All @@ -18,6 +18,7 @@ passenv = GITHUB_*

[testenv:packaging]
deps =
setuptools
twine
commands =
python setup.py sdist bdist_wheel --universal
Expand All @@ -31,8 +32,7 @@ commands =

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311, packaging, pre-commit-check
3.12: py312
3.11: py311
3.12: py312, packaging, pre-commit-check

0 comments on commit a978171

Please sign in to comment.