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 19, 2024
1 parent f90dc24 commit 6010aaf
Show file tree
Hide file tree
Showing 113 changed files with 7,494 additions and 5,996 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/[email protected]
- 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'
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ define deactivate_virtualenv
fi
endef

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


# Install dependencies
Expand All @@ -48,6 +48,8 @@ install:
$(call install_poetry) && \
poetry install --with dev --all-extras

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

install/all: install
exit_code=0; \
Expand All @@ -70,7 +72,7 @@ lint:
$(call run_checks,.)

# Development commands
build:
build:
$(ACTIVATE) && poetry build

run: lint
Expand All @@ -79,8 +81,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 All @@ -97,6 +99,6 @@ clean:
rm -rf docs/_build
rm -rf dist/

# make bump/integrations VERSION=0.3.2
# make bump/integrations VERSION=0.3.2
bump/integrations:
./scripts/bump-all.sh $(VERSION)
./scripts/bump-all.sh $(VERSION)
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/
400 changes: 224 additions & 176 deletions integrations/argocd/poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion integrations/argocd/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 Expand Up @@ -100,4 +101,4 @@ exclude = '''
|Dockerfile
|\.venv
)/
'''
'''
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/
Loading

0 comments on commit 6010aaf

Please sign in to comment.