Skip to content

Commit

Permalink
added GitHub workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaasRostock committed Jan 11, 2024
1 parent e943699 commit 9c461f4
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 0 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/_build_and_publish_documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Build and publish documentation

on: workflow_call

env:
DEFAULT_BRANCH: 'release'
#SPHINXOPTS: '-W --keep-going -T'
# ^-- If these SPHINXOPTS are enabled, then be strict about the builds and fail on any warnings

jobs:
build-and-publish-docs:
name: Build and publish documentation
runs-on: ubuntu-latest
steps:
- name: Checkout active branch
uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
- name: Print debugging information
run: |
echo "github.ref:" ${{github.ref}}
echo "github.event_name:" ${{github.event_name}}
echo "github.head_ref:" ${{github.head_ref}}
echo "github.base_ref:" ${{github.base_ref}}
set -x
git rev-parse --abbrev-ref HEAD
git branch
git branch -a
git remote -v
python -V
pip list --not-required
pip list
# Build documentation
- uses: sphinx-doc/github-problem-matcher@master
- name: Build documentation
run: |
cd docs
make html
- name: Clone and cleanup gh-pages branch
run: |
set -x
git fetch
( git branch gh-pages remotes/origin/gh-pages && git clone . --branch=gh-pages _gh-pages/ ) || mkdir _gh-pages
rm -rf _gh-pages/.git/
mkdir -p _gh-pages/branch/
# Delete orphaned branch-folders:
# Go through each subfolder in _gh-pages/branch/
# If it relates to an orphaned branch, delete it.
- name: Delete orphaned branch-folders
run: |
set -x
for brdir in `ls _gh-pages/branch/` ; do
brname=${brdir//--/\/} # replace '--' with '/'
if ! git show-ref remotes/origin/$brname ; then
echo "Removing $brdir"
rm -r _gh-pages/branch/$brdir/
fi
done
# Copy documentation to _gh-pages/ (if push happened on release branch)
- name: Copy documentation to _gh-pages/
if: |
contains(github.ref, env.DEFAULT_BRANCH)
run: |
set -x
# Delete everything under _gh-pages/ that is from the
# primary branch deployment. Excludes the other branches
# _gh-pages/branch-* paths, and not including
# _gh-pages itself.
find _gh-pages/ -mindepth 1 ! -path '_gh-pages/branch*' -delete
rsync -a docs/build/html/ _gh-pages/
# Copy documentation to _gh-pages/branch/$brname (if push happened on any other branch)
# ('/' gets replaced by '--')
- name: Copy documentation to _gh-pages/branch/${{github.ref}}
if: |
!contains(github.ref, env.DEFAULT_BRANCH)
run: |
set -x
#brname=$(git rev-parse --abbrev-ref HEAD)
brname="${{github.ref}}"
brname="${brname##refs/heads/}"
brdir=${brname//\//--} # replace '/' with '--'
rm -rf _gh-pages/branch/${brdir}
rsync -a docs/build/html/ _gh-pages/branch/${brdir}
# Add .nojekyll file
- name: Add .nojekyll file
run: touch _gh-pages/.nojekyll

# Publish: Commit gh-pages branch and publish it to GitHub Pages
- name: Publish documentation
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _gh-pages/
force_orphan: true
54 changes: 54 additions & 0 deletions .github/workflows/_build_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build Package

on: workflow_call

jobs:
build:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install build and twine
run: pip install build twine
- name: Run build
run: python -m build
- name: Run twine check
run: twine check --strict dist/*
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.tar.gz

# build_wheels:
# name: Build wheels for ${{ matrix.platform }}
# needs:
# - black
# - ruff
# - pyright
# - test
# runs-on: ${{ matrix.platform }}
# strategy:
# matrix:
# platform: [ubuntu-latest, macos-latest, windows-latest]
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 1
# lfs: true
# - uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# cache: 'pip' # cache pip dependencies
# - name: Install cibuildwheel
# run: python -m pip install cibuildwheel==2.16
# - name: Build wheels
# run: python -m cibuildwheel --output-dir wheels
# - uses: actions/upload-artifact@v3
# with:
# path: ./wheels/*.whl
50 changes: 50 additions & 0 deletions .github/workflows/_code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Code Quality

on: workflow_call

jobs:
black:
name: black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: '--check --diff'
src: '.'
jupyter: true
version: '==23.12'

ruff:
runs-on: ubuntu-latest
name: ruff
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: pip install -r requirements.txt
- name: Install ruff
run: pip install ruff==0.1.8
- name: Run ruff
run: ruff .

pyright:
runs-on: ubuntu-latest
name: pyright
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip' # cache pip dependencies
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest
- name: Install pyright
run: pip install pyright==1.1.338
- name: Run pyright
run: pyright .
25 changes: 25 additions & 0 deletions .github/workflows/_merge_into_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Merge into release

on:
workflow_call:
secrets:
RELEASE_TOKEN:
required: true

jobs:
merge_into_release:
name: Merge ${{ github.event.ref }} -> release branch
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4
with:
# Fetch the whole history to prevent unrelated history errors
fetch-depth: 0
# The branch you want to checkout (usually equal to `branchtomerge`)
# ref: ${{ github.event.ref }}
- uses: devmasx/[email protected]
with:
type: now
target_branch: release
github_token: ${{ secrets.RELEASE_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/_publish_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish Package to pypi

on:
workflow_call:
secrets:
PYPI_API_TOKEN:
required: true

jobs:
publish:
name: Publish package
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: ./dist/
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/_publish_package_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish Package to testpypi

on:
workflow_call:
secrets:
TEST_PYPI_API_TOKEN:
required: true

jobs:
publish:
name: Publish package
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: ./dist/
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Unit Tests

on: workflow_call

jobs:
test:
name: Test on ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}}
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
toxenv: linux
- runner: windows-latest
toxenv: windows
python:
- version: '3.9'
toxenv: 'py39'
- version: '3.10'
toxenv: 'py310'
- version: '3.11'
toxenv: 'py311'
- version: '3.12'
toxenv: 'py312'
steps:
- uses: actions/checkout@v4
- name: Install Python ${{ matrix.python.version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.version }}
cache: 'pip' # cache pip dependencies
- name: Install tox
run: python -m pip install tox
- name: Run pytest
run: tox -e ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}}
31 changes: 31 additions & 0 deletions .github/workflows/_test_future.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Unit Tests (py312)
# Test also with Python 3.12 (experimental; workflow will not fail on error.)

on: workflow_call

jobs:
test312:
name: Test on ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}} (experimental)
continue-on-error: true
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
toxenv: linux
- runner: windows-latest
toxenv: windows
python:
- version: '3.13.0a2'
toxenv: 'py313'
steps:
- uses: actions/checkout@v4
- name: Install Python ${{ matrix.python.version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.version }}
cache: 'pip' # cache pip dependencies
- name: Install tox
run: python -m pip install tox
- name: Run pytest
run: tox -e ${{matrix.python.toxenv}}-${{matrix.platform.toxenv}}
22 changes: 22 additions & 0 deletions .github/workflows/nightly_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Nightly Build
run-name: Nightly Build (by @${{ github.actor }})

on:
schedule:
- cron: '30 5 * * *'

jobs:
code_quality:
uses: ./.github/workflows/_code_quality.yml
test:
uses: ./.github/workflows/_test.yml
test_future:
uses: ./.github/workflows/_test_future.yml
build_package:
needs:
- test
uses: ./.github/workflows/_build_package.yml
build_and_publish_documentation:
needs:
- build_package
uses: ./.github/workflows/_build_and_publish_documentation.yml
Loading

0 comments on commit 9c461f4

Please sign in to comment.