diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 0000000..4d522a2 --- /dev/null +++ b/.github/main.workflow @@ -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 ." +} + +action "unit test" { + needs = ["build docker image"] + uses = "actions/docker/cli@master" + args = "run -i tartiflette make test-unit" +} + +action "functional test" { + needs = ["build docker image"] + uses = "actions/docker/cli@master" + args = "run -i tartiflette make test-functional" +} + +action "style" { + needs = ["build docker image"] + uses = "actions/docker/cli@master" + args = "run -i tartiflette 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" + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d52ae0b..d29fcd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,15 @@ -# tartiflette-plugin-time-it +# Tartiflette-plugin-time-it Changelog -## Released Versions +All notable changes to this project will be documented in this file. -### [x.y.Z] +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). -#### Fixed +## [Unreleased] -#### Changed +- [Next](./changelogs/next.md) -#### Added \ No newline at end of file +## [Released] + +- [0.0.x] + - [0.0.1](./changelogs/0.0.1.md) - 2019-06-19 diff --git a/Makefile b/Makefile index b588cff..16e8363 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,12 @@ +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: @@ -46,3 +55,27 @@ 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 \ No newline at end of file diff --git a/README.md b/README.md index a798c44..b9e9fb3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # tartiflette-plugin-time-it -Write here a little laius about how your plugin is working and how it can be configured \ No newline at end of file +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()}}]) +``` \ No newline at end of file diff --git a/changelogs/0.0.1.md b/changelogs/0.0.1.md new file mode 100644 index 0000000..60a06c9 --- /dev/null +++ b/changelogs/0.0.1.md @@ -0,0 +1,3 @@ +# [0.0.1] - 2019-06-19 + +First Release of this plugin diff --git a/changelogs/next.md b/changelogs/next.md new file mode 100644 index 0000000..8c543b9 --- /dev/null +++ b/changelogs/next.md @@ -0,0 +1,7 @@ +# [Next] + +## Added + +## Changed + +## Fixed diff --git a/github-actions/pypi/Dockerfile b/github-actions/pypi/Dockerfile new file mode 100644 index 0000000..75ebc25 --- /dev/null +++ b/github-actions/pypi/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.7.2 + +LABEL "name"="pypi" +LABEL "maintainer"="Stan Chollet " +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"] \ No newline at end of file diff --git a/github-actions/pypi/README.md b/github-actions/pypi/README.md new file mode 100644 index 0000000..148293f --- /dev/null +++ b/github-actions/pypi/README.md @@ -0,0 +1 @@ +Fork of https://github.com/mariamrf/py-package-publish-action \ No newline at end of file diff --git a/github-actions/pypi/entrypoint.sh b/github-actions/pypi/entrypoint.sh new file mode 100644 index 0000000..854082a --- /dev/null +++ b/github-actions/pypi/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/github-actions/release/Dockerfile b/github-actions/release/Dockerfile new file mode 100644 index 0000000..41d67c3 --- /dev/null +++ b/github-actions/release/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.11 + +LABEL "name"="github-release" +LABEL "maintainer"="Stan Chollet " +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 [""] diff --git a/github-actions/release/entrypoint.sh b/github-actions/release/entrypoint.sh new file mode 100644 index 0000000..e738313 --- /dev/null +++ b/github-actions/release/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/github-actions/shell/Dockerfile b/github-actions/shell/Dockerfile new file mode 100644 index 0000000..4330aba --- /dev/null +++ b/github-actions/shell/Dockerfile @@ -0,0 +1,35 @@ +FROM ruby:2-slim + +LABEL "name"="Shell Action" +LABEL "maintainer"="Stan Chollet " +LABEL "version"="1.0.0" + +LABEL "com.github.actions.name"="Shell Action" +LABEL "com.github.actions.description"="Action for executing shell/make commands" +LABEL "com.github.actions.icon"="filter" +LABEL "com.github.actions.color"="gray-dark" + +COPY README.md / + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + bats \ + build-essential \ + ca-certificates \ + curl \ + gnupg2 \ + jq \ + git \ + make \ + shellcheck && \ + curl -sL https://deb.nodesource.com/setup_10.x | bash - && \ + apt-get install -y \ + nodejs && \ + npm install -g dockerfile_lint && \ + apt-get clean -y && \ + rm -rf /var/lib/apt/lists/* + +COPY is_ref.sh /usr/bin/is_ref +RUN chmod +x /usr/bin/is_ref + +CMD ["make", "run"] \ No newline at end of file diff --git a/github-actions/shell/Makefile b/github-actions/shell/Makefile new file mode 100644 index 0000000..9d67e1a --- /dev/null +++ b/github-actions/shell/Makefile @@ -0,0 +1,3 @@ +.PHONY: run +run: + true \ No newline at end of file diff --git a/github-actions/shell/README.md b/github-actions/shell/README.md new file mode 100644 index 0000000..f4aa444 --- /dev/null +++ b/github-actions/shell/README.md @@ -0,0 +1,3 @@ +## Github Action + +Action which allow you to execute some make commands \ No newline at end of file diff --git a/github-actions/shell/is_ref.sh b/github-actions/shell/is_ref.sh new file mode 100644 index 0000000..22edc0a --- /dev/null +++ b/github-actions/shell/is_ref.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +cat /github/workflow/event.json | jq -e ". | select(.ref==\"$REF_NAME\")" + +return_code=$? + +if [ $return_code -ne 0 ]; then + exit 78 +fi + +exit 0 \ No newline at end of file