Skip to content

Commit 3ccfefa

Browse files
committed
Add Github workflow and badges
1 parent 7ad3792 commit 3ccfefa

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: 'setup-poetry'
2+
description: 'Setup Poetry Project'
3+
4+
#----------------------------------------------
5+
# following the steps outlined at
6+
# https://github.com/snok/install-poetry?tab=readme-ov-file#testing
7+
#----------------------------------------------
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
#----------------------------------------------
13+
# set-up python
14+
#----------------------------------------------
15+
- name: Set up python
16+
id: setup-python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
#----------------------------------------------
22+
# install & configure poetry
23+
#----------------------------------------------
24+
- name: Install Poetry
25+
uses: snok/install-poetry@v1
26+
with:
27+
virtualenvs-create: true
28+
virtualenvs-in-project: true
29+
installer-parallel: true
30+
31+
#----------------------------------------------
32+
# load cached venv if cache exists
33+
#----------------------------------------------
34+
- name: Load cached venv
35+
id: cached-poetry-dependencies
36+
uses: actions/cache@v4
37+
with:
38+
path: .venv
39+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
40+
41+
#----------------------------------------------
42+
# install dependencies if cache does not exist
43+
#----------------------------------------------
44+
- name: Install dependencies
45+
if: steps.cached--dependencies.outputs.cache-hit != 'true'
46+
run: poetry install --no-interaction --no-root
47+
shell: bash
48+
49+
#----------------------------------------------
50+
# install your root project, if required
51+
#----------------------------------------------
52+
- name: Install project
53+
run: poetry install --no-interaction
54+
shell: bash

.github/workflows/testing.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
ruff:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
- name: Setup Poetry
18+
uses: ./.github/actions/setup-poetry
19+
- name: Ruff (linting + formating)
20+
id: ruff
21+
run: |
22+
source .venv/bin/activate
23+
pre-commit run --all
24+
- name: Generate Badges
25+
if: success() || failure()
26+
run: |
27+
source .venv/bin/activate
28+
mkdir -p badges/
29+
anybadge --overwrite --label=python --value=3.12+ --file=badges/python.svg --color='dodgerblue'
30+
anybadge --overwrite --value="${{ steps.ruff.outcome }}" --label=ruff --file=badges/ruff.svg success=green failure=red
31+
anybadge --overwrite --label=version --value="v$(poetry version --short)" --file=badges/version.svg --color='green'
32+
- name: Publish badges to GitHub Pages
33+
if: (success() || failure()) && (github.ref_name == github.event.repository.default_branch)
34+
uses: JamesIves/github-pages-deploy-action@v4
35+
with:
36+
folder: badges/
37+
clean: false
38+
39+
pytest:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Check out repository
43+
uses: actions/checkout@v4
44+
- name: Setup Poetry
45+
uses: ./.github/actions/setup-poetry
46+
- name: Run Pytest
47+
id: pytest
48+
run: |
49+
source .venv/bin/activate
50+
coverage run -m pytest tests/
51+
- name: Generate Badges
52+
if: success() || failure()
53+
run: |
54+
source .venv/bin/activate
55+
coverage report
56+
mkdir -p badges/
57+
anybadge --overwrite --value="${{ steps.pytest.outcome }}" --label=pytest --file=badges/pytest.svg success=green failure=red
58+
anybadge --overwrite --value="$(coverage report --format=total)" --file=badges/coverage.svg coverage
59+
- name: Publish badges to GitHub Pages
60+
if: (success() || failure()) && (github.ref_name == github.event.repository.default_branch)
61+
uses: JamesIves/github-pages-deploy-action@v4
62+
with:
63+
folder: badges/
64+
clean: false

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Python Injection Framework (PIF)
22

3+
[![python](https://github.com/scottzach1/Python-Injector-Framework/blob/gh-pages/python.svg?raw=true)](https://github.com/scottzach1/Python-Injector-Framework/)
4+
[![version](https://github.com/scottzach1/Python-Injector-Framework/blob/gh-pages/version.svg?raw=true)](https://github.com/scottzach1/Python-Injector-Framework/)
5+
[![coverage](https://github.com/scottzach1/Python-Injector-Framework/blob/gh-pages/coverage.svg?raw=true)](https://github.com/scottzach1/Python-Injector-Framework/)
6+
[![pytest](https://github.com/scottzach1/Python-Injector-Framework/blob/gh-pages/pytest.svg?raw=true)](https://github.com/scottzach1/Python-Injector-Framework/)
7+
[![ruff](https://github.com/scottzach1/Python-Injector-Framework/blob/gh-pages/ruff.svg?raw=true)](https://github.com/scottzach1/Python-Injector-Framework/)
8+
39
A simple Python dependency injection framework.
410

511
## Usage

0 commit comments

Comments
 (0)