Skip to content

Commit 08895f4

Browse files
committed
Fix test CI/CD
1 parent a4a59a7 commit 08895f4

File tree

6 files changed

+104
-14
lines changed

6 files changed

+104
-14
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
2+
3+
name: cti-python-stix2 release
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python 3.12
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.12
19+
- name: Install and update essential dependencies
20+
run: |
21+
pip install -U pip setuptools
22+
pip install tox-gh-actions
23+
pip install codecov
24+
- name: Test with Tox
25+
run: |
26+
tox
27+
- name: Upload coverage information to Codecov
28+
uses: codecov/[email protected]
29+
with:
30+
token: ${{ secrets.CODECOV_TOKEN }}
31+
fail_ci_if_error: false # optional (default = false)
32+
verbose: true # optional (default = false)
33+
- name: Upload package artifact
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: python-package-distributions
37+
path: dist/
38+
39+
publish-to-pypi:
40+
runs-on: ubuntu-latest
41+
needs: build
42+
43+
permissions:
44+
id-token: write
45+
46+
steps:
47+
- name: Download dist files
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: python-package-distributions
51+
path: dist/
52+
53+
- name: Publish to PyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
with:
56+
skip-existing: true

.github/workflows/python-ci-tests.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
22

33
name: cti-python-stix2 test harness
4-
on: [push, pull_request]
4+
on:
5+
push:
6+
pull_request:
57

68
jobs:
7-
build:
9+
test:
810

911
runs-on: ubuntu-latest
1012
strategy:
1113
matrix:
12-
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
14+
python-version: ['3.9', '3.10', '3.11', '3.12']
1315

1416
name: Python ${{ matrix.python-version }} Build
1517
steps:
@@ -26,9 +28,30 @@ jobs:
2628
- name: Test with Tox
2729
run: |
2830
tox
29-
- name: Upload coverage information to Codecov
30-
uses: codecov/[email protected]
31+
- name: Upload package artifact
32+
if: ${{ matrix.python-version == '3.12' }}
33+
uses: actions/upload-artifact@v4
3134
with:
32-
token: ${{ secrets.CODECOV_TOKEN }}
33-
fail_ci_if_error: false # optional (default = false)
34-
verbose: true # optional (default = false)
35+
name: python-package-distributions
36+
path: dist/
37+
38+
publish-to-test-pypi:
39+
runs-on: ubuntu-latest
40+
needs: test
41+
42+
permissions:
43+
id-token: write
44+
45+
steps:
46+
- name: Download dist files
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: python-package-distributions
50+
path: dist/
51+
52+
- name: Publish to Test PyPI
53+
if: ${{ github.event_name == 'push' }}
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
with:
56+
skip-existing: true
57+
repository-url: https://test.pypi.org/legacy/

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.4.0
3+
rev: v4.5.0
44
hooks:
55
- id: trailing-whitespace
66
- id: check-merge-conflict
@@ -9,7 +9,7 @@ repos:
99
hooks:
1010
- id: add-trailing-comma
1111
- repo: https://github.com/PyCQA/flake8
12-
rev: 3.8.4
12+
rev: 7.0.0
1313
hooks:
1414
- id: flake8
1515
name: Check project styling

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
from codecs import open
3+
from importlib import metadata
34
import os.path
5+
import sys
46

57
from setuptools import find_packages, setup
68

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

2426

27+
try:
28+
metadata.version("stix2")
29+
sys.exit("Error: 'stix2' is installed. Uninstall it before proceeding.")
30+
except metadata.PackageNotFoundError:
31+
pass
32+
33+
2534
setup(
2635
name='misp-lib-stix2',
2736
version=get_version(),

stix2/test/v21/test_datastore_filesystem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def test_filesystem_source_bad_stix_file(fs_source, bad_stix_files):
151151
except STIXError as e:
152152
assert "Can't parse object with no 'type' property" in str(e)
153153

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

170171
os.remove(filepath)
171172

173+
172174
def test_filesystem_sink_add_pretty_false(fs_sink, fs_source):
173175
"""Test adding a STIX object with pretty=False."""
174176
camp1 = stix2.v21.Campaign(

tox.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py38,py39,py310,py311,py312,packaging,pre-commit-check
2+
envlist = py39,py310,py311,py312,packaging,pre-commit-check
33

44
[testenv]
55
deps =
@@ -18,6 +18,7 @@ passenv = GITHUB_*
1818

1919
[testenv:packaging]
2020
deps =
21+
setuptools
2122
twine
2223
commands =
2324
python setup.py sdist bdist_wheel --universal
@@ -31,8 +32,7 @@ commands =
3132

3233
[gh-actions]
3334
python =
34-
3.8: py38
3535
3.9: py39
3636
3.10: py310
37-
3.11: py311, packaging, pre-commit-check
38-
3.12: py312
37+
3.11: py311
38+
3.12: py312, packaging, pre-commit-check

0 commit comments

Comments
 (0)