diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-12-19 20:11:26 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-12-19 20:11:26 +0100 |
commit | bd28500252d015f715e2b7a51d365a3625cc54c5 (patch) | |
tree | 3fcfcfe69a9257ce638207f9e71a12f0b681501d | |
parent | adf5aa0ab0a6e91a8e3cd659d5b91a5dcdee1b4a (diff) | |
download | psutil-bd28500252d015f715e2b7a51d365a3625cc54c5.tar.gz |
improve github actions
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | .flake8 | 1 | ||||
-rw-r--r-- | .github/ISSUE_TEMPLATE/bug.md | 2 | ||||
-rw-r--r-- | .github/ISSUE_TEMPLATE/enhancement.md | 2 | ||||
-rw-r--r-- | .github/PULL_REQUEST_TEMPLATE.md | 2 | ||||
-rw-r--r-- | .github/no-response.yml | 2 | ||||
-rw-r--r-- | .github/workflows/build.yml | 11 | ||||
-rw-r--r-- | .github/workflows/issues.py (renamed from scripts/internal/github_issue_bot.py) | 107 | ||||
-rw-r--r-- | .github/workflows/issues.yml (renamed from .github/workflows/issue_bot.yml) | 15 | ||||
-rw-r--r-- | MANIFEST.in | 1 | ||||
-rwxr-xr-x | scripts/internal/download_wheels_github.py | 15 |
10 files changed, 96 insertions, 62 deletions
@@ -12,3 +12,4 @@ per-file-ignores = scripts/internal/convert_readme.py:E501,T001 psutil/tests/runner.py:T001 psutil/tests/test_memleaks.py:T001 + .github/workflows/*:T001 diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 096033db..24d01efa 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -11,7 +11,7 @@ labels: 'bug' * Architecture: { 64bit, 32bit, ARM, PowerPC, s390 } * Psutil version: { pip3 show psutil } * Python version: { python3 -V } -* Type: { core, doc, performance, scripts, tests, wheels, newapi } +* Type: { core, doc, performance, scripts, tests, wheels, new-api, installation } ## Description diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md index 0a1cbb77..2f7d75a5 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -9,7 +9,7 @@ title: "[OS] title" ## Summary * OS: { type-or-version } -* Type: { core, doc, performance, scripts, tests, wheels, newapi } +* Type: { core, doc, performance, scripts, tests, wheels, new-api } ## Description diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6b7fdee7..e8bbb2a4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,7 @@ * OS: { type-or-version } * Bug fix: { yes/no } -* Type: { core, doc, performance, scripts, tests, wheels, newapi } +* Type: { core, doc, performance, scripts, tests, wheels, new-api } * Fixes: { comma-separated list of issues fixed by this PR, if any } ## Description diff --git a/.github/no-response.yml b/.github/no-response.yml index e5afde07..56457a28 100644 --- a/.github/no-response.yml +++ b/.github/no-response.yml @@ -3,7 +3,7 @@ # Number of days of inactivity before an issue is closed for lack of response daysUntilClose: 14 # Label requiring a response -responseRequiredLabel: awaiting-response +responseRequiredLabel: need-more-info # Comment to post when closing an Issue for lack of response. # Set to `false` to disable closeComment: > diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8a98f79..25efdbc1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ # https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip on: [push] -name: Build +name: build jobs: linux-macos-win: name: ${{ matrix.os }} @@ -29,6 +29,7 @@ jobs: PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_TESTING=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/test_memleaks.py CIBW_TEST_EXTRAS: test CIBW_SKIP: cp35-* pp* + steps: - name: Cancel previous runs uses: styfle/cancel-workflow-action@0.6.0 @@ -40,15 +41,17 @@ jobs: with: python-version: 3.9 + - name: Install cibuildwheel + run: pip install cibuildwheel + # - name: (Windows) install Visual C++ for Python 2.7 # if: matrix.os == 'windows-latest' # run: | # choco install vcpython27 -f -y - name: Run tests - run: | - pip install cibuildwheel - cibuildwheel . + run: cibuildwheel . + - name: Create wheels uses: actions/upload-artifact@v2 with: diff --git a/scripts/internal/github_issue_bot.py b/.github/workflows/issues.py index ce66a293..a2beecc7 100644 --- a/scripts/internal/github_issue_bot.py +++ b/.github/workflows/issues.py @@ -4,9 +4,15 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +""" +Bot triggered by Github Actions every time a new issue, PR or comment +is created. Assign labels, provide replies, closes issues, etc. depending +on the situation. +""" + import os import re -import textwrap +import sys from github import Github @@ -132,6 +138,10 @@ def is_new(issue): return issue.comments == 0 +def is_comment(issue): + return not is_new(issue) + + def has_label(issue, label): assigned = [x.name for x in issue.labels] return label in assigned @@ -151,52 +161,34 @@ def get_repo(): return Github(token).get_repo(repo) -def get_issue_event(): - url = os.environ.get('GITHUB_ISSUE_URL') - if url: # issue - num = int(url.split('/')[-1]) - else: # PR - url = os.environ['GITHUB_REF'] - num = int(url.split('/')[-2]) - repo = get_repo() - return repo.get_issue(number=num) - - # --- actions def log(msg): - print(">>> %s <<<" % msg) + if '\n' in msg or "\r\n" in msg: + print(">>>\n%s\n<<<" % msg) + else: + print(">>> %s <<<" % msg) def add_label(issue, label): def should_add(issue, label): if has_label(issue, label): - log("issue %r already has label %r" % (issue, label)) + log("already has label %r" % (label)) return False for left, right in ILLOGICAL_PAIRS: if label == left and has_label(issue, right): - log("issue %r already has label %r" % (issue, label)) + log("already has label" % (label)) return False return not has_label(issue, label) if not should_add(issue, label): + log("should not add label %r" % label) return - type_ = "PR:" if is_pr(issue) else "issue:" - assigned = ', '.join([x.name for x in issue.labels]) - log(textwrap.dedent("""\ - %-10s %s: %s - assigned: %s - new: %s""" % ( - type_, - issue.number, - issue.title, - assigned, - label, - ))) + log("add label %r" % label) issue.add_to_labels(label) @@ -212,26 +204,38 @@ def add_labels_from_text(issue, text): add_label(issue, label) -def add_labels_from_body(issue, text): +def add_labels_from_new_body(issue, text): + log("start searching for template lines in new issue/PR body") # add os label - print(repr(text)) r = re.search(r"\* OS:.*?\n", text) + log("search for 'OS: ...' line") if r: + log("found") add_labels_from_text(issue, r.group(0)) + else: + log("not found") + # add bug/enhancement label + log("search for 'Bug fix: y/n' line") r = re.search(r"\* Bug fix:.*?\n", text) if is_pr(issue) and \ r is not None and \ not has_label(issue, "bug") and \ not has_label(issue, "enhancement"): + log("found") s = r.group(0).lower() if 'yes' in s: add_label(issue, 'bug') else: add_label(issue, 'enhancement') + else: + log("not found") + # add type labels + log("search for 'Type: ...' line") r = re.search(r"\* Type:.*?\n", text) if r: + log("found") s = r.group(0).lower() if 'doc' in s: add_label(issue, 'doc') @@ -243,43 +247,56 @@ def add_labels_from_body(issue, text): add_label(issue, 'tests') if 'wheels' in s: add_label(issue, 'wheels') - if 'newapi' in s: - add_label(issue, 'api') - - -# --- run + if 'new-api' in s: + add_label(issue, 'new-api') + if 'new-platform' in s: + add_label(issue, 'new-platform') + else: + log("not found") -def process_both(issue): - add_labels_from_text(issue, issue.title) - add_labels_from_body(issue, issue.body) +# --- events -def process_issue(issue): +def on_new_issue(issue): def has_text(text): return text in issue.title.lower() or text in issue.body.lower() + log("searching for missing Python.h") if has_text("missing python.h") or \ has_text("python.h: no such file or directory") or \ "#include<Python.h>\n^~~~" in issue.body.replace(' ', '') or \ "#include<Python.h>\r\n^~~~" in issue.body.replace(' ', ''): + log("found") issue.create_comment(REPLY_MISSING_PYTHON_HEADERS) issue.edit(state='closed') return -def process_pr(pr): +def on_new_pr(issue): + pass + + +def on_new_comment(issue): pass def main(): - log("Running issue/PR bot.") - issue = get_issue_event() - process_both(issue) - if is_issue(issue): - process_issue(issue) + issue = get_repo().get_issue(number=int(sys.argv[1])) + stype = "issue" if is_issue(issue) else "PR" + log("running issue bot for %s %r" % (stype, issue)) + + if is_new(issue): + log("new %s\n%s" % (stype, issue.body)) + add_labels_from_text(issue, issue.title) + add_labels_from_new_body(issue, issue.body) + if is_issue(issue): + on_new_issue(issue) + if is_pr(issue): + on_new_pr(issue) else: - process_pr(issue) + log("new comment: \n", issue.body) + on_new_comment(issue) if __name__ == '__main__': diff --git a/.github/workflows/issue_bot.yml b/.github/workflows/issues.yml index 223c0b6e..17355dee 100644 --- a/.github/workflows/issue_bot.yml +++ b/.github/workflows/issues.yml @@ -1,22 +1,27 @@ -name: Issue/PR bot +name: issue-bot on: issues: types: [opened] pull_request: typed: [opened] + issue_comment: + types: [created] jobs: build: runs-on: ubuntu-latest steps: + # install python - uses: actions/checkout@v2 - - name: Set up Python 3.8 + - name: Install Python uses: actions/setup-python@v2 with: python-version: 3.8 + # install deps + - name: Install deps + run: python -m pip install --upgrade pip PyGithub + # run - name: Run env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_ISSUE_URL: ${{ github.event.issue.url }} run: | - PYTHONUNBUFFERED=1 python -m pip install --upgrade pip PyGithub - PYTHONUNBUFFERED=1 python scripts/internal/github_issue_bot.py + python .github/workflows/issues.py ${{ github.event.issue.number }} diff --git a/MANIFEST.in b/MANIFEST.in index df112833..d651cd4e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -123,7 +123,6 @@ include scripts/internal/download_wheels_github.py include scripts/internal/fix_flake8.py include scripts/internal/generate_manifest.py include scripts/internal/git_pre_commit.py -include scripts/internal/github_issue_bot.py include scripts/internal/print_access_denied.py include scripts/internal/print_announce.py include scripts/internal/print_api_speed.py diff --git a/scripts/internal/download_wheels_github.py b/scripts/internal/download_wheels_github.py index 5ce98b84..a344ec49 100755 --- a/scripts/internal/download_wheels_github.py +++ b/scripts/internal/download_wheels_github.py @@ -19,6 +19,7 @@ import argparse import json import os import requests +import sys import zipfile from psutil import __version__ as PSUTIL_VERSION @@ -79,10 +80,18 @@ def run(): def main(): global TOKEN parser = argparse.ArgumentParser(description='GitHub wheels downloader') - parser.add_argument('--tokenfile', required=True) + parser.add_argument('--token') + parser.add_argument('--tokenfile') args = parser.parse_args() - with open(os.path.expanduser(args.tokenfile)) as f: - TOKEN = f.read().strip() + + if args.tokenfile: + with open(os.path.expanduser(args.tokenfile)) as f: + TOKEN = f.read().strip() + elif args.token: + TOKEN = args.token + else: + return sys.exit('specify --token or --tokenfile args') + try: run() finally: |