Skip to content

Commit

Permalink
WIP check
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Aug 23, 2019
1 parent 0a22c05 commit e934922
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/release-check-action/Dockerfile
@@ -0,0 +1,7 @@
FROM python:3.7-alpine

RUN pip install httpx

COPY . /action

ENTRYPOINT ["python", "/action/check.py"]
31 changes: 31 additions & 0 deletions .github/release-check-action/check.py
@@ -0,0 +1,31 @@
import json
import os
import pathlib
import sys

from github import add_release_check_comment, get_comments, is_release_check_comment


RELEASE_FILE_PATH = "RELEASE.md"
GITHUB_SHA = os.environ["GITHUB_SHA"]
GITHUB_EVENT_PATH = os.environ["GITHUB_EVENT_PATH"]
GITHUB_WORKSPACE = os.environ["GITHUB_WORKSPACE"]

with open(GITHUB_EVENT_PATH) as f:
event_data = json.load(f)

current_comments = get_comments(event_data)

release_file = pathlib.Path(GITHUB_WORKSPACE) / RELEASE_FILE_PATH

if not release_file.exists():
print("release file does not exist")

has_release_check_comment = any(
is_release_check_comment(comment) for comment in current_comments
)

if not has_release_check_comment:
add_release_check_comment(event_data)

sys.exit(1)
61 changes: 61 additions & 0 deletions .github/release-check-action/github.py
@@ -0,0 +1,61 @@
import os
import sys
import typing

import httpx


GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
SIGNATURE = "<!-- action-check: release-file -->"

COMMENT_TEMPLATE = f"""\
Hi, thanks for contributing to Strawberry 馃崜! We noticed that this PR\
is missing a `RELEASE.md` file. We use that to automatically\
do releases here on GitHub and, most importantly, to PyPI!
So as soon as this PR is merged, a release will be made 馃殌.
Here's an example of `RELEASE.md`:
```markdown
Release type: patch
Description of the changes, ideally with some examples, if adding a new feature.
```
Release type can be one of patch, minor or major. We use [semver](https://semver.org/),\
so make sure to pick the appropriate type. If in doubt feel free to ask :)
{SIGNATURE}
"""


def is_release_check_comment(comment: dict) -> bool:
return (
comment["user"]["login"] == "github-actions[bot]"
and SIGNATURE in comment["body"]
)


def get_comments(github_event_data: dict) -> typing.List[dict]:
comments_link = github_event_data["pull_request"]["_links"]["comments"]["href"]

comments_request = httpx.get(comments_link)

return comments_request.json()


def add_release_check_comment(github_event_data: dict):
comments_link = github_event_data["pull_request"]["_links"]["comments"]["href"]

request = httpx.post(
comments_link,
headers={"Authorization": f"token {GITHUB_TOKEN}"},
json={"body": COMMENT_TEMPLATE},
)

if request.status_code != 200:
print(request.text)
print(request.status_code)

sys.exit(1)
18 changes: 18 additions & 0 deletions .github/workflows/release-check.yml
@@ -0,0 +1,18 @@
name: Release file check

on:
pull_request:
branches:
- master

jobs:
release-file-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Release file check
uses: ./.github/release-check-action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .isort.cfg
Expand Up @@ -11,5 +11,5 @@ known_pytest=pytest
known_future_library=future
known_standard_library=types,requests
default_section=THIRDPARTY
known_third_party = base,click,github_release,graphql,hupper,pygments,starlette,uvicorn
known_third_party = base,click,github,github_release,graphql,httpx,hupper,pygments,starlette,uvicorn
sections=FUTURE,STDLIB,PYTEST,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

0 comments on commit e934922

Please sign in to comment.