build: restore CI trigger for merge to main (#40) #266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: CI | |
on: | |
push: | |
paths: | |
- 'src/**' | |
- 'tests/**' | |
- '.github/workflows/CI.yml' | |
- 'pyproject.toml' | |
- 'docs/**' | |
pull_request: | |
branches: | |
- main | |
- 'release**' | |
paths: | |
- 'src/**' | |
- 'tests/**' | |
- '.github/workflows/CI.yml' | |
- 'pyproject.toml' | |
- 'docs/**' | |
jobs: | |
test: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macOS-latest] | |
python-version: ['3.10', '3.11'] | |
steps: | |
- uses: actions/checkout@v3 | |
# Set up Python environment | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
# Setup macOS | |
- name: Setup macOS | |
if: runner.os == 'macOS' | |
run: brew install libomp | |
# Install Poetry | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org | python - | |
# Add Poetry to PATH | |
- name: Add Poetry to PATH | |
run: echo "$HOME/.local/bin" >> $GITHUB_PATH | |
# Configure poetry | |
- name: Configure poetry | |
run: poetry config virtualenvs.in-project true | |
# Cache Poetry dependencies | |
- name: Cache Poetry dependencies | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: | | |
${{ runner.os }}-poetry-${{ matrix.python-version }}- | |
${{ runner.os }}-poetry- | |
${{ runner.os }}- | |
# Ensure cache is healthy | |
- name: Ensure cache is healthy | |
if: steps.cache.outputs.cache-hit == 'true' | |
shell: bash | |
run: poetry run pip --version > /dev/null 2>&1 || { echo "Cache is stale, clearing cache and exiting." && rm -rf .venv && exit 1; } | |
# Upgrade pip | |
- name: Upgrade pip | |
shell: bash | |
run: poetry run python -m pip install --upgrade pip | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
poetry install | |
# Install dtaidistance | |
- name: Install dtaidistance | |
run: | | |
if [ "${{ matrix.python-version }}" != "3.10" ] && \ | |
[ "${{ matrix.python-version }}" != "3.11" ]; then \ | |
poetry run python -m pip install dtaidistance | |
fi | |
# Run pre-commit hooks | |
#- name: Run pre-commit hooks | |
# uses: pre-commit/[email protected] | |
# Run tests | |
- name: Test with pytest | |
run: | | |
poetry run python -m pytest tests -vv --cov=src/ \ | |
--cov-report term --junitxml=report.xml | |
# --cov-fail-under=${{ secrets.TEST_COVERAGE_THRESHOLD }} \ | |
# Generate coverage report | |
- name: Generate coverage report | |
run: | | |
poetry run python -m coverage xml | |
poetry run pycobertura show coverage.xml --format html --output coverage.html | |
if: always() | |
# Convert coverage report to markdown | |
- name: Install pandoc on macOS | |
if: runner.os == 'macOS' && always() | |
run: | | |
brew install pandoc | |
- name: Convert coverage report to markdown (macOS) | |
if: runner.os == 'macOS' && always() | |
run: | | |
pandoc coverage.html -t gfm -o coverage.md | |
- name: Convert coverage report to markdown (Ubuntu) | |
uses: docker://pandoc/core:3.1 | |
if: runner.os == 'Linux' && always() | |
with: | |
args: "coverage.html -t gfm -o coverage.md" | |
# Generate concise coverage report | |
- name: Generate concise coverage report | |
if: always() | |
run: | | |
if [[ -f "coverage.md" ]]; then | |
sed -n '/####/q;p' coverage.md > coverage_concise.md | |
if grep -q "<div>" coverage_concise.md; then | |
echo "</div>" >> coverage_concise.md | |
else | |
echo "Warning: No opening <div> tag found in coverage_concise.md." | |
fi | |
else | |
echo "Error: coverage.md file not found." | |
exit 1 | |
fi | |
# Retrieve PR number to publish coverage report to | |
- name: Retrieve PR number to publish coverage report to | |
uses: jwalton/gh-find-current-pr@v1 | |
id: finder | |
if: always() | |
with: | |
state: all | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Add coverage report to PR | |
#- name: Add coverage report to PR | |
# uses: marocchino/sticky-pull-request-comment@v2 | |
# if: always() | |
# with: | |
# number: ${{ steps.finder.outputs.pr }} | |
# recreate: true | |
# path: coverage_concise.md | |
# Upload coverage report | |
#- name: Upload coverage report | |
# uses: actions/upload-artifact@v2 | |
# with: | |
# name: coverage | |
# path: coverage.md | |
# Publish coverage report to PR | |
#- name: Publish coverage to PR | |
# uses: codecov/codecov-action@v3 | |
# with: | |
# token: ${{ secrets.CODECOV_TOKEN }} | |
# fail_ci_if_error: true | |
# verbose: true | |
# commitlint: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# with: | |
# fetch-depth: 0 | |
# - uses: wagoid/commitlint-github-action@v4 | |
docs: | |
name: Test docs build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: 3.8 | |
- name: Install Poetry | |
run: | | |
curl -sSL https://install.python-poetry.org | python - | |
# Add Poetry to PATH | |
- name: Add Poetry to PATH | |
run: echo "$HOME/.local/bin" >> $GITHUB_PATH | |
# Cache Poetry dependencies | |
- name: Cache Poetry dependencies | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: | | |
${{ runner.os }}-poetry- | |
${{ runner.os }}- | |
# Configure poetry | |
- name: Configure poetry | |
run: poetry config virtualenvs.in-project true | |
# Install dependencies using poetry | |
- name: Install dependencies | |
run: | | |
poetry install | |
# Install Sphinx | |
- name: Install Sphinx | |
run: poetry add sphinx | |
# Build sphinx documentation | |
- name: Build sphinx documentation | |
run: | | |
cd docs | |
poetry run make clean | |
poetry run make html --debug --jobs 2 SPHINXOPTS="-W -v" | |
# Upload built docs | |
- name: Upload built docs | |
uses: actions/upload-artifact@v2 | |
with: | |
name: docs-results-${{ runner.os }} | |
path: docs/build/html/ | |
# Use always() to always run this step to publish test results when there are test failures | |
if: success() |