Skip to content

Merge changes from paper plots branch back to main branch while ignoring files which are not required #166

Merge changes from paper plots branch back to main branch while ignoring files which are not required

Merge changes from paper plots branch back to main branch while ignoring files which are not required #166

Workflow file for this run

name: CI Pipeline
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
permissions:
contents: write
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to support dependency checks
ref: ${{ github.head_ref || github.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Setup Python environment with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install --group dev
- name: Check for dependency changes
id: deps
run: |
# Determine if the event is a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "PR detected. Comparing with main branch."
# Fetch the main branch
git fetch origin main
# Compare the PR branch with main
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
else
echo "Push detected. Comparing with previous commit."
# For push events, compare with the previous commit
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
fi
echo "Changed files: $CHANGED_FILES"
# Check if pyproject.toml has changed
if echo "$CHANGED_FILES" | grep -qE '(^|/)pyproject\.toml$'; then
echo "dependencies-changed=true" >> $GITHUB_ENV
else
echo "dependencies-changed=false" >> $GITHUB_ENV
fi
- name: Generate requirements.txt
if: env.dependencies-changed == 'true'
run: |
source .venv/bin/activate
uv pip freeze > requirements.txt
- name: Commit and push updated requirements.txt
if: |
env.dependencies-changed == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add requirements.txt
git diff --cached --exit-code || git commit -m "Update requirements.txt [skip ci]"
git push || echo "Nothing to push"
- name: Run Black (auto-reformat)
run: |
source .venv/bin/activate
black .
- name: Run isort (auto-reformat)
run: |
source .venv/bin/activate
isort .
- name: Run pytest and generate coverage report
run: |
source .venv/bin/activate
pytest --cov-report=term-missing:skip-covered --cov=codes test/ --cov-report=xml:coverage.xml
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml # Path to the coverage XML file, adjust if necessary
fail_ci_if_error: true # Optional, ensures the CI fails if Codecov upload fails
docs:
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main')
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history if necessary
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Setup Python environment with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install --group dev
- name: Generate API Documentation with Sphinx
run: |
source .venv/bin/activate
sphinx-apidoc -o docs/ codes
- name: Build HTML with Sphinx
run: |
source .venv/bin/activate
sphinx-build -b html docs/ docs/_build
- name: Deploy Sphinx API docs to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build
publish_branch: gh-pages
user_name: "GitHub Actions"
user_email: "actions@github.com"