Skip to content
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
67 changes: 67 additions & 0 deletions .github/pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "github-rest-api>=0.25.0",
# ]
# ///

"""Create a PR from the specified branch to dev.
The branch is updated (using dev) before creating the PR.
"""

from argparse import ArgumentParser, Namespace
from github_rest_api import Repository


def parse_args(args=None, namespace=None) -> Namespace:
"""Parse command-line arguments.
:param args: The arguments to parse.
If None, the arguments from command-line are parsed.
:param namespace: An inital Namespace object.
:return: A namespace object containing parsed options.
"""
parser = ArgumentParser(description="Create pull requests to the dev branch.")
parser.add_argument(
"--token",
dest="token",
required=True,
help="The personal access token for authentication.",
)
parser.add_argument(
"--head-branch",
dest="head_branch",
required=True,
help="The head branch containing changes to merge.",
)
parser.add_argument(
"--base-branch",
dest="base_branch",
required=True,
help="The base branch to merge changes into.",
)
return parser.parse_args(args=args, namespace=namespace)


def main():
"""Main entrance of the script,
which creates a PR from the specified branch to dev.
The branch is updated (using dev) before creating the PR.
"""
args = parse_args()
# skip branches with the pattern _*
if args.head_branch.startswith("_"):
return
repo = Repository(args.token, "legendu-net", "github_rest_api")
repo.create_pull_request(
{
"base": args.base_branch,
"head": args.head_branch,
"title": f"Merge {args.head_branch} Into {args.base_branch}",
},
)


if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions .github/workflows/create_pr_dev_to_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Create PR From dev To main
on:
push:
branches:
- dev
jobs:
create_pr_dev_to_main:
runs-on: ubuntu-latest
steps:
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sudo env UV_INSTALL_DIR="/usr/local/bin" sh
- uses: actions/checkout@v6
- name: Create PR From dev To main
run: |
.github/pr.py --head-branch dev --base-branch main --token ${{ secrets.GITHUBACTIONS }}

19 changes: 19 additions & 0 deletions .github/workflows/create_pr_to_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Create PR To dev
on:
push:
branches-ignore:
- main
- dev
- gh-pages*
jobs:
create_pr_to_dev:
runs-on: ubuntu-latest
steps:
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sudo env UV_INSTALL_DIR="/usr/local/bin" sh
- uses: actions/checkout@v6
- name: Create PR to dev
run: |
.github/pr.py --head-branch ${{ github.ref_name }} --base-branch dev --token ${{ secrets.GITHUBACTIONS }}

34 changes: 9 additions & 25 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,18 @@ on:
jobs:
lint_code:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
steps:
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v6
- name: Install dependencies
run: |
curl -sSL https://raw.githubusercontent.com/legendu-net/icon/main/install_icon.sh | sudo bash -
icon pt -ic
~/.local/bin/poetry env use python3
~/.local/bin/poetry install
- name: Lint with pylint
curl -LsSf https://astral.sh/uv/install.sh | sh
~/.local/bin/uv sync --all-extras
- name: Lint with ruff
run: |
~/.local/bin/poetry run pylint -E github_rest_api/ tests/
# - name: Lint with pytype
# run: |
# ~/.local/bin/poetry run pytype ./
~/.local/bin/uv run ruff check github_rest_api/ tests/
- name: Lint with Ty
run: |
~/.local/bin/uv run ty check
- name: Check code format
run: |
~/.local/bin/poetry run black --check ./
~/.local/bin/uv run ruff format --check ./
14 changes: 5 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ jobs:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install Poetry
- uses: actions/checkout@v6
- name: Install uv
run: |
pip3 install -U git+https://github.com/dclong/xinstall@main
xinstall pt -ic
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Build and Publish Package to PyPI
run: |
~/.local/bin/poetry publish --build -u __token__ -p ${{ secrets.PYPI_GITHUB_REST_API }}
~/.local/bin/uv build
ls -lha dist/
~/.local/bin/uv publish -u __token__ -p ${{ secrets.PYPI_AIUTIL }}
# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions github_rest_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""GitHub REST APIs.
"""
"""GitHub REST APIs."""

from .github import Repository # noqa: F401
3 changes: 1 addition & 2 deletions github_rest_api/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
"""GitHub Actions related utils.
"""
"""GitHub Actions related utils."""
6 changes: 3 additions & 3 deletions github_rest_api/actions/cargo/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Benchmark action using cargo criterion.
"""
"""Benchmark action using cargo criterion."""

from typing import Callable
import tempfile
from pathlib import Path
Expand Down Expand Up @@ -166,7 +166,7 @@ def _reg_value(value: str):


def _sort_cips(
cips: list[tuple[tuple[str, str, str], Path]]
cips: list[tuple[tuple[str, str, str], Path]],
) -> list[tuple[tuple[str, str, str], Path]]:
"""Sort confidence intervals according to the average performance changes."""

Expand Down
6 changes: 3 additions & 3 deletions github_rest_api/actions/cargo/profiling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Utils for profiling Rust applications.
"""
"""Utils for profiling Rust applications."""

from typing import Iterable
from pathlib import Path
import time
Expand Down Expand Up @@ -95,7 +95,7 @@ def _save_flamegraph(prof_dir: Path, history: int = 5):

def _gen_markdown(svgs: Iterable[Path], prof_dir: Path) -> None:
def _gen_link(svg: Path):
svg = svg.name
svg: str = svg.name
yyyymmdd = svg[:8]
prof_name = svg[9:-4]
return f"- [{prof_name} - {yyyymmdd}]({svg})"
Expand Down
4 changes: 2 additions & 2 deletions github_rest_api/actions/cargo/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Util functions for building GitHub Actions for Rust projects.
"""
"""Util functions for building GitHub Actions for Rust projects."""

from ...utils import run_cmd


Expand Down
6 changes: 3 additions & 3 deletions github_rest_api/actions/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Util functions for GitHub actions.
"""
"""Util functions for GitHub actions."""

from typing import Iterable
from pathlib import Path
import random
Expand All @@ -16,7 +16,7 @@ def __init__(self, branch: str, branch_alt: str):
super().__init__(msg)


def config_git(local_repo_dir: str, user_email: str, user_name: str):
def config_git(local_repo_dir: str | Path, user_email: str, user_name: str):
"""Config Git.
:param local_repo_dir: The root directory of the project.
:param user_email: The email of the user (no need to be a valid one).
Expand Down
Loading