Skip to content

Commit

Permalink
Updated to CI/CD.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrichardwebster committed Nov 20, 2024
1 parent 0a565ba commit 6c6324c
Show file tree
Hide file tree
Showing 140 changed files with 3,316 additions and 3,986 deletions.
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# :auto shared:
*.rst conflict-marker-size=79
**.pt filter=lfs diff=lfs merge=lfs -text
**.pth filter=lfs diff=lfs merge=lfs -text
**.pkl filter=lfs diff=lfs merge=lfs -text
**.png filter=lfs diff=lfs merge=lfs -text
**.jpg filter=lfs diff=lfs merge=lfs -text
**.jpeg filter=lfs diff=lfs merge=lfs -text
**.tiff filter=lfs diff=lfs merge=lfs -text
**.bin filter=lfs diff=lfs merge=lfs -text
**.tiff filter=lfs diff=lfs merge=lfs -text
**.npy filter=lfs diff=lfs merge=lfs -text
# :auto shared:
37 changes: 37 additions & 0 deletions .github/actions/build-stage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "build-stage"
description: "Setup user python environment with poetry and enable caching."
runs:
using: "composite"
steps:
- name: Install Git LFS
run: |
apt-get -qq update
apt-get -qq install -y git-lfs
shell: bash
- name: Environment Variables
run: |
export PIP_CACHE_DIR="$GITHUB_WORKSPACE/.cache/pip"
export POETRY_CACHE_DIR="$GITHUB_WORKSPACE/.cache/poetry"
echo "${HOME}/.local/bin" >> $GITHUB_PATH
shell: bash
- name: Setup Poetry
run: |
pip install --root-user-action=ignore --upgrade pip -q
pip install --root-user-action=ignore --user -U poetry -q
shell: bash
- name: Configure Poetry
run: |
poetry config --local virtualenvs.in-project true
poetry config --local virtualenvs.prefer-active-python true
shell: bash
- name: Versions of things used here
run: |
python --version
poetry -q run python --version
pip --version
poetry --version
poetry check
shell: bash
- name: Install Environment
run: poetry install --sync --only main,linting,tests,docs
shell: bash
10 changes: 10 additions & 0 deletions .github/actions/quality-stage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "quality-stage"
description: "Setup user python environment with poetry and enable caching."
runs:
using: "composite"
steps:
- name: Setup Environment
uses: ./.github/actions/build-stage
- name: Synchronize Poetry Environment
run: poetry install --sync --only main,linting,tests
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/test-stage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "test-stage"
description: "Setup user python environment with poetry and enable caching."

inputs:
extras:
description: "Parameterize the 'extras' required for testing"
required: true
default: ""

runs:
using: "composite"
steps:
- name: Setup Environment
uses: ./.github/actions/build-stage
- name: Synchronize Poetry Environment
run: poetry install --sync --only main,linting,tests --extras "${{ inputs.extras }}"
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,23 @@ jobs:
if: github.repository_owner == 'XAITK'
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Cache local python environment artifacts for the current python version
# and poetry lockfile hash.
- uses: actions/cache@v3
- uses: actions/cache@v4
id: env-cache
with:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: |
~/.cache/pypoetry/virtualenvs/
~/.local
~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}

- name: Setup Environment
# Using non-relative path for correct behavior when used as a remote
# workflow.
uses: Kitware/SMQTK-Core/.github/actions/python-poetry-setup@master
uses: ./.github/actions/build-stage

# Ensure there is alignment with the tag reference and the reported
# version of the package
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: CI Unittests
name: Quality Assurance

# Controls when the action will run.
on:
Expand All @@ -26,7 +26,7 @@ defaults:
# NOTE: Github actions does not support anchors apparently. Forgive duplication of job
# steps.
jobs:
lint:
mypy:
runs-on: ubuntu-latest
container: python:3.9
steps:
Expand All @@ -42,17 +42,15 @@ jobs:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: |
~/.cache/pypoetry/virtualenvs/
~/.local
path: ~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-a-public-action-in-a-subdirectory
uses: Kitware/SMQTK-Core/.github/actions/python-poetry-setup@master
- name: Lint with Flake8
run: poetry run flake8
uses: ./.github/actions/quality-stage
- name: Typecheck with MyPy
run: poetry run mypy --config-file pyproject.toml src/ tests/
shell: bash

typecheck:
ruff-lint:
runs-on: ubuntu-latest
container: python:3.9
steps:
Expand All @@ -68,32 +66,17 @@ jobs:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: |
~/.cache/pypoetry/virtualenvs/
~/.local
path: ~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-a-public-action-in-a-subdirectory
uses: Kitware/SMQTK-Core/.github/actions/python-poetry-setup@master
- name: Typecheck with MyPy
run: poetry run mypy
uses: ./.github/actions/quality-stage
- name: Lint with Ruff
run: poetry run ruff check --config pyproject.toml
shell: bash

unittests:
ruff-format:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9","3.10","3.11","3.12"]
# Extras for included, optional plugin support (space-separated lists)
opt-extra: [
"", # no extras
"tools",
]
# We want all python versions tested even if one of them happens to fail
fail-fast: false

container: python:${{ matrix.python-version }}

# Steps represent a sequence of tasks that will be executed as part of the job
container: python:3.9
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
Expand All @@ -107,30 +90,34 @@ jobs:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: |
~/.cache/pypoetry/virtualenvs/
~/.local
key: python-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}-${{ matrix.opt-extra }}
restore-keys: |
python-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
path: ~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-a-public-action-in-a-subdirectory
uses: Kitware/SMQTK-Core/.github/actions/python-poetry-setup@master
- name: Optionally install additional requirements
env:
OPT_EXTRA: ${{ matrix.opt-extra }}
run: |
if [[ -n "$OPT_EXTRA" ]]
then
poetry install --extras "$OPT_EXTRA"
fi
- name: Run Unittests
run: poetry run pytest
uses: ./.github/actions/quality-stage
- name: Format check with Ruff
run: poetry run ruff format --config pyproject.toml --check
shell: bash

- name: CodeCov report submission
uses: codecov/codecov-action@v4
sphinx-lint:
runs-on: ubuntu-latest
container: python:3.9
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: coverage.xml
flags: unittests
fetch-depth: 0
# Cache local python environment artifacts for the current python version
# and poetry lockfile hash.
- uses: actions/cache@v4
id: env-cache
with:
# Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident that
# only our python stuff is being captured in this cache (intentional).
path: ~/.cache
key: python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
uses: ./.github/actions/quality-stage
- name: Lint docs with Spinx-lint
run: poetry run sphinx-lint --enable all --disable leaked-markup --max-line-length 120 -i docs/_implementations docs
shell: bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: CI Example Notebooks
# This is a basic workflow to help you get started with Actions

name: Unit Testing

# Controls when the action will run.
on:
Expand All @@ -20,8 +22,55 @@ defaults:
run:
shell: bash

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
# NOTE: Github actions does not support anchors apparently. Forgive duplication of job
# steps.
jobs:
run_notebook:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9","3.10","3.11","3.12"]
# Extras for included, optional plugin support (space-separated lists)
opt-extra: [
"", # no extras
"tools",
]
# We want all python versions tested even if one of them happens to fail
fail-fast: false

container: python:${{ matrix.python-version }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Cache local python environment artifacts for the current python version
# and poetry lockfile hash.
- uses: actions/cache@v4
id: env-cache
with:
path: |
~/.cache
key: python-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}-${{ matrix.opt-extra }}
restore-keys: |
python-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
uses: ./.github/actions/test-stage
with:
extras: "${{ matrix.opt-extra }}"
- name: Unit Testing
run: poetry run pytest
- name: CodeCov report submission
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: coverage.xml
flags: unittests
notebooks:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -52,53 +101,35 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0

# Cache local python environment artifacts for the current python version
# and poetry lockfile hash.
- uses: actions/cache@v2
id: env-cache
with:
# * Confirmed that the `.local` directory doesn't exist until the
# `pip install --user` is invoked below, so we can be confident
# that only our python stuff is being captured in this cache
# (intentional).
# * *Not* caching the actual virtualenv, just the cached packages for
# installation -- Some packages used in examples have very large
# installation sizes which does not compliment well our limited
# cache GB allowance.
path: |
~/.cache/pypoetry/artifacts/
~/.cache/pypoetry/cache/
~/.local
~/.cache
# Using a different key due to additional things the notebook
# examples ad-hoc install.
key: python-3.9-${{ hashFiles('poetry.lock') }}-Examples
restore-keys: |
python-3.9-${{ hashFiles('poetry.lock') }}
- name: Setup Environment
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-a-public-action-in-a-subdirectory
uses: Kitware/SMQTK-Core/.github/actions/python-poetry-setup@master

- name: Install additional example extras requirements
run: poetry install -E example_deps

uses: ./.github/actions/test-stage
with:
extras: "tools example_deps"
- uses: actions/cache@v2
id: notebook-data-cache
with:
path: |
~/.cache/torch/
~/.cache/
examples/data/
key: python-3.9-${{ hashFiles('poetry.lock') }}-ExampleData-${{ matrix.notebook-file }}
# pretty unique, no restore-keys.

- name: Run Notebook
env:
NOTEBOOK_FILENAME: ${{ matrix.notebook-file }}
run: |
cd examples
poetry run papermill \
--progress-bar \
-k python3 \
--stdout-file - --stderr-file - \
"${NOTEBOOK_FILENAME}" /dev/null
"${{ matrix.notebook-file }}" /dev/null
Loading

0 comments on commit 6c6324c

Please sign in to comment.