Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redis dep. JSON is much simpler #374

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/bundle_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ jobs:
# Its necessary to do this here, since 'schedule' events cannot (currently)
# be limited (they run on all forks' default branches).
if: startswith(github.repository, 'adafruit/')
services:
redis:
image: redis
ports:
- 6379/tcp
options: --entrypoint redis-server
steps:
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.12
- name: Load contributor cache
uses: actions/cache@v4
with:
key: "contributor-cache"
path: "contributors.json"
- name: Versions
run: |
python3 --version
Expand Down
30 changes: 15 additions & 15 deletions adabot/circuitpython_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@

from datetime import date
from io import StringIO
import json
import os
import pathlib
import shlex
import subprocess

import redis as redis_py

import sh
from sh.contrib import git

from adabot import github_requests as gh_reqs
from adabot.lib import common_funcs
from adabot import circuitpython_library_download_stats as dl_stats

REDIS = None
if "GITHUB_WORKSPACE" in os.environ:
REDIS = redis_py.StrictRedis(port=os.environ["REDIS_PORT"])
else:
REDIS = redis_py.StrictRedis()

BUNDLES = ["Adafruit_CircuitPython_Bundle", "CircuitPython_Community_Bundle"]

Expand Down Expand Up @@ -380,20 +375,17 @@ def get_contributors(repo, commit_range):
return contributors
for log_line in output.split("\n"):
sha, author_email, committer_email = log_line.split(",")
author = REDIS.get("github_username:" + author_email)
committer = REDIS.get("github_username:" + committer_email)
author = CONTRIBUTOR_CACHE.get("github_username:" + author_email, None)
committer = CONTRIBUTOR_CACHE.get("github_username:" + committer_email, None)
if not author or not committer:
github_commit_info = gh_reqs.get("/repos/" + repo + "/commits/" + sha)
github_commit_info = github_commit_info.json()
if github_commit_info["author"]:
author = github_commit_info["author"]["login"]
REDIS.set("github_username:" + author_email, author)
CONTRIBUTOR_CACHE["github_username:" + author_email] = author
if github_commit_info["committer"]:
committer = github_commit_info["committer"]["login"]
REDIS.set("github_username:" + committer_email, committer)
else:
author = author.decode("utf-8")
committer = committer.decode("utf-8")
CONTRIBUTOR_CACHE["github_username:" + committer_email] = committer

if committer_email == "noreply@github.com":
committer = None
Expand Down Expand Up @@ -506,7 +498,7 @@ def new_release(bundle, bundle_path):
release_description.append(
"The libraries in each release are compiled for all recent major versions of CircuitPython."
" Please download the one that matches the major version of your CircuitPython. For example"
", if you are running 8.2.6 you should download the `8.x` bundle.\n"
", if you are running 9.1.1 you should download the `9.x` bundle.\n"
)

release_description.append(
Expand Down Expand Up @@ -554,6 +546,12 @@ def new_release(bundle, bundle_path):


if __name__ == "__main__":
contributor_cache_fn = pathlib.Path("contributors.json").resolve()
if contributor_cache_fn.exists():
CONTRIBUTOR_CACHE = json.loads(contributor_cache_fn.read_text())
else:
CONTRIBUTOR_CACHE = {}

bundles_dir = os.path.abspath(".bundles")
if "GITHUB_WORKSPACE" in os.environ:
git.config("--global", "user.name", "adabot")
Expand All @@ -570,3 +568,5 @@ def new_release(bundle, bundle_path):
except RuntimeError as e:
print("Failed to update and release:", cp_bundle)
print(e)
finally:
contributor_cache_fn.write_text(json.dumps(CONTRIBUTOR_CACHE))
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ packaging==22.0
pylint==2.11.1
pytest
pyyaml>=5.4.1
redis==4.5.4
requests==2.32.0
sh==1.12.14
requests-cache==0.5.2
Expand Down
Loading