Skip to content

Commit

Permalink
ci: refurbishing for GitHub CI
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Jul 18, 2023
1 parent 50acbae commit 304fd82
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 79 deletions.
46 changes: 46 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

<!--
For general questions please use the Discussions section of the project:
https://github.com/bihealth/varfish-server/discussions
For bug reports and feature requests please open a ticket using the templates!
-->

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

<!--
For general questions please use the Discussions section of the project:
https://github.com/bihealth/varfish-server/discussions
For bug reports and feature requests please open a ticket using the templates!
-->

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
NOTE
NOTE In most cases, you should create an issue first, and only then
NOTE a pull request. Please see the contribution guidelines for
NOTE further information. In particular related to conventional
NOTE commit messages.
NOTE
The title should have the following format:
<type>: description (#<issue>)
-->
18 changes: 18 additions & 0 deletions .github/workflows/conventional-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PR
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

jobs:
title-format:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v3.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: true
81 changes: 81 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches_ignore: []

jobs:
cancel-previous:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- uses: khan/pull-request-workflow-cancel@1.0.0
with:
workflows: "main.yml"
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

linting:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.11"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"

- name: Install dependencies
run: |
make dev-deps
pip install -e .
- name: Run lintings
run: |
make lint
testing:
runs-on: ubuntu-latest
needs: linting
strategy:
matrix:
django-version:
- ">=3.0,<4.0"
- ">=4.0,<5.0"
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"

- name: Install Django dependency
run: |
pip install "Django${{ matrix.django-version }}"
- name: Install this library via pip
run: |
pip install -e .
- name: "No tests yet :("
run: |
# make test
41 changes: 41 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches:
- main

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:

- uses: GoogleCloudPlatform/release-please-action@v2
id: release
with:
release-type: python
package-name: drf-keyed-list-bihealth

- uses: actions/checkout@v2
if: ${{ steps.release.outputs.release_created }}
with:
fetch-depth: 0

- name: Set up Python
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Build package
if: ${{ steps.release.outputs.release_created }}
run: |
python -m pip install --upgrade pip
python setup.py sdist
- name: Publish to PyPI
if: ${{ steps.release.outputs.release_created }}
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ venv.bak/
.mypy_cache/

# JetBrains
.idea
.idea
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DIRS := drf_keyed_list

.PHONY: all
all:

.PHONY: dev-deps
dev-deps:
pip install black==23.7.0 isort==5.12.0 flake8

.PHONY: format
format: black isort

.PHONY: isort
isort:
isort --force-sort-within-sections --profile=black $(DIRS)

.PHONY: black
black:
black --line-length 100 $(DIRS)

.PHONY: lint
lint: check-black check-isort flake8

.PHONY: check-black
check-black:
black --check --diff --line-length 100 $(DIRS)

.PHONY: check-isort
check-isort:
isort --force-sort-within-sections --profile=black --check $(DIRS)

.PHONY: flake8
flake8:
flake8 $(DIRS)

.PHONY: test
test:
cd example-project
python manage.py test djangoplugins
python manage.py makemigrations
python manage.py migrate
python manage.py syncplugins
12 changes: 6 additions & 6 deletions drf_keyed_list/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__title__ = 'DRF Keyed List'
__version__ = '0.0.2'
__author__ = 'Clayton Daley III'
__license__ = 'Apache 2.0'
__copyright__ = 'Copyright 2018 Clayton Daley'
__title__ = "DRF Keyed List"
__version__ = "0.0.2"
__author__ = "Clayton Daley III"
__license__ = "Apache 2.0"
__copyright__ = "Copyright 2018 Clayton Daley"

# Version synonym
VERSION = __version__


from .serializers import KeyedListSerializer
from .serializers import KeyedListSerializer # noqa: F401,E402
28 changes: 11 additions & 17 deletions drf_keyed_list/serializers.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
from django.utils.translation import ugettext_lazy as _
from rest_framework.serializers import ListSerializer
from rest_framework.exceptions import ValidationError
from rest_framework.fields import SkipField
from rest_framework.serializers import ListSerializer
from rest_framework.settings import api_settings


class KeyedListSerializer(ListSerializer):
default_error_messages = {
'not_a_dict': _('Expected a dict of items but got type "{input_type}".'),
'empty': _('This dict may not be empty.')
"not_a_dict": _('Expected a dict of items but got type "{input_type}".'),
"empty": _("This dict may not be empty."),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
meta = getattr(self.child, 'Meta', None)
assert hasattr(meta, 'keyed_list_serializer_field'), \
"Must provide a field name at keyed_list_serializer_field when using KeyedListSerializer"
meta = getattr(self.child, "Meta", None)
assert hasattr(
meta, "keyed_list_serializer_field"
), "Must provide a field name at keyed_list_serializer_field when using KeyedListSerializer"
self._keyed_field = meta.keyed_list_serializer_field

def to_internal_value(self, data):
if not isinstance(data, dict):
message = self.error_messages['not_a_dict'].format(
input_type=type(data).__name__
)
raise ValidationError({
api_settings.NON_FIELD_ERRORS_KEY: [message]
}, code='not_a_dict')
message = self.error_messages["not_a_dict"].format(input_type=type(data).__name__)
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: [message]}, code="not_a_dict")
if not self.allow_empty and len(data) == 0:
if self.parent and self.partial:
raise SkipField()

message = self.error_messages['empty']
raise ValidationError({
api_settings.NON_FIELD_ERRORS_KEY: [message]
}, code='empty')
message = self.error_messages["empty"]
raise ValidationError({api_settings.NON_FIELD_ERRORS_KEY: [message]}, code="empty")
data = [{**v, **{self._keyed_field: k}} for k, v in data.items()]
return super().to_internal_value(data)

def to_representation(self, data):
response = super().to_representation(data)
return {v.pop(self._keyed_field): v for v in response}

10 changes: 10 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[metadata]
license_file = LICENSE.md
description-file = README.md

[flake8]
exclude =
.*.py
max-complexity = 18
select = B,C,E,F,W,T4,B9
ignore = E203, E266, E501, W503
max-line-length = 100
application_import_names = mycmsproject
import-order-style = google
Loading

0 comments on commit 304fd82

Please sign in to comment.