forked from Zuehlke/zuehlke.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate automation to GitHub action.
- Loading branch information
1 parent
2efd08e
commit 6315e48
Showing
18 changed files
with
175 additions
and
583 deletions.
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,10 @@ | ||
FROM python:3.8 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY ./src/ . | ||
|
||
CMD [ "python", "/usr/src/app/main.py" ] |
File renamed without changes.
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,5 @@ | ||
name: 'Data Update' | ||
description: 'Update contributions & people form the GitHub API.' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
File renamed without changes.
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,13 @@ | ||
# Env var names | ||
ENV_GITHUB_PAT = "GITHUB_PAT" | ||
ENV_DATA_DIR = "DATA_DIR" | ||
|
||
# API and rate limits | ||
API_REQUEST_DELAY_SEC = 1 | ||
RATE_LIMIT_BUFFER_SEC = 60 | ||
RATE_LIMIT_MAX_AGE_SEC = 30 | ||
MAX_RETRIES = 1 | ||
|
||
# Files | ||
CONTRIBUTIONS_FILENAME = "contributions.json" | ||
PEOPLE_FILENAME = "people.json" |
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,59 @@ | ||
import json | ||
import os | ||
from pathlib import Path | ||
|
||
import consts | ||
import log | ||
|
||
|
||
class Context: | ||
""" | ||
Represents an application context containing shared information such as configurations, paths and secrets. | ||
""" | ||
|
||
def __init__(self, out_dir_path, github_token): | ||
""" | ||
Private constructor. | ||
""" | ||
self._data_dir_path = out_dir_path | ||
self._github_token = github_token | ||
|
||
@staticmethod | ||
def _read_config_file(main_script_path): | ||
file_path = main_script_path.parent.joinpath("config.json") | ||
try: | ||
with open(file_path) as infile: | ||
return json.load(infile) | ||
except FileNotFoundError: | ||
log.abort_and_exit("CTXT", f"Context init failed, could not to read config file '{file_path}': not found.") | ||
|
||
@staticmethod | ||
def _read_env_var(var_name): | ||
val = os.getenv(var_name) | ||
if val is None: | ||
log.abort_and_exit("CTXT", f"Context init failed, required env var '{var_name}' is not set.") | ||
return val | ||
|
||
@staticmethod | ||
def create(): | ||
""" | ||
Read environment variables and create a new Context. | ||
:return: newly created Context object | ||
""" | ||
data_dir_path = Path(Context._read_env_var(consts.ENV_DATA_DIR)) | ||
github_pat = Context._read_env_var(consts.ENV_GITHUB_PAT) | ||
return Context(data_dir_path, github_pat) | ||
|
||
def get_github_token(self): | ||
""" | ||
Get the GitHub API token. | ||
:return: GitHub API token. | ||
""" | ||
return self._github_token | ||
|
||
def get_data_dir_path(self): | ||
""" | ||
Get the pathlib.Path to the data directory, where data file outputs should go. | ||
:return: Path to the data directory | ||
""" | ||
return self._data_dir_path |
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
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
File renamed without changes.
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
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,43 @@ | ||
import os | ||
|
||
import log | ||
from pathlib import Path | ||
|
||
import util | ||
import jobs | ||
from context import Context | ||
from github_api import GitHubApi | ||
|
||
|
||
def run_jobs(context, github_api): | ||
""" | ||
Run predefined set of data update jobs. | ||
:param context: application context | ||
:param github_api: GitHub API wrapper | ||
""" | ||
util.log_rate_limit_status("MAIN", github_api) | ||
jobs.JobCollectOrgRepos.initialize(context, github_api).run() | ||
# jobs.JobCollectOrgMembers.initialize(context, github_api).run() | ||
util.log_rate_limit_status("MAIN", github_api) | ||
|
||
|
||
def main(): | ||
# Absolute path of this script. | ||
script_path = Path(os.path.abspath(__file__)) | ||
|
||
# Set up context and API wrappers. | ||
context = Context.create() | ||
github_api = GitHubApi(context) | ||
|
||
# Run jobs. | ||
run_jobs(context, github_api) | ||
|
||
# Terminate. | ||
log.terminate_successfully("MAIN") | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
main() | ||
except Exception as ex: | ||
log.unhandled_exception_exit("MAIN", ex) |
File renamed without changes.
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,35 @@ | ||
import time | ||
|
||
import log | ||
|
||
|
||
def decode_command_output_buffer(buffer): | ||
return buffer.decode("utf-8").strip() | ||
|
||
|
||
def get_time_format_pattern(): | ||
""" | ||
Return default datetime format string. | ||
:return: default datetime format string | ||
""" | ||
return "%Y/%m/%d %H:%M:%S" | ||
|
||
|
||
def epoch_to_local_datetime(epoch_time): | ||
""" | ||
Convert an UTC epoch value to a formatted date and time string in local time. | ||
:param epoch_time: epoch seconds value | ||
:return: formatted local date and time string | ||
""" | ||
return time.strftime(get_time_format_pattern(), time.localtime(epoch_time)) | ||
|
||
|
||
def log_rate_limit_status(tag, github_api): | ||
""" | ||
Log the current rate limit status. | ||
:param tag: log location identifier | ||
:param github_api: GitHub API wrapper | ||
""" | ||
rl_status = github_api.request_rate_limit_status() | ||
log.info(tag, | ||
f"{rl_status['remaining']} calls remaining, resets at {epoch_to_local_datetime(rl_status['reset_at_utc'])}.") |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.