Skip to content

Commit

Permalink
Config unit tests for CI (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Rockman <ebuschang@gmail.com>
  • Loading branch information
mikealfare and emmyoop authored Jan 17, 2024
1 parent f81e17e commit 3929ed2
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240112-230236.yaml
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 25 additions & 0 deletions .github/actions/publish-results/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 18 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ testpaths = [
"tests/functional",
"tests/unit",
]
color = true
csv = "results.csv"

0 comments on commit 3929ed2

Please sign in to comment.