Skip to content

Adding documentation and Examples to the repo [version:1.0.4] #316

Adding documentation and Examples to the repo [version:1.0.4]

Adding documentation and Examples to the repo [version:1.0.4] #316

Workflow file for this run

name: crow-ci
on:
push:
branches:
- main
paths-ignore:
- "docs/**/*.md"
- "*.md"
pull_request:
branches:
- "*"
paths-ignore:
- "docs/**/*.md"
- "*.md"
types:
- opened
- synchronize
- reopened
- ready_for_review
env:
CONDA_ENV: crow
CACHE_VERSION: 1
jobs:
quick-validation:
name: Quick validation (Lint + Tests)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
python-version: 3.12
activate-environment: ${{ env.CONDA_ENV }}
use-mamba: true
- name: Verify environment
run: |
conda info
conda list
- name: Check code formatting with black
run: conda run -n ${{ env.CONDA_ENV }} black --check --diff crow tests
- name: Check import order with isort
run: conda run -n ${{ env.CONDA_ENV }} isort --check --diff crow tests
- name: Run tests with pytest + coverage
run: |
conda run -n ${{ env.CONDA_ENV }} pip install coverage
conda run -n ${{ env.CONDA_ENV }} coverage run -m pytest -v --maxfail=1 --disable-warnings
conda run -n ${{ env.CONDA_ENV }} coverage report -m
conda run -n ${{ env.CONDA_ENV }} coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
use_oidc: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
check-code-version:
name: Verify code version update
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
# Get current version
- name: Check out the code
uses: actions/checkout@v4
- name: Get version from current branch
id: current_version
run: |
CURRENT_VERSION="$(grep -oP '__version__ = "\K[^"]+' crow/__init__.py)"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "my branch is ${{ github.ref }}"
# Get main version
- name: Checkout the main branch to get its version
uses: actions/checkout@v4
with:
ref: main
- name: Get version from main branch
id: main_version
run: |
if [[ "$(git show origin/main:crow/__init__.py)" == *"__version__"* ]]; then
MAIN_VERSION="$(grep -oP '__version__ = "\K[^"]+' crow/__init__.py)"
else
echo "No version found at main, assuming version 0.0.0"
MAIN_VERSION="0.0.0"
fi
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
- name: Get PR number
id: pr_number
run: |
# Fetch the pull request number from the GitHub context
PR_NUMBER=$(echo $GITHUB_REF | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# Compare new version number
- name: Compare new version number
run: |
IFS=. read -r C1 C2 C3 <<< "$CURRENT_VERSION"
if [ "$MAIN_VERSION" == "1.0.2-1" ]; then MAIN_VERSION="1.0.2"; fi
IFS=. read -r M1 M2 M3 <<< "$MAIN_VERSION"
if [ "$C1" != "$M1" ]; then
GOAL="$((M1 + 1)).0.0"
if [ $C1 -lt $M1 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$C1" != "$((M1 + 1))" ]; then
ERROR=" - Increment should be done by 1: $GOAL"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - When major version is increased, others should be zero: $GOAL"
fi
elif [ "$C2" != "$M2" ]; then
GOAL="$C1.$((M2 + 1)).0"
if [ $C2 -lt $M2 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$C2" != "$((M2 + 1))" ]; then
ERROR=" - Increments should be done by 1: $GOAL"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - When middle version is increased, last number should be zero: $GOAL"
fi
elif [ "$C3" != "$M3" ]; then
GOAL="$C1.$C2.$((M3 + 1))"
if [ $C3 -lt $M3 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - Increments should be done by 1: $GOAL"
fi
else
ERROR=" - Version at crow/__init__.py has not been updated!"
fi
echo "ERROR=$ERROR" >> $GITHUB_ENV
# Update PR title
- name: Get PR title and clean version number from it
env:
TITLE: ${{ github.event.pull_request.title }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_TITLE="${TITLE% [version:*}"
echo "Clean title: $NEW_TITLE"
if [ "$ERROR" == "" ]; then
NEW_TITLE="${NEW_TITLE} [version:$CURRENT_VERSION]"
echo "New title: $NEW_TITLE"
fi
echo "Updating PR #$PR_NUMBER with new title: $NEW_TITLE"
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"title\":\"$NEW_TITLE\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" > /dev/null
- name: Check version update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$ERROR" != "" ]; then
echo "Check failed:"
echo "$ERROR"
exit 1
fi
echo "[ok] Version increased changed!"
crow-matrix:
name: (${{ matrix.os }}, py${{ matrix.python-version }})${{ matrix.coverage && ' + coverage' || '' }}
runs-on: ${{ matrix.os }}-latest
needs: quick-validation
if: >
(github.event_name == 'pull_request' && !github.event.pull_request.draft)
|| (github.event_name == 'push' && github.ref == 'refs/heads/main')
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "macos"]
python-version: ["3.11", "3.12", "3.13"]
include:
- os: ubuntu
python-version: "3.12"
coverage: true
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
activate-environment: ${{ env.CONDA_ENV }}
use-mamba: true
environment-file: environment.yml
- name: Cache Conda env
uses: actions/cache/restore@v4
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('environment.yml') }}-v${{ env.CACHE_VERSION }}
- name: Update environment
if: steps.cache.outputs.cache-hit != 'true'
run: conda env update -n ${{ env.CONDA_ENV }} -f environment.yml
- name: Install test dependencies
run: |
conda run -n ${{ env.CONDA_ENV }} pip install pytest-xdist pytest-cov
- name: Check code formatting with black
run: conda run -n ${{ env.CONDA_ENV }} black --check --diff crow tests
- name: Check import order with isort
run: conda run -n ${{ env.CONDA_ENV }} isort --check --diff crow tests
- name: Run tests
run: |
if [[ "${{ matrix.coverage || false }}" == "true" ]]; then
conda run -n ${{ env.CONDA_ENV }} pytest -vv --runslow --cov crow --cov-report xml --cov-branch -n auto
else
conda run -n ${{ env.CONDA_ENV }} pytest -vv --runslow -n auto
fi
- name: Upload coverage to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
use_oidc: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
doc-valid:
name: Documentation build
runs-on: ubuntu-latest
needs: quick-validation
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV }}
use-mamba: true
environment-file: environment.yml
- name: Install the package
run: conda run -n crow pip install . --no-deps --no-build-isolation
- name: Build the docs
run: conda run -n crow make -C docs/ html