Skip to content

Commit

Permalink
Add unit test support
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Aug 13, 2024
1 parent 1127315 commit ad12c49
Show file tree
Hide file tree
Showing 113 changed files with 1,183 additions and 111 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Test

on:
pull_request:
workflow_dispatch:

jobs:
detect-changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Get list of changed files
id: changed-files
uses: tj-actions/changed-files@v44.5.2
- name: Set matrix
id: set-matrix
run: |
folders_to_ignore="integrations/*/LICENSE.md|integrations/*/README.md|integrations/*/CONTRIBUTING.md|integrations/*/CHANGELOG.md"
changed_folders=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '^integrations/' | grep -v '^($folders_to_ignore)' | cut -d'/' -f2 | sort | uniq)
if [ -z "$changed_folders" ]; then
changed_folders=""
fi
folders_to_ignore="integrations/|scripts/|assets/|docs/|LICENSE.md|README.md|CONTRIBUTING.md|CHANGELOG.md"
other_changes=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -v '^($folders_to_ignore)' | wc -l)
if [ "$other_changes" -ne 0 ]; then
# Add the root directory to the matrix if there are changes outside the integrations folder
changed_folders=$(echo -e "$changed_folders\n.")
fi
matrix=$(echo "$changed_folders" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
test:
name: ${{ matrix.folder == '.' && '🌊 Ocean Core' || format('🚢 {0}', matrix.folder) }}
needs: detect-changes
runs-on: ubuntu-latest
strategy:
matrix:
folder: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Checkout Repo
uses: actions/checkout@v4
- name: Install dependencies
working-directory: ${{ matrix.folder != '.' && format('integrations/{0}', matrix.folder) || '.' }}
run: |
make install
- name: Test
working-directory: ${{ matrix.folder != '.' && format('integrations/{0}', matrix.folder) || '.' }}
env:
PYTEST_ADDOPTS: --junitxml=junit/test-results-${{ matrix.folder != '.' && format('integrations/{0}', matrix.folder) || '.' }}.xml
run: |
make test
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: ${{ always() }}
with:
report_paths: '**/junit/test-results-**/*.xml'
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define deactivate_virtualenv
fi
endef

.SILENT: install install/all lint build run new test clean bump/integrations bump/single-integration
.SILENT: install install/all test/all lint build run new test clean bump/integrations bump/single-integration


# Install dependencies
Expand All @@ -54,7 +54,8 @@ install:
$(ACTIVATE) && \
$(call install_precommit)


test/all: test
pytest --import-mode=importlib -n auto ./port_ocean/tests ./integrations/*/tests

install/all: install
exit_code=0; \
Expand Down Expand Up @@ -86,8 +87,8 @@ run: lint
new:
$(ACTIVATE) && poetry run ocean new ./integrations --public

test: lint
$(ACTIVATE) && pytest
test:
$(ACTIVATE) && pytest -vv -n auto --ignore-glob=./integrations/* ./port_ocean/tests

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
Expand Down
6 changes: 3 additions & 3 deletions integrations/argocd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ lint:
run:
$(ACTIVATE) && ocean sail

test: lint
$(ACTIVATE) && poetry run pytest
test:
$(ACTIVATE) && poetry run pytest -n auto

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
Expand All @@ -71,4 +71,4 @@ clean:
rm -rf htmlcov
rm -rf .tox/
rm -rf docs/_build
rm -rf dist/
rm -rf dist/
36 changes: 35 additions & 1 deletion integrations/argocd/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integrations/argocd/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mypy = "^1.3.0"
ruff = "^0.0.278"
pylint = "^2.17.4"
towncrier = "^23.6.0"
pytest-xdist = "^3.6.1"

[tool.towncrier]
directory = "changelog"
Expand Down
2 changes: 2 additions & 0 deletions integrations/argocd/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_example() -> None:
assert 1 == 1
2 changes: 2 additions & 0 deletions integrations/argocd/tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_example() -> None:
assert 1 == 1
6 changes: 3 additions & 3 deletions integrations/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ lint:
run:
$(ACTIVATE) && ocean sail

test: lint
$(ACTIVATE) && poetry run pytest
test:
$(ACTIVATE) && poetry run pytest -n auto

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
Expand All @@ -71,4 +71,4 @@ clean:
rm -rf htmlcov
rm -rf .tox/
rm -rf docs/_build
rm -rf dist/
rm -rf dist/
36 changes: 35 additions & 1 deletion integrations/aws/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integrations/aws/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mypy = "^1.3.0"
ruff = "^0.0.278"
pylint = "^2.17.4"
towncrier = "^23.6.0"
pytest-xdist = "^3.6.1"

[tool.towncrier]
directory = "changelog"
Expand Down
2 changes: 2 additions & 0 deletions integrations/aws/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_example() -> None:
assert 1 == 1
2 changes: 2 additions & 0 deletions integrations/aws/tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_example() -> None:
assert 1 == 1
6 changes: 3 additions & 3 deletions integrations/azure-devops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ lint:
run:
$(ACTIVATE) && ocean sail

test: lint
$(ACTIVATE) && poetry run pytest
test:
$(ACTIVATE) && poetry run pytest -n auto

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
Expand All @@ -71,4 +71,4 @@ clean:
rm -rf htmlcov
rm -rf .tox/
rm -rf docs/_build
rm -rf dist/
rm -rf dist/
36 changes: 35 additions & 1 deletion integrations/azure-devops/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integrations/azure-devops/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ruff = "^0.2.2"
pylint = "^2.17.4"
towncrier = "^23.6.0"
types-pyyaml = "^6.0.12.10"
pytest-xdist = "^3.6.1"

[tool.towncrier]
directory = "changelog"
Expand Down
2 changes: 2 additions & 0 deletions integrations/azure-devops/tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_example() -> None:
assert 1 == 1
6 changes: 3 additions & 3 deletions integrations/azure/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ lint:
run:
$(ACTIVATE) && ocean sail

test: lint
$(ACTIVATE) && poetry run pytest
test:
$(ACTIVATE) && poetry run pytest -n auto

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
Expand All @@ -71,4 +71,4 @@ clean:
rm -rf htmlcov
rm -rf .tox/
rm -rf docs/_build
rm -rf dist/
rm -rf dist/
Loading

0 comments on commit ad12c49

Please sign in to comment.