Skip to content

Commit 30420fa

Browse files
authored
feat: 从环境变量中读取测试相关变量 (#236)
* docs(examples): 简化 noneflow 的写法 不再需要单独的插件测试 job * feat: 从环境变量中读取 REGISTRY_BASE_URL 和 STORE_BASE_URL 方便在测试环境中测试脚本 * docs(examples): 更新运行 store_test 的方法 * feat: 从环境变量中读取 DOCKER_IMAGES_VERSION * chore: 添加并调整注释的位置 * ci: docker tags 使用 prefix 来添加 python 版本 * ci: docker tags 使用 flavor 来添加 prefix
1 parent 338baeb commit 30420fa

File tree

4 files changed

+25
-104
lines changed

4 files changed

+25
-104
lines changed

.github/workflows/docker-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ jobs:
3838
id: metadata
3939
with:
4040
images: ghcr.io/nonebot/nonetest
41+
flavor: |
42+
prefix=${{ matrix.python-version }}-,onlatest=true
4143
tags: |
4244
type=semver,pattern={{version}}
43-
type=raw,value=${{ matrix.python-version }}-{{branch}}
45+
type=ref,event=branch
4446
4547
- name: Build and Publish
4648
uses: docker/build-push-action@v6

examples/noneflow.yml

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -15,91 +15,9 @@ concurrency:
1515
cancel-in-progress: false
1616

1717
jobs:
18-
check:
19-
runs-on: ubuntu-latest
20-
name: check
21-
# do not run on forked PRs, do not run on not related issues, do not run on pr comments
22-
if: |
23-
!(
24-
(
25-
github.event.pull_request &&
26-
(
27-
github.event.pull_request.head.repo.fork ||
28-
!(
29-
contains(github.event.pull_request.labels.*.name, 'Plugin') ||
30-
contains(github.event.pull_request.labels.*.name, 'Adapter') ||
31-
contains(github.event.pull_request.labels.*.name, 'Bot')
32-
)
33-
)
34-
) ||
35-
(
36-
github.event_name == 'issue_comment' && github.event.issue.pull_request
37-
)
38-
)
39-
steps:
40-
- run: echo "Check passed"
41-
reaction:
42-
runs-on: ubuntu-latest
43-
name: reaction
44-
needs: check
45-
if: |
46-
(
47-
github.event_name == 'issue_comment' &&
48-
github.event.action == 'created'
49-
) ||
50-
(
51-
github.event_name == 'issues' &&
52-
github.event.action == 'opened'
53-
)
54-
steps:
55-
- name: Generate token
56-
id: generate-token
57-
uses: tibdex/github-app-token@v2
58-
with:
59-
app_id: ${{ secrets.APP_ID }}
60-
private_key: ${{ secrets.APP_KEY }}
61-
62-
- name: Reaction on issue
63-
if: github.event_name == 'issues'
64-
run: |
65-
gh api --method POST /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions -f "content=rocket"
66-
env:
67-
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
68-
69-
- name: Reaction on issue comment
70-
if: github.event_name == 'issue_comment'
71-
run: |
72-
gh api --method POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f "content=rocket"
73-
env:
74-
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
75-
plugin_test:
76-
runs-on: ubuntu-latest
77-
name: nonebot2 plugin test
78-
needs: check
79-
permissions:
80-
issues: read
81-
outputs:
82-
result: ${{ steps.plugin-test.outputs.RESULT }}
83-
output: ${{ steps.plugin-test.outputs.OUTPUT }}
84-
metadata: ${{ steps.plugin-test.outputs.METADATA }}
85-
steps:
86-
- name: Install Poetry
87-
if: ${{ !startsWith(github.event_name, 'pull_request') }}
88-
run: pipx install poetry
89-
90-
- name: Setup Python
91-
uses: actions/setup-python@v5
92-
with:
93-
python-version: "3.x"
94-
95-
- name: Test Plugin
96-
id: plugin-test
97-
run: |
98-
curl -sSL https://github.com/nonebot/noneflow/releases/latest/download/plugin_test.py | python -
9918
noneflow:
10019
runs-on: ubuntu-latest
10120
name: noneflow
102-
needs: plugin_test
10321
steps:
10422
- name: Generate token
10523
id: generate-token
@@ -127,12 +45,10 @@ jobs:
12745
"base": "master",
12846
"plugin_path": "assets/plugins.json",
12947
"bot_path": "assets/bots.json",
130-
"adapter_path": "assets/adapters.json"
48+
"adapter_path": "assets/adapters.json",
49+
"registry_repository": "nonebot/registry"
13150
}
13251
env:
133-
PLUGIN_TEST_RESULT: ${{ needs.plugin_test.outputs.result }}
134-
PLUGIN_TEST_OUTPUT: ${{ needs.plugin_test.outputs.output }}
135-
PLUGIN_TEST_METADATA: ${{ needs.plugin_test.outputs.metadata }}
13652
APP_ID: ${{ secrets.APP_ID }}
13753
PRIVATE_KEY: ${{ secrets.APP_KEY }}
13854
PRE_COMMIT_HOME: /github/workspace/.cache/.pre-commit

examples/store-test.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,26 @@ jobs:
3535
repository: nonebot/noneflow
3636
fetch-depth: 0
3737

38-
- name: Install poetry
39-
run: pipx install poetry
40-
41-
- uses: actions/setup-python@v5
38+
- name: Install the latest version of uv
39+
uses: astral-sh/setup-uv@v3
4240
with:
43-
python-version: "3.x"
44-
45-
- name: Prepare test
46-
run: |
47-
git checkout `git describe --abbrev=0 --tags`
48-
poetry config virtualenvs.prefer-active-python true
49-
poetry install
41+
enable-cache: true
5042

5143
- name: Test plugin
5244
if: ${{ !contains(fromJSON('["Bot", "Adapter", "Plugin"]'), github.event.client_payload.type) }}
5345
run: |
54-
poetry run python -m src.utils.store_test --offset ${{ github.event.inputs.offset || 0 }} --limit ${{ github.event.inputs.limit || 50 }} ${{ github.event.inputs.args }}
46+
uv run --no-dev --extra plugin python -m src.providers.store_test --offset ${{ github.event.inputs.offset || 0 }} --limit ${{ github.event.inputs.limit || 50 }} ${{ github.event.inputs.args }}
5547
5648
- name: Update registry(Plugin)
5749
if: github.event.client_payload.type == 'Plugin'
58-
run: poetry run python -m src.utils.store_test -k '${{ github.event.client_payload.key }}' -f
50+
run: uv run --no-dev --extra plugin python -m src.providers.store_test -k '${{ github.event.client_payload.key }}' -f
5951
env:
6052
PLUGIN_CONFIG: ${{ github.event.client_payload.config }}
6153
PLUGIN_DATA: ${{ github.event.client_payload.data }}
6254

6355
- name: Update registry(Bot, Apdater)
6456
if: ${{ contains(fromJSON('["Bot", "Adapter"]'), github.event.client_payload.type) }}
65-
run: poetry run python -m src.utils.store_test -l 0
57+
run: uv run --no-dev --extra plugin python -m src.providers.store_test -l 0
6658

6759
- name: Upload results
6860
uses: actions/upload-artifact@v4

src/providers/constants.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1+
import os
2+
13
# NoneBot 插件商店测试结果
24
# https://github.com/nonebot/registry/tree/results
3-
REGISTRY_BASE_URL = "https://raw.githubusercontent.com/nonebot/registry/results"
5+
REGISTRY_BASE_URL = (
6+
os.environ.get("REGISTRY_BASE_URL")
7+
or "https://raw.githubusercontent.com/nonebot/registry/results"
8+
)
49
REGISTRY_RESULTS_URL = f"{REGISTRY_BASE_URL}/results.json"
510
REGISTRY_PLUGINS_URL = f"{REGISTRY_BASE_URL}/plugins.json"
611
REGISTRY_PLUGIN_CONFIG_URL = f"{REGISTRY_BASE_URL}/plugin_configs.json"
712

813
# NoneBot 插件商店
914
# https://github.com/nonebot/nonebot2/tree/master/assets
10-
STORE_BASE_URL = "https://raw.githubusercontent.com/nonebot/nonebot2/master/assets"
15+
STORE_BASE_URL = (
16+
os.environ.get("STORE_BASE_URL")
17+
or "https://raw.githubusercontent.com/nonebot/nonebot2/master/assets"
18+
)
1119
STORE_ADAPTERS_URL = f"{STORE_BASE_URL}/adapters.json"
1220
STORE_BOTS_URL = f"{STORE_BASE_URL}/bots.json"
1321
STORE_DRIVERS_URL = f"{STORE_BASE_URL}/drivers.json"
1422
STORE_PLUGINS_URL = f"{STORE_BASE_URL}/plugins.json"
1523
"""plugin_test.py 中也有一个常量,需要同时修改"""
1624

17-
DOCKER_IMAGES = "ghcr.io/nonebot/nonetest:{}-main"
25+
# 商店测试镜像
26+
# https://github.com/orgs/nonebot/packages/container/package/nonetest
27+
DOCKER_IMAGES_VERSION = os.environ.get("DOCKER_IMAGES_VERSION") or "latest"
28+
DOCKER_IMAGES = f"ghcr.io/nonebot/nonetest:{{}}-{DOCKER_IMAGES_VERSION}"

0 commit comments

Comments
 (0)