diff --git a/.changes/unreleased/Under the Hood-20240112-230236.yaml b/.changes/unreleased/Under the Hood-20240112-230236.yaml new file mode 100644 index 00000000..1470ac6e --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240112-230236.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Implement unit testing in CI +time: 2024-01-12T23:02:36.630106-05:00 +custom: + Author: mikealfare + Issue: "10" diff --git a/.github/actions/publish-results/action.yml b/.github/actions/publish-results/action.yml new file mode 100644 index 00000000..3b6e1a1f --- /dev/null +++ b/.github/actions/publish-results/action.yml @@ -0,0 +1,25 @@ +name: Publish results + +inputs: + file-name: + description: File type for file name stub (e.g. "unit-tests") + required: true + python-version: + description: Create an environment with the appropriate version of python and hatch installed + required: true + source-file: + description: File to be uploaded + required: true + +runs: + using: "composite" + steps: + - name: Get timestamp + id: timestamp + run: echo "ts=$(date +'%Y-%m-%dT%H_%M_%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts + shell: bash + + - uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.file-name }}_${{ inputs.python-version }}-${{ steps.timestamp.outputs.ts }}.csv + path: ${{ inputs.source-file }} diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml new file mode 100644 index 00000000..649fddb0 --- /dev/null +++ b/.github/actions/setup-environment/action.yml @@ -0,0 +1,18 @@ +name: Setup `hatch` + +inputs: + python-version: + description: Create an environment with the appropriate version of python and hatch installed + required: true + +runs: + using: "composite" + steps: + - name: Set up Python ${{ inputs.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Install hatch + run: python -m pip install hatch + shell: bash diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 00000000..9716b1f5 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,49 @@ +name: Unit Tests + +on: + push: + branches: + - "main" + - "*.latest" + pull_request: + workflow_dispatch: + +permissions: read-all + +# will cancel previous workflows triggered by the same event and for the same ref for PRs or same SHA otherwise +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }} + cancel-in-progress: true + +jobs: + unit: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup environment + uses: ./.github/actions/setup-environment + with: + python-version: ${{ matrix.python-version }} + + - name: Run unit tests + run: hatch run unit-tests + shell: bash + + - name: Publish results + uses: ./.github/actions/publish-results + if: always() + with: + source-file: "results.csv" + file-name: "unit_results" + python-version: ${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index 7a59e8ad..efd6a515 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,3 +119,5 @@ testpaths = [ "tests/functional", "tests/unit", ] +color = true +csv = "results.csv"