Skip to content

Commit

Permalink
Add github action related code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien 'Bubu' Busi committed Jun 19, 2019
1 parent c06d390 commit fc34b2e
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 7 deletions.
65 changes: 65 additions & 0 deletions .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"
}
}
16 changes: 10 additions & 6 deletions 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
## [Released]

- [0.0.x]
- [0.0.1](./changelogs/0.0.1.md) - 2019-06-19
33 changes: 33 additions & 0 deletions 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:
Expand Down Expand Up @@ -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
19 changes: 18 additions & 1 deletion 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
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
@@ -0,0 +1,3 @@
# [0.0.1] - 2019-06-19

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

## Added

## Changed

## Fixed
22 changes: 22 additions & 0 deletions github-actions/pypi/Dockerfile
@@ -0,0 +1,22 @@
FROM python:3.7.2

LABEL "name"="pypi"
LABEL "maintainer"="Stan Chollet <stanislas.chollet@gmail.com>"
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
@@ -0,0 +1 @@
Fork of https://github.com/mariamrf/py-package-publish-action
36 changes: 36 additions & 0 deletions 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
23 changes: 23 additions & 0 deletions github-actions/release/Dockerfile
@@ -0,0 +1,23 @@
FROM golang:1.11

LABEL "name"="github-release"
LABEL "maintainer"="Stan Chollet <stanislas.chollet@gmail.com>"
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
@@ -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
35 changes: 35 additions & 0 deletions github-actions/shell/Dockerfile
@@ -0,0 +1,35 @@
FROM ruby:2-slim

LABEL "name"="Shell Action"
LABEL "maintainer"="Stan Chollet <stanislas.chollet@gmail.com>"
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"]
3 changes: 3 additions & 0 deletions github-actions/shell/Makefile
@@ -0,0 +1,3 @@
.PHONY: run
run:
true
3 changes: 3 additions & 0 deletions github-actions/shell/README.md
@@ -0,0 +1,3 @@
## Github Action

Action which allow you to execute some make commands
11 changes: 11 additions & 0 deletions 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

0 comments on commit fc34b2e

Please sign in to comment.