Skip to content

Commit

Permalink
Merge pull request #1 from tartiflette/bubu/first-implem
Browse files Browse the repository at this point in the history
Add Implementation and tests
  • Loading branch information
abusi authored Jun 19, 2019
2 parents ba8577d + 9bedf5b commit 3e85fb9
Show file tree
Hide file tree
Showing 26 changed files with 695 additions and 1 deletion.
65 changes: 65 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
workflow "build and release" {
on = "push"
resolves = ["release"]
}

action "build docker image" {
uses = "actions/docker/cli@master"
args = "build -t tartiflette_plugin_time_it ."
}

action "unit test" {
needs = ["build docker image"]
uses = "actions/docker/cli@master"
args = "run -i tartiflette_plugin_time_it make test-unit"
}

action "functional test" {
needs = ["build docker image"]
uses = "actions/docker/cli@master"
args = "run -i tartiflette_plugin_time_it make test-functional"
}

action "style" {
needs = ["build docker image"]
uses = "actions/docker/cli@master"
args = "run -i tartiflette_plugin_time_it make style"
}

action "build and publish to pypi" {
uses = "./github-actions/pypi/"
secrets = ["TWINE_PASSWORD", "TWINE_USERNAME"]
needs = ["unit test", "functional test", "style"]
}

action "is master" {
uses = "actions/bin/filter@master"
needs = ["build and publish to pypi"]
args = "branch master"
}

action "is ref master" {
uses = "./github-actions/shell/"
needs = ["is master"]
runs = "is_ref"
env = {
REF_NAME = "refs/heads/master"
}
}

action "set version and changelog" {
uses = "./github-actions/shell/"
needs = ["is ref master"]
runs = "make"
args = "github-action-version-and-changelog"
}

action "release" {
uses = "./github-actions/release/"
secrets = ["GITHUB_TOKEN"]
needs = ["set version and changelog"]
env = {
USERNAME = "tartiflette"
REPOSITORY = "tartiflette-plugin-time-it"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ venv.bak/

# mypy
.mypy_cache/

reports/
11 changes: 11 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[settings]
line_length=79
indent=' '
multi_line_output=3
known_third_party=tartiflette
known_first_party=tartiflette_plugin_time_it,tests
include_trailing_comma=1
use_parentheses=1
force_grid_wrap=0
combine_as_imports=1
lines_between_types=1
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tartiflette-plugin-time-it Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

- [Next](./changelogs/next.md)

## [Released]

- [0.0.x]
- [0.0.1](./changelogs/0.0.1.md) - 2019-06-19
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.7.2

RUN apt-get update && apt-get install -y cmake bison flex git

ENV PYTHONPATH=/usr/src/app/

WORKDIR /usr/src/app

COPY . /usr/src/app/

RUN make init
RUN pip install -e .[test]
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
SET_ALPHA_VERSION = 0
PKG_VERSION := $(shell cat setup.py | grep "_VERSION =" | egrep -o "([0-9]+\\.[0-9]+\\.[0-9]+)")

REF := $(shell cat /github/workflow/event.json | jq ".ref")

ifneq ($(REF),"refs/heads/master")
PKG_VERSION := $(shell echo | awk -v pkg_version="$(PKG_VERSION)" -v build_number="$(shell date +\"%s\")" '{print pkg_version "a" build_number}')
SET_ALPHA_VERSION = 1
endif

.PHONY: init
init:
git submodule init
git submodule update

.PHONY: format-import
format-import:
isort -rc tartiflette_plugin_time_it/. tests/. setup.py

.PHONY: format
format: format-import
black -l 79 --py36 tartiflette_plugin_time_it tests setup.py

.PHONY: check-import
check-import:
isort --check-only -rc tartiflette_plugin_time_it/. tests/. setup.py

.PHONY: check-format
check-format:
black -l 79 --py36 --check tartiflette_plugin_time_it tests setup.py

.PHONY: style
style: check-format check-import
pylint tartiflette_plugin_time_it --rcfile=pylintrc

.PHONY: complexity
complexity:
xenon --max-absolute B --max-modules B --max-average A tartiflette_plugin_time_it

.PHONY: test-unit
test-unit: clean
mkdir -p reports
py.test -s tests/unit --junitxml=reports/report_unit_tests.xml --cov . --cov-config .coveragerc --cov-report term-missing --cov-report xml:reports/coverage_func.xml $(EXTRA_ARGS)

.PHONY: test-functional
test-functional: clean
mkdir -p reports
py.test -s tests/functional --junitxml=reports/report_func_tests.xml --cov . --cov-config .coveragerc --cov-report term-missing --cov-report xml:reports/coverage_unit.xml $(EXTRA_ARGS)

.PHONY: test
test: test-unit test-functional

.PHONY: clean
clean:
find . -name '*.pyc' -exec rm -fv {} +
find . -name '*.pyo' -exec rm -fv {} +
find . -name '__pycache__' -exec rm -frv {} +

.PHONY: set-version
set-version:
ifneq ($(SET_ALPHA_VERSION), 0)
bash -c "sed -i \"s@_VERSION[ ]*=[ ]*[\\\"\'][0-9]\+\\.[0-9]\+\\.[0-9]\+[\\\"\'].*@_VERSION = \\\"$(PKG_VERSION)\\\"@\" setup.py"
endif

.PHONY: run-docs
run-docs:
docker-compose up docs

.PHONY: get-version
get-version:
@echo $(PKG_VERSION)

.PHONY: get-last-released-changelog-entry
get-last-released-changelog-entry:
@cat changelogs/$(PKG_VERSION).md

.PHONY: github-action-version-and-changelog
github-action-version-and-changelog:
echo $(PKG_VERSION) > $(HOME)/name
echo $(PKG_VERSION) > $(HOME)/tag
@cp changelogs/$(PKG_VERSION).md $(HOME)/changelog
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# tartiflette-plugin-time-it
Small plugin to tartiflette that will provide a directive for timing field execution

Allows you to view field time execution in your log as easily as :

```
type Example {
aField: String @timeIt
}
```

By default the `timeIt` directive will use it's own logger retrieved by `logging.getLogger("__name__")`.

If called with `useLogger: false` it will use the print statement.

At init time, using the `create_engine` api, you can pass your own logger to the directive.

```python

engine = await create_engine(sdl, modules=[{"name": "tartiflette_plugin_time_it", "config": {"logger": myLogger()}}])
```
3 changes: 3 additions & 0 deletions changelogs/0.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [0.0.1] - 2019-06-19

First Release of this plugin
7 changes: 7 additions & 0 deletions changelogs/next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# [Next]

## Added

## Changed

## Fixed
22 changes: 22 additions & 0 deletions github-actions/pypi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.7.2

LABEL "name"="pypi"
LABEL "maintainer"="Stan Chollet <[email protected]>"
LABEL "version"="1.0.0"

LABEL "com.github.actions.name"="Pypi Release"
LABEL "com.github.actions.description"="Push package to pypi server."
LABEL "com.github.actions.icon"="upload"
LABEL "com.github.actions.color"="green"

RUN apt-get update && apt-get install -y cmake bison flex git jq

RUN pip install --upgrade setuptools wheel twine

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

WORKDIR /github/workspace

ENTRYPOINT ["/entrypoint.sh"]
1 change: 1 addition & 0 deletions github-actions/pypi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fork of https://github.com/mariamrf/py-package-publish-action
36 changes: 36 additions & 0 deletions github-actions/pypi/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

if [ -d "./libgraphqlparser" ]; then
rm -rf ./libgraphqlparser
fi

make init

set_version_if_not_master() {
cat /github/workflow/event.json | jq -e '. | select(.ref=="refs/heads/master")'
return_code=$?

if [ $return_code -ne 0 ]; then
export TWINE_REPOSITORY_URL="https://test.pypi.org/legacy/"
make set-version
fi
}

check_if_setup_file_exists() {
if [ ! -f setup.py ]; then
echo "setup.py must exist in the directory that is being packaged and published."
exit 1
fi
}

upload_package() {
python setup.py sdist
twine upload dist/*
}

set_version_if_not_master

make get-version

check_if_setup_file_exists
upload_package
23 changes: 23 additions & 0 deletions github-actions/release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.11

LABEL "name"="github-release"
LABEL "maintainer"="Stan Chollet <[email protected]>"
LABEL "version"="1.0.0"

LABEL "com.github.actions.name"="Github Release"
LABEL "com.github.actions.description"="Create a release on github"
LABEL "com.github.actions.icon"="upload"
LABEL "com.github.actions.color"="green"

RUN go get github.com/aktau/github-release

COPY "entrypoint.sh" "/entrypoint.sh"

WORKDIR /github/workspace
RUN mkdir -p /github/workspace

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

CMD [""]
50 changes: 50 additions & 0 deletions github-actions/release/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

set -e

_PATH_TAG="${HOME}/tag"
_PATH_USERNAME="${HOME}/username"
_PATH_REPOSITORY="${HOME}/repository"
_PATH_CHANGELOG="${HOME}/changelog"
_PATH_NAME="${HOME}/name"

if [ -f $_PATH_TAG ]; then
TAG=$(cat $_PATH_TAG)
fi

if [ -f $_PATH_USERNAME ]; then
USERNAME=$(cat $_PATH_USERNAME)
fi

if [ -f $_PATH_REPOSITORY ]; then
REPOSITORY=$(cat $_PATH_REPOSITORY)
fi

if [ -f $_PATH_NAME ]; then
NAME=$(cat $_PATH_NAME)
fi

echo "---------------------------"
echo "TAG: $TAG"
echo "REPOSITORY: $REPOSITORY"
echo "USERNAME: $USERNAME"
echo "NAME: $NAME"
echo "---------------------------"

if [ -f $_PATH_CHANGELOG ]; then
echo "Release with changelog"
desc=$(cat $_PATH_CHANGELOG)
github-release release \
--user $USERNAME \
--repo $REPOSITORY \
--tag $TAG \
--name $NAME \
--description "${desc}"
else
echo "Release without changelog"
github-release release \
--user $USERNAME \
--repo $REPOSITORY \
--tag $TAG \
--name $NAME
fi
Loading

0 comments on commit 3e85fb9

Please sign in to comment.