Skip to content

Commit

Permalink
Update project to use GitHub workflows (#9)
Browse files Browse the repository at this point in the history
* Add pre-commit

* Convert project to use pyproject.toml

* Fix project to comply with pre-commit hooks

* Add GitHub action workflow for PR's

* Add yaml pre-commit hook

* Fix workflow

* Update circleci build

* Fix Action trigger events

* Fix workflow syntax

* Add pre-commit to deps

* Wrap pre-commit in venv

* Fix pytest version

* Fix workflow actions

* Add postgres db to workflow

* Add multiple Python versions and OSes to workflow

* Try removing lock file

* Remove support for 3.6

* Fix deps caching for matrix strategy

* Fix re-factor typo in unit test

* Add code coverage step

* Remove other OSes

* Rename workflow file

* Split out major steps into separate jobs

* Add license file to package

* Fix order of step variables

* Remove push pre-commit step

* Add release workflow

* Add release workflow

* Generate release body

* Uncomment publish steps

* Add pre-commit hook to validate pyproject.toml

* Rename pipeline workflow file

* Remove CircleCI pipeline
  • Loading branch information
shawalli committed Jul 20, 2020
1 parent bf04c05 commit 9714996
Show file tree
Hide file tree
Showing 21 changed files with 563 additions and 415 deletions.
72 changes: 0 additions & 72 deletions .circleci/config.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .flake8
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 120
max-complexity = 10
exclude =
psycopg2_pgevents/__init__.py,
tests
142 changes: 142 additions & 0 deletions .github/workflows/pipeline.yaml
@@ -0,0 +1,142 @@
name: Build, Lint, Test

on:
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize

jobs:
lint:
name: ️⚒️ & 👕

strategy:
matrix:
python-version: [3.7, 3.8]

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Set Poetry config
run: |
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install

- name: Run pre-commit
if: github.event_name == 'pull_request'
run: |
git fetch origin master:master
poetry run pre-commit run --from-ref master --to-ref HEAD
test:
name: 🧪
needs: lint

strategy:
matrix:
python-version: [3.7, 3.8]

runs-on: ubuntu-latest

services:
postgres:
image: postgres:10-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Cache Poetry virtualenv
uses: actions/cache@v2
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
poetry-${{ github.ref }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Set Poetry config
run: |
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: poetry install

- name: Unit Test
env:
TEST_DATABASE_BASE_URL: postgresql://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}
run: poetry run python -m pytest --cov=psycopg2_pgevents --cov-branch tests/

- name: Submit Code Coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: py-${{ matrix.python-version }}
COVERALLS_PARALLEL: true
run: poetry run coveralls

test-finish:
name: 🚪
needs: test

runs-on: ubuntu-latest
container: python:3-slim

steps:
- name: Finished
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip3 install coveralls
coveralls --finish
73 changes: 73 additions & 0 deletions .github/workflows/release.yaml
@@ -0,0 +1,73 @@
name: Package, Ship

on:
push:
branches:
- master

jobs:
package:
name: 📦 & 🚢

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: '0'

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Get next package version
id: bumpversion
uses: anothrNick/github-tag-action@1.23.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DRY_RUN: true

- name: Install poetry
uses: dschep/install-poetry-action@v1.3
with:
create_virtualenvs: true

- name: Bump release version
run: poetry version ${{ steps.bumpversion.outputs.new_tag }}

- name: Build package
run: poetry build

- name: Publish package (Test PyPI)
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_PASSWORD }}
poetry publish -r testpypi
- name: Publish package (PyPI)
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_PASSWORD }}
poetry publish
- name: Generate release message
id: release_message
run: |
# Get (squashed) commit summaries since last tag, convert to list,
# escape multi-lines into a format GitHub Actions respect, and set as output
export NOTES=`git log --pretty=format:'%s' $(git describe --tags --abbrev=0 HEAD^)..HEAD | tr '\n' '\0' | xargs -0 -I{} echo '- {}'`
export NOTES_ENCODED_NEWLINES="${NOTES//$'\n'/'%0A'}"
echo "::set-output name=message::$NOTES_ENCODED_NEWLINES"
- name: Create release
uses: actions/create-release@v1.1.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.bumpversion.outputs.new_tag }}
release_name: ${{ steps.bumpversion.outputs.new_tag }}
body: ${{ steps.release_message.outputs.message}}
draft: false
prerelease: false
4 changes: 4 additions & 0 deletions .isort.cfg
@@ -0,0 +1,4 @@
[settings]
known_third_party = psycopg2,pytest,testfixtures
multi_line_output=3
include_trailing_comma=True
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,33 @@
---
repos:
- repo: https://gitlab.com/smop/pre-commit-hooks
rev: v1.0.0
hooks:
- id: check-poetry
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.0.9
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit
rev: v2.6.0
hooks:
- id: validate_manifest
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
2 changes: 0 additions & 2 deletions README.rst
Expand Up @@ -4,8 +4,6 @@ psycopg2-pgevents

.. image:: https://badge.fury.io/py/psycopg2-pgevents.svg
:target: https://badge.fury.io/py/psycopg2-pgevents
.. image:: https://circleci.com/gh/shawalli/psycopg2-pgevents.svg?style=svg
:target: https://circleci.com/gh/shawalli/psycopg2-pgevents
.. image:: https://coveralls.io/repos/github/shawalli/psycopg2-pgevents/badge.svg?branch=master
:target: https://coveralls.io/github/shawalli/psycopg2-pgevents?branch=master
.. image:: https://img.shields.io/badge/License-MIT-yellow.svg
Expand Down
12 changes: 0 additions & 12 deletions psycopg2_pgevents/__about__.py

This file was deleted.

19 changes: 13 additions & 6 deletions psycopg2_pgevents/__init__.py
@@ -1,10 +1,17 @@
"""This package provides the ability to listen for PostGreSQL table events at the database level."""
from psycopg2_pgevents.__about__ import __author__, __copyright__, __email__, __license__, __summary__, \
__title__, __uri__, __version__


from psycopg2_pgevents.debug import log, set_debug
from psycopg2_pgevents.event import poll, register_event_channel, unregister_event_channel
from psycopg2_pgevents.event import (
poll,
register_event_channel,
unregister_event_channel,
)
from psycopg2_pgevents.sql import execute
from psycopg2_pgevents.trigger import install_trigger, install_trigger_function, trigger_function_installed, \
trigger_installed, uninstall_trigger, uninstall_trigger_function
from psycopg2_pgevents.trigger import (
install_trigger,
install_trigger_function,
trigger_function_installed,
trigger_installed,
uninstall_trigger,
uninstall_trigger_function,
)

0 comments on commit 9714996

Please sign in to comment.