diff --git a/.github/actions/run_and_upload_unit_tests/action.yml b/.github/actions/run_and_upload_unit_tests/action.yml new file mode 100644 index 0000000..d7d5ea7 --- /dev/null +++ b/.github/actions/run_and_upload_unit_tests/action.yml @@ -0,0 +1,27 @@ +name: 'Run and upload unit tests' +description: 'Run unit tests using pytest and upload the results as an artifact.' +runs: + using: "composite" + steps: + - name: Get OS version + run: echo "osVersion=$ImageOS" >> "$GITHUB_ENV" + shell: bash + - name: Cache ni.datastore virtualenv + uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + with: + path: ./.venv + key: ni.datastore-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles('./poetry.lock') }} + - name: Install ni.datastore + run: poetry install -v + working-directory: . + shell: bash + - name: Run ni.datastore unit tests and code coverage + run: poetry run pytest ./tests/unit -v --cov=ni.datastore --junitxml=test_results/ni.datastore-${{ env.osVersion }}-py${{ env.pythonVersion }}.xml + working-directory: . + shell: bash + - name: Upload ni.datastore test results + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: test_results_unit_ni.datastore_${{ env.osVersion }}_py${{ env.pythonVersion }} + path: ${{ github.workspace }}/test_results/*.xml + if: always() \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1445022..85fa86a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,8 +9,19 @@ on: workflow_dispatch: jobs: - todo_make_a_ci: - runs-on: ubuntu-latest - steps: - - name: CI Inactive - run: echo "This CI is inactive. Please activate it by removing this job." \ No newline at end of file + check_analyzers: + name: Check analyzers for ni.datastore + uses: ./.github/workflows/check_ni_datastore.yml + check_docs: + name: Check docs for ni.datastore + uses: ./.github/workflows/check_docs.yml + run_unit_tests: + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + name: Run unit tests + uses: ./.github/workflows/run_unit_tests.yml + with: + python-version: ${{ matrix.python-version }} + os: ${{ matrix.os }} diff --git a/.github/workflows/check_docs.yml b/.github/workflows/check_docs.yml new file mode 100644 index 0000000..c603188 --- /dev/null +++ b/.github/workflows/check_docs.yml @@ -0,0 +1,38 @@ +name: Check docs + +on: + workflow_call: + workflow_dispatch: + +jobs: + check_docs: + name: Check docs for ni.datastore + runs-on: ubuntu-latest + defaults: + run: + # Set the working-directory for all steps in this job. + working-directory: . + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Set up Python + uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + id: setup-python + - name: Set up Poetry + uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Check for lock changes + run: poetry check --lock + - name: Cache virtualenv (with docs) + uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + with: + path: .venv + key: ni.datastore-with-docs-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('./poetry.lock') }} + - name: Install nitypes (with docs) + run: poetry install -v --only main,docs + - name: Generate docs + run: poetry run sphinx-build docs docs/_build -b html -W + - name: Upload docs artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: ni.datastore-docs + path: ./docs/_build/ \ No newline at end of file diff --git a/.github/workflows/check_ni_datastore.yml b/.github/workflows/check_ni_datastore.yml new file mode 100644 index 0000000..a8ade82 --- /dev/null +++ b/.github/workflows/check_ni_datastore.yml @@ -0,0 +1,52 @@ +name: Check analyzers + +on: + workflow_call: + workflow_dispatch: + +jobs: + check_analyzers: + name: Check analyzers for ni.datastore + runs-on: ubuntu-latest + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + submodules: true + - name: Set up Python + uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + id: setup-python + - name: Set up Poetry + uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Check for lock changes + run: poetry check --lock + - name: Cache virtualenv + uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + with: + path: ./.venv + key: ni.datastore-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-{{ hashFiles('./poetry.lock') }} + - name: Install ni.datastore + run: | + poetry install -v + - name: Lint + run: poetry run ni-python-styleguide lint + - name: Mypy static analysis (Linux) + run: poetry run mypy + - name: Mypy static analysis (Windows) + run: poetry run mypy --platform win32 + - name: Bandit security checks + run: poetry run bandit -c pyproject.toml -r src/ + - name: Add virtualenv to the path for pyright-action + run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH + - name: Pyright static analysis (Linux) + uses: jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2 + with: + python-platform: Linux + version: PATH + working-directory: . + - name: Pyright static analysis (Windows) + uses: jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2 + with: + python-platform: Windows + version: PATH + working-directory: . diff --git a/.github/workflows/run_unit_tests.yml b/.github/workflows/run_unit_tests.yml new file mode 100644 index 0000000..1bee334 --- /dev/null +++ b/.github/workflows/run_unit_tests.yml @@ -0,0 +1,37 @@ +name: Run unit tests + +on: + workflow_call: + inputs: + python-version: + description: 'The version of Python to use' + default: '' + required: true + type: string + os: + description: 'The name of the OS to use' + required: true + type: string + +jobs: + run_unit_tests: + name: Run unit tests for ni.datastore with ${{ inputs.python-version }} on ${{ inputs.os }} + runs-on: ${{ inputs.os }} + strategy: + # Fail-fast skews the pass/fail ratio and seems to make pytest produce + # incomplete JUnit XML results. + fail-fast: false + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + submodules: true + - name: Set up Python + uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + id: setup-python + with: + python-version: ${{ inputs.python-version }} + - name: Set up Poetry + uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Run and upload unit tests for ni.datastore + uses: ./.github/actions/run_and_upload_unit_tests \ No newline at end of file diff --git a/examples/placeholder.py b/examples/placeholder.py index da732a9..31f1667 100644 --- a/examples/placeholder.py +++ b/examples/placeholder.py @@ -1 +1 @@ -"""Temporary placeholder example.""" \ No newline at end of file +"""Temporary placeholder example.""" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..d420712 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Tests.""" diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e0310a0 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1 @@ +"""Unit tests.""" diff --git a/tests/unit/test_ni_datastore_client.py b/tests/unit/test_ni_datastore_client.py new file mode 100644 index 0000000..974038b --- /dev/null +++ b/tests/unit/test_ni_datastore_client.py @@ -0,0 +1,7 @@ +"""Contains tests to validate the datastore client functionality.""" + +from __future__ import annotations + + +def test__datastore_client() -> None: + assert True