Skip to content

Commit

Permalink
Merge pull request #19 from siisurit/10-add-github-ci
Browse files Browse the repository at this point in the history
#10 Add GitHub CI
  • Loading branch information
mcsken authored Oct 23, 2024
2 parents 224464b + 86e8552 commit 2175b32
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Continuous integration build for check-done.
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
env:
MAIN_PYTHON_VERSION: "3.12" # same as Ubuntu 24 LTS

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction
- name: Build check-done package
run: |
poetry build
- name: Run the test suite
env:
CHECK_DONE_GITHUB_APP_ID: ${{ secrets.CHECK_DONE_GITHUB_APP_ID }}
CHECK_DONE_GITHUB_APP_PRIVATE_KEY: |
${{ secrets.CHECK_DONE_GITHUB_APP_PRIVATE_KEY }}
run: |
poetry run pytest --cov=check-done --cov-branch
check-style:
runs-on: ubuntu-latest
# Disable pre-commit check on main and production to prevent
# pull request merges to fail with don't commit to branch".
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Install pre-commit
run: |
sudo apt-get install python3 python3-pip
pip install pre-commit
- name: Load cached pre-commit
id: cached-pre-commit
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commit hooks
if: steps.cached-pre-commit.outputs.cache-hit != 'true'
run: pre-commit install --install-hooks
- name: Check coding style
run: pre-commit run --all-files
14 changes: 11 additions & 3 deletions check_done/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import jwt
import requests

from check_done.common import GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, AuthenticationError, HttpBearerAuth
from check_done.common import (
CHECK_DONE_GITHUB_APP_ID,
CHECK_DONE_GITHUB_APP_PRIVATE_KEY,
AuthenticationError,
HttpBearerAuth,
)

_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code"
_SECONDS_PER_MINUTE = 60
Expand All @@ -16,6 +21,9 @@ def github_app_access_token(organization: str) -> str:
return authentication.access_token


# TODO: Refactor code into functions instead of a class.


class _Authentication:
def __init__(self, organization: str):
self.organization = organization
Expand All @@ -42,9 +50,9 @@ def _generated_jwt_token() -> str:
payload = {
"exp": _EXPIRES_AT,
"iat": _ISSUED_AT,
"iss": GITHUB_APP_ID,
"iss": CHECK_DONE_GITHUB_APP_ID,
}
return jwt.encode(payload, GITHUB_APP_PRIVATE_KEY, algorithm="RS256")
return jwt.encode(payload, CHECK_DONE_GITHUB_APP_PRIVATE_KEY, algorithm="RS256")
except Exception as error:
raise AuthenticationError(f"Cannot generate JWT token: {error}") from error

Expand Down
4 changes: 2 additions & 2 deletions check_done/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
def _issue_warning_string(issue: IssueInfo, reason_for_warning: str) -> str:
# TODO: Ponder better wording.
return (
f" Issue '#{issue.number} {issue.title}' in repository '{issue.repository.name}' "
f"should be {reason_for_warning}."
f" Done issue should be {reason_for_warning}."
f" - repository: '{issue.repository.name}', issue: '#{issue.number} {issue.title}'."
)


Expand Down
8 changes: 4 additions & 4 deletions check_done/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from requests.auth import AuthBase

load_dotenv()
_ENVVAR_GITHUB_APP_ID = "GITHUB_APP_ID"
_ENVVAR_GITHUB_APP_PRIVATE_KEY = "GITHUB_APP_PRIVATE_KEY"
GITHUB_APP_ID = os.environ.get(_ENVVAR_GITHUB_APP_ID)
GITHUB_APP_PRIVATE_KEY = os.environ.get(_ENVVAR_GITHUB_APP_PRIVATE_KEY)
_ENVVAR_CHECK_DONE_GITHUB_APP_ID = "CHECK_DONE_GITHUB_APP_ID"
_ENVVAR_CHECK_DONE_GITHUB_APP_PRIVATE_KEY = "CHECK_DONE_GITHUB_APP_PRIVATE_KEY"
CHECK_DONE_GITHUB_APP_ID = os.environ.get(_ENVVAR_CHECK_DONE_GITHUB_APP_ID)
CHECK_DONE_GITHUB_APP_PRIVATE_KEY = os.environ.get(_ENVVAR_CHECK_DONE_GITHUB_APP_PRIVATE_KEY)

_GITHUB_ORGANIZATION_NAME_AND_PROJECT_NUMBER_URL_REGEX = re.compile(
r"https://github\.com/orgs/(?P<organization_name>[a-zA-Z0-9\-]+)/projects/(?P<project_number>[0-9]+).*"
Expand Down

0 comments on commit 2175b32

Please sign in to comment.