Skip to content

Commit

Permalink
feat: implement auto-release GHA and conventional commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
drodarie committed Oct 7, 2024
1 parent 541939a commit 0bcd511
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Black

on: [push, pull_request]
on: [workflow_call]

jobs:
black:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest

steps:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check branch commit

on:
push:
branches:
- '**' # matches every branch ...
- '!main' # ... that is not main

jobs:
isort:
uses: ./.github/workflows/isort.yml
black:
uses: ./.github/workflows/black.yml
build:
uses: ./.github/workflows/build.yml
docs:
uses: ./.github/workflows/docs.yml
api:
uses: ./.github/workflows/api.yml
21 changes: 12 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
name: Test BSB HDF5 engine

on: [ push, pull_request ]
on: [workflow_call]

jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install apt dependencies
run: |
sudo apt-get update
sudo apt-get install openmpi-bin libopenmpi-dev
sudo apt update
sudo apt install openmpi-bin libopenmpi-dev
- name: Cache pip
uses: actions/cache@v4
with:
Expand All @@ -27,13 +28,15 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies & self
run: |
python -m pip install --upgrade pip
pip install -e .[test]
pip install bsb-test==4.0.0rc3 --no-deps
# Install latest pip
pip install --upgrade pip
pip install .[test]
- name: Run tests & coverage
run: |
coverage run -p -m unittest
mpiexec -n 2 coverage run -p -m unittest
coverage run -p -m unittest discover -v -s ./tests
mpiexec -n 2 coverage run -p -m unittest discover -v -s ./tests
bash <(curl -s https://codecov.io/bash)
21 changes: 10 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
name: docs
name: Documentation

on: [ push, pull_request ]
on: [workflow_call]

jobs:
check-documentation:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install MPI
- name: Setup software environment
run: |
sudo apt-get update
sudo apt-get install -y openmpi-bin libopenmpi-dev
- name: Install dependencies
sudo apt update
sudo apt install -y openmpi-bin libopenmpi-dev
- name: Setup Python environment
run: |
python -m pip install pip --upgrade
python -m pip install --upgrade pip
pip install -e .[docs]
- name: Fail documentations on warnings
- name: Build documentation, nitpick, and fail on warnings
run: cd docs && sphinx-build -nW -b html ./source ./build/html
4 changes: 2 additions & 2 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run isort
on:
- push

on: [workflow_call]

jobs:
isort:
Expand Down
159 changes: 159 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Bump version, create release and deploy

on:
push:
branches:
- main

jobs:
isort:
uses: ./.github/workflows/isort.yml
black:
uses: ./.github/workflows/black.yml
build:
uses: ./.github/workflows/build.yml
docs:
uses: ./.github/workflows/docs.yml
api:
uses: ./.github/workflows/api.yml

tag_release:
needs: [isort, black, build, docs, api]
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.semver.outputs.next }}
old_tag: ${{ steps.semver.outputs.current }}

steps:
- name: Create Github token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DBBS_APP_ID }}
private-key: ${{ secrets.DBBS_APP_PRIVATE_KEY }}

- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Get Next Version
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ steps.app-token.outputs.token }}
branch: main

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Bump version in Python project
run: |
pip install --upgrade pip bump-my-version
oldv="${{ steps.semver.outputs.current }}"
newv="${{steps.semver.outputs.next}}"
# Bump the version, dropping the leading `v` with `${x:1}`
bump-my-version replace --current-version=${oldv:1} --new-version=${newv:1} pyproject.toml
- name: Commit & Push version change
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: 'docs: bump version: ${{ steps.semver.outputs.current }} → ${{ steps.semver.outputs.next }} [skip ci]'

- name: Create tag
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.semver.outputs.next }}
github_token: ${{ steps.app-token.outputs.token }}

release:
runs-on: ubuntu-latest
needs: tag_release

steps:
- name: Create Github token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DBBS_APP_ID }}
private-key: ${{ secrets.DBBS_APP_PRIVATE_KEY }}

- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Pull commit of version change
run: |
git pull origin main
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ steps.app-token.outputs.token }}
fromTag: ${{ needs.tag_release.outputs.tag }}
toTag: ${{ needs.tag_release.outputs.old_tag }}

- name: Create Release
uses: ncipollo/[email protected]
with:
allowUpdates: true
draft: false
makeLatest: true
tag: ${{ needs.tag_release.outputs.tag }}
name: ${{ needs.tag_release.outputs.tag }}
body: ${{ steps.changelog.outputs.changes }}
token: ${{ steps.app-token.outputs.token }}

- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
file_pattern: CHANGELOG.md

pypi-publish:
runs-on: ubuntu-latest
needs: release
environment:
name: pypi
url: https://pypi.org/p/bsb-hdf5
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Create Github token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DBBS_APP_ID }}
private-key: ${{ secrets.DBBS_APP_PRIVATE_KEY }}

- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Pull commits of version bump
run: |
git pull origin main
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install dependencies and build dist
run: |
python -m pip install --upgrade pip
pip install build
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
32 changes: 32 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Validate Pull Request

on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
uses: ytanikin/[email protected]
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","revert"]'

preview-docs:
runs-on: ubuntu-latest
if: github.event.action != 'edited'
steps:
- uses: actions/checkout@v4
- name: Check modifications on docs
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docs: # name of the filter
- 'docs/**'
- name: Preview Readthedocs
if: steps.filter.outputs.docs == 'true'
uses: readthedocs/actions/preview@v1
with:
project-slug: "bsb"
12 changes: 11 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.1
Expand All @@ -7,4 +10,11 @@ repos:
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
name: isort (python)
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.3.0
hooks:
- id: conventional-pre-commit
name: conventional-commit
stages: [ commit-msg ]
args: [ ]
Empty file added CHANGELOG.md
Empty file.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[![Build Status](https://github.com/dbbs-lab/bsb-hdf5/actions/workflows/main.yml/badge.svg)](https://github.com/dbbs-lab/bsb-hdf5/actions/workflows/main.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# bsb-hdf5
The HDF5 storage engine of the BSB

`bsb-hdf5` is a plugin of [BSB](https://github.com/dbbs-lab/bsb) (see also
[bsb-core](https://github.com/dbbs-lab/bsb-core)).
It contains the storage engine allowing the user to save and load their models'
in HDF5 files.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ docs = [
"sphinx-design~=0.5",
"sphinx-copybutton~=0.5"
]
dev = [
"bsb-hdf5[test]",
"build~=1.0",
"twine~=4.0",
"pre-commit~=3.5",
"black~=24.1.1",
"isort~=5.12",
"snakeviz~=2.1",
"bump-my-version~=0.24"
]

[tool.isort]
profile = "black"
Expand Down

0 comments on commit 0bcd511

Please sign in to comment.