-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM python:3.7-alpine | ||
|
||
RUN pip install httpx | ||
|
||
COPY . /action | ||
|
||
ENTRYPOINT ["python", "/action/check.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters