Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovizro committed Nov 15, 2023
1 parent 5dcff8c commit bed8225
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 84 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
os: [windows-latest, ubuntu-20.04, macos-latest]
# exclude:
# # package dependencies error on macos 3.9+ for unkwown reason
# - os: macos-latest
# python-version: 3.9
# - os: macos-latest
# python-version: "3.10"
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Install typing-extensions
if: ${{ matrix.python-version == 3.6 }}
run: |
pip install typing-extensions==4.1.1
- name: Build dist and test with unittest
run: |
make build install test build_dist
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: lint

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
flake8-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install flake8
run: pip install flake8
- name: Run flake8
run: make lint
161 changes: 122 additions & 39 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,122 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
create:
workflow_dispatch:

permissions:
contents: read

jobs:
deploy-wheels:
name: Deploy wheels on ${{ matrix.os }} for ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [36, 37, 38, 39, 310]
manylinux-image: [manylinux2010, manylinux2014, manylinux_2_24]
arch: [auto]
include:
- os: ubuntu-latest
manylinux-image: manylinux2014
arch: aarch64
python-version: 36
- os: ubuntu-latest
manylinux-image: manylinux2014
arch: aarch64
python-version: 37
- os: ubuntu-latest
manylinux-image: manylinux2014
arch: aarch64
python-version: 38
- os: ubuntu-latest
manylinux-image: manylinux2014
arch: aarch64
python-version: 39
- os: ubuntu-latest
manylinux-image: manylinux2014
arch: aarch64
python-version: 310
exclude:
# manyliunx image is not a valid variation on MacOS and Windows
- os: macos-latest
manylinux-image: manylinux2010
- os: windows-latest
manylinux-image: manylinux2010
- os: macos-latest
manylinux-image: manylinux2014
- os: windows-latest
manylinux-image: manylinux2014

steps:
- uses: actions/checkout@v2
- name: Set up QEMU
if: ${{ matrix.arch == 'aarch64' }}
uses: docker/setup-qemu-action@v1
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine setuptools wheel
- name: Install cibuildwheel
run: python -m pip install cibuildwheel -U

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: 'cp${{ matrix.python-version }}-*'
CIBW_SKIP: '*musllinux*'
CIBW_ARCHS: ${{matrix.arch}}
CIBW_MANYLINUX_*_IMAGE: ${{ matrix.manylinux-image }}
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux-image }}

- name: Publish wheels to PyPI Unix
if: matrix.os != 'windows-latest'
continue-on-error: true
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload wheelhouse/*.whl
- name: Publish wheels to PyPI Windows
if: matrix.os == 'windows-latest'
continue-on-error: true
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload (Get-ChildItem wheelhouse/*.whl)
deploy-tar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine setuptools wheel
- name: Build source tar
run: |
python setup.py sdist
- name: Publish wheels to PyPI
continue-on-error: true
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*tar*
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ From pip:

From source code:

python setup.py install
git clone https://github.com/Ovizro/Karuha.git
cd Karuha
make install

## Quick Start

> Before starting, you need to make sure you have the Tinode service running locally with its gRPC port set to the default value of 16060. If your service is not local or the default port has been changed, you need to add additional server configuration items in the following code.
Create a new file `config.json` and write the following content:

```json
Expand Down Expand Up @@ -60,7 +64,7 @@ Well, you can actually go a step further and send messages to users.

Currently, if you want to reply to a message, you currently need to add a handler for the event yourself. This is not a simple process. Fortunately, we are about to introduce a command module to improve this.

Because this is a relatively low-level function, I will only give an example to show how karuha is currently used in python:
Because this is a relatively low-level API, I will only give an example to show how karuha is currently used in python:

```python
import karuha
Expand Down
95 changes: 95 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Karuha

[![License](https://img.shields.io/github/license/Ovizro/Karuha.svg)](/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/KaruhaBot.svg)](https://pypi.python.org/pypi/KaruhaBot)
![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg)

一个简单的Tinode聊天机器人框架

> 目前项目仍处于开发期,部分次要接口可能会频繁变化,造成的不便敬请谅解
库的名称`Karuha`来自游戏星空列车与白的旅行中的角色 狩叶·朗姆柯妮(カルハ・ラムコネ)

<center>

![Karuha](/docs/img/tw_icon-karuha2.png)

</center>

> カルハ・ラムコネと申します。カルハちゃんって呼んでいいわよ
# 安装

从Pypi安装:

pip install KaruhaBot

或从源码安装:

git clone https://github.com/Ovizro/Karuha.git
cd Karuha
make install

# 快速开始

在开始前,你需要确保在本地有运行的Tinode服务,其gRPC端口为默认值16060。如果你的服务不在本地,在接下来的代码中,你需要额外添加服务器的配置项。

创建一个新的文件`config.json`并写入以下内容作为配置文件:

```json
{
"server": {
"host": "localhost:16060",
"listen": "0.0.0.0:40051"
},
"bots": [
{
"name": "chatbot",
"schema": "basic",
"secret": "{chatbot_login_name}:{chatebot_login_passwd}"
}
]
}
```

> `{chatbot_login_name}``{chatebot_login_passwd}` 替换为聊天机器人在 Tinode 服务器中的登录帐户名和密码。
使用以下的命令启动聊天机器人:

python -m Karuha ./config.json

现在您可以在命令行上查看其他人发送到聊天机器人的消息。是的,这就是我们目前能做到的大部分内容。

## 更进一步?

好吧,其实我们的确可以再进一步,让我们试着回复一些消息吧。

至于为什么我并不在上面一段提及这个,因为就目前来说,回复消息的确不是几件简单的事情。这需要我们手动对事件进行绑定。但不要担心,我们很快就会有一套命令模块来简化这一流程。

由于这涉及到低层级API,故此处仅提供一个例子,以展示其目前在Python中的使用方法:

```python
import karuha
from karuha import Bot, DataEvent


bot = Bot(
"basic",
"chatbot:123456"
)


@karuha.on(DataEvent)
async def reply(event: DataEvent) -> None:
if event.server_message.content.decode() == "\"Hello chatbot!\"": # message.content is a json string
await event.bot.publish(
event.server_message.topic,
"Hello world!"
)


if __name__ = "__main__":
karuha.load_config()
karuha.add_bot(bot)
karuha.run()
```
41 changes: 0 additions & 41 deletions docs/cn/README.md

This file was deleted.

Loading

0 comments on commit bed8225

Please sign in to comment.