Skip to content

Commit

Permalink
ops: set dev infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
kerberizer committed Aug 8, 2024
1 parent d87195b commit 9d0f707
Show file tree
Hide file tree
Showing 11 changed files with 486 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 80
extend-select = B950
extend-ignore = E203,E501,E701
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
assignees:
- "kerberizer"
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
name: CI

on: # yamllint disable-line rule:truthy
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:

env:
POETRY_VERSION: 1.8.3
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}


jobs:

test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'

steps:

- name: Checkout the repository
uses: actions/[email protected]

- name: Setup Python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Get the precise Python version
run: echo "PYTHON_ID=$( python -VV | sha256sum | awk '{ print $1 }' )" >> "$GITHUB_ENV"

- name: Load the cached Poetry installation
id: cached-poetry
uses: actions/[email protected]
with:
path: ~/.local
key: poetry-${{ env.POETRY_VERSION }}-py_${{ env.PYTHON_ID}}-0

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/[email protected]
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load the cached dependencies
id: cached-deps
uses: actions/[email protected]
with:
path: .venv
key: py${{ matrix.python-version }}-deps-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-deps.outputs.cache-hit != 'true'
run: poetry install --no-interaction

- name: Run pre-commit
run: >-
if [[ $GITHUB_REF == refs/heads/main ]]; then
SKIP=no-commit-to-branch poetry run pre-commit run --all-files
else
poetry run pre-commit run --all-files
fi
- name: Run tests
env:
COVERAGE_FILE: .coverage.${{ matrix.python-version }}
run: poetry run pytest --cov

- name: Store the coverage report
uses: actions/[email protected]
with:
name: coverage-${{ matrix.python-version }}
path: .coverage.${{ matrix.python-version }}

coverage:

runs-on: ubuntu-latest
needs: test
permissions:
pull-requests: write
contents: write

steps:

- name: Checkout the repository
uses: actions/[email protected]

- name: Retrieve the coverage reports
id: download
uses: actions/[email protected]
with:
pattern: coverage-*
merge-multiple: true

- name: Process the coverage reports
id: coverage_processing
uses: py-cov-action/[email protected]
with:
COVERAGE_DATA_BRANCH: 'COVERAGE-REPORT'
GITHUB_TOKEN: ${{ github.token }}
MERGE_COVERAGE_FILES: true

- name: Store the pull request coverage comment for later posting
if: steps.coverage_processing.outputs.COMMENT_FILE_WRITTEN == 'true'
uses: actions/[email protected]
with:
name: python-coverage-comment-action
path: python-coverage-comment-action.txt
29 changes: 29 additions & 0 deletions .github/workflows/coverage-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Post a coverage report comment on pull requests

on: # yamllint disable-line rule:truthy
workflow_run:
workflows:
- 'CI'
types:
- 'completed'

jobs:

comment:

runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
permissions:
pull-requests: write
contents: write
actions: read

steps:

- name: Post the stored pull request coverage comment
uses: py-cov-action/[email protected]
with:
COVERAGE_DATA_BRANCH: 'COVERAGE-REPORT'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
repos:
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
hooks:
- id: poetry-check
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-docstring-first
- id: check-json
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: name-tests-test
- id: no-commit-to-branch
- id: pretty-format-json
args: [--autofix, --no-ensure-ascii]
- id: trailing-whitespace
- repo: https://github.com/facebook/usort
rev: v1.0.8
hooks:
- id: usort
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
args: [--preview]
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear == 24.4.26
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
7 changes: 7 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: default
rules:
line-length:
max: 119
new-lines:
type: platform
Loading

0 comments on commit 9d0f707

Please sign in to comment.