Skip to content

Commit

Permalink
Migrate to delfino (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Lát authored Dec 1, 2021
1 parent 5f60025 commit 48149f2
Show file tree
Hide file tree
Showing 46 changed files with 1,885 additions and 1,748 deletions.
135 changes: 94 additions & 41 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,96 +1,106 @@
version: 2.1

orbs:
slack: circleci/[email protected]
gh: circleci/[email protected]

parameters:
project_name:
type: string
default: issue-watcher
working_directory:
type: string
default: ~/issuewatcher
default: ~/issue-watcher
python_version:
type: string
default: "3.6"
default: "3.7"
cache_version:
type: string
default: "1"
git_trunk_branch:
type: string
default: "master"
command_prefix:
type: string
default: "poetry run delfino"

jobs: # A basic unit of work in a run
test:
working_directory: << pipeline.parameters.working_directory >>
environment:
PYTHONPATH: src
parameters:
version:
python_version:
type: string
docker:
- image: circleci/python:<< parameters.version >>
- image: circleci/python:<< parameters.python_version >>
environment:
PIPENV_VENV_IN_PROJECT: true
PIPENV_VENV_IN_PROJECT: "true"
working_directory: << pipeline.parameters.working_directory >>
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python<< parameters.version >>/site-packages
- run: sudo chown -R circleci:circleci /usr/local/lib/python<< parameters.python_version >>/site-packages
- restore_cache:
key: issuewatcher-<< parameters.version >>-{{ checksum "Pipfile.lock" }}
key: << pipeline.parameters.cache_version >>-<< pipeline.parameters.project_name >>-<< parameters.python_version >>-{{ checksum "poetry.lock" }}
- run:
name: Install dev libraries
command: |
pip install --upgrade pip &&
pip install pipenv &&
pipenv install --dev --deploy
command: pip install --upgrade pip poetry && poetry install --no-ansi --no-root
- run:
name: Format check
command: pipenv run inv format --check
command: << pipeline.parameters.command_prefix >> format --check
- run:
name: Type check
command: pipenv run inv typecheck
command: << pipeline.parameters.command_prefix >> typecheck
- run:
name: Linters
command: pipenv run inv lint
command: << pipeline.parameters.command_prefix >> lint
- save_cache:
key: issuewatcher-<< parameters.version >>-{{ checksum "Pipfile.lock" }}
key: << pipeline.parameters.cache_version >>-<< pipeline.parameters.project_name >>-<< parameters.python_version >>-{{ checksum "poetry.lock" }}
paths:
- ".venv"
- "/usr/local/bin"
- "/usr/local/lib/python<< parameters.version >>/site-packages"
- "/usr/local/lib/python<< parameters.python_version >>/site-packages"
- run:
name: Unit tests
command: |
pipenv run inv test-unit
command: << pipeline.parameters.command_prefix >> test-unit
- run:
name: Integration tests
command: |
pipenv run inv test-integration
command: << pipeline.parameters.command_prefix >> test-integration
- run:
name: Build coverage report
command: pipenv run inv coverage-report
command: << pipeline.parameters.command_prefix >> coverage-report
- run:
name: Upload coverage reports to Codecov
#
command: |
[[ "${CIRCLE_BRANCH}" == "master" ]] && BASE_COMMIT_SHA=$(git rev-parse HEAD~1) || BASE_COMMIT_SHA=$(git merge-base ${CIRCLE_BRANCH} origin/master)
bash <(curl -s https://codecov.io/bash) -N ${BASE_COMMIT_SHA} -f reports/unit-test-report.xml -f reports/integration-test-report.xml -F $(echo << parameters.version >> | tr "." "_")
[[ "${CIRCLE_BRANCH}" == "<< pipeline.parameters.git_trunk_branch >>" ]] && BASE_COMMIT_SHA=$(git rev-parse HEAD~1) || BASE_COMMIT_SHA=$(git merge-base ${CIRCLE_BRANCH} origin/<< pipeline.parameters.git_trunk_branch >>)
bash <(curl -s https://codecov.io/bash) -N ${BASE_COMMIT_SHA} -f reports/coverage-unit.xml -F total,unit_tests &&
bash <(curl -s https://codecov.io/bash) -N ${BASE_COMMIT_SHA} -f reports/coverage-integration.xml -F total,integration_tests
- store_artifacts:
path: reports/coverage-report
- store_test_results:
path: reports

build:
working_directory: << pipeline.parameters.working_directory >>
docker: # run the steps with Docker
- image: circleci/python:<< pipeline.parameters.python_version >>
environment:
PIPENV_VENV_IN_PROJECT: true
PIPENV_VENV_IN_PROJECT: "true"
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
- run: sudo chown -R circleci:circleci /usr/local/lib/python<< pipeline.parameters.python_version >>/site-packages
- restore_cache:
key: issuewatcher-<< pipeline.parameters.python_version >>-{{ checksum "Pipfile.lock" }}
key: << pipeline.parameters.cache_version >>-<< pipeline.parameters.project_name >>-<< pipeline.parameters.python_version >>-{{ checksum "poetry.lock" }}
- run:
name: Build library
command: |
pip install pipenv &&
pipenv run inv build
poetry build
- persist_to_workspace:
root: << pipeline.parameters.working_directory >>
paths: .
paths:
- .

deploy_library:
publish:
working_directory: << pipeline.parameters.working_directory >>
docker: # run the steps with Docker
- image: circleci/python:<< pipeline.parameters.python_version >>
Expand All @@ -99,26 +109,69 @@ jobs: # A basic unit of work in a run
at: << pipeline.parameters.working_directory >>
- run:
name: Upload to pypi
command: pipenv run inv upload
command: |
VERSION=$(poetry version -s)
VERSION_EXISTS=$( \
curl -Ls https://pypi.org/pypi/<< pipeline.parameters.project_name >>/json | \
jq -r '.releases | keys_unsorted' | \
grep -q "\"$VERSION\"" ; echo $? \
)
if [[ $VERSION_EXISTS -ne 0 ]]; then
poetry publish --username "__token__" --password $PYPI_API_TOKEN
else
echo "Package with this version has been already release. Skipping."
fi
release:
working_directory: << pipeline.parameters.working_directory >>
docker:
- image: circleci/python:<< pipeline.parameters.python_version >>
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python<< pipeline.parameters.python_version >>/site-packages
- restore_cache:
key: << pipeline.parameters.cache_version >>-<< pipeline.parameters.project_name >>-<< pipeline.parameters.python_version >>-{{ checksum "poetry.lock" }}
- gh/setup
- run:
name: Check if current version has been released
command: |
VERSION=$(poetry version -s)
if [[ $(gh release view $VERSION >/dev/null 2>&1; echo $?) -eq 0 ]]; then
echo "Tag '$VERSION' already exists. Skipping."
circleci-agent step halt
fi
- run:
name: Create a release
command: gh release create $(poetry version -s) -F CHANGELOG.md

workflows:
version: 2
all_pipelines:
jobs:
- test:
context: issue watcher
name: Python << matrix.version >> tests
name: Python << matrix.python_version >> tests
context: << pipeline.parameters.project_name >>
matrix:
parameters:
version: ["3.6", "3.7", "3.8"]
python_version: [ "3.7", "3.8", "3.9", "3.10" ]
- build:
name: Build
requires:
- test
- deploy_library:
name: Deploy to pypi
context: issue watcher
- publish:
name: Publish to Pypi
context: pypi_upload
requires:
- Build
filters:
branches:
only: master
only: << pipeline.parameters.git_trunk_branch >>
- release:
context:
- github
requires:
- Publish to Pypi
filters:
branches:
only: << pipeline.parameters.git_trunk_branch >>
4 changes: 3 additions & 1 deletion .idea/issue-watcher.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# See https://pre-commit.com/ for usage and config
default_language_version:
python: python3.7
repos:
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
language_version: python3
- repo: local
hooks:
- id: formatting
name: formatting
stages: [commit]
language: system
entry: poetry run delfino format
pass_filenames: false
12 changes: 0 additions & 12 deletions .pydocstyle

This file was deleted.

2 changes: 1 addition & 1 deletion .venv/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# created by virtualenv automatically
*
!.gitignore
Loading

0 comments on commit 48149f2

Please sign in to comment.