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
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: ci

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: 単体テスト
run: python3 -m unittest discover -s tests -v
- name: lock の形を確かめる
run: |
python3 - << 'PYEOF'
import json, pathlib
lock = json.loads(pathlib.Path('plugins.lock.json').read_text(encoding='utf-8'))
assert lock, 'lock が空です'
for name, e in lock.items():
assert e['source'].split(':')[0] in ('modrinth', 'github', 'compat', 'manual'), (name, e['source'])
assert e['version'] and e['file'], name
if e['source'].startswith(('modrinth:', 'github:')):
assert e['url'].startswith('https://'), name
assert len(e['sha256']) == 64, name
print(f"{len(lock)} 件のエントリの形が正しい")
PYEOF
66 changes: 66 additions & 0 deletions .github/workflows/plugin-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: plugin-lock

# plugins.lock.json の確かめと更新。TORO-Proxy の plugin-pins と同じ型。
# プルリクエストでは、固定した版を配布元の公開ハッシュと比べる。
# 週に1度 (と手動で) 新しいリリースを調べて PR を作る。

on:
schedule:
- cron: '31 19 * * 2'
workflow_dispatch:
pull_request:
paths:
- 'plugins.lock.json'
- 'auto_update_plugins.py'
- '.github/workflows/plugin-lock.yml'

permissions:
contents: read

concurrency:
group: plugin-lock-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: 固定した版を確かめる
env:
GH_TOKEN: ${{ github.token }}
run: python3 auto_update_plugins.py check

update:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v7
- name: 新しいリリースを調べる
env:
GH_TOKEN: ${{ github.token }}
run: python3 auto_update_plugins.py update
- name: 変わっていれば PR を作る
env:
GH_TOKEN: ${{ github.token }}
run: |
if git diff --quiet -- plugins.lock.json; then
echo '更新はありません'
exit 0
fi
branch="aup/update-$(date +%Y%m%d)"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b "$branch"
git add plugins.lock.json
git commit -m 'プラグインの固定を最新リリースへ上げる'
git push -u origin "$branch"
gh pr create --title 'プラグインの固定を最新リリースへ上げる' \
--body 'auto_update_plugins.py update の自動生成。check が配布元の公開ハッシュと実ダウンロードの一致を確かめてからマージすること。' \
--base main --head "$branch"
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# AutoUpdatePlugins

toro-main (Paper) のプラグインを、版を固定して配布元の公開ハッシュで確かめながらそろえるためのツール。
旧実装 (dev ブランチにあった、最新版を無検証で上書きする方式) は廃止し、TORO-Proxy の
plugin-pins と同じ lock 駆動の設計に作り替えた。

## 設計

- `plugins.lock.json` が正本。プラグインごとに配布元・版・ファイル名・URL・ハッシュを持つ。
- `auto_update_plugins.py` は標準ライブラリだけの Python で、サブコマンドは3つ。
- `check`: 固定した版について、配布元が現在公開している情報と、実際にダウンロードした
もののハッシュを、lock と照合する。
- `update`: 配布元の最新リリースを解決し、ダウンロードして公開ハッシュと一致することを
確かめてから lock を書き換える。上げるかどうかは PR のレビューで決める。
- `fetch <dir>`: lock の版をディレクトリへ取りそろえる。既にある jar はハッシュが合えば
取り直さず、版上げで旧くなった jar は glob に合うものを除く。本番の plugins へ直接
書く用途ではなく、staging へそろえて運用の段階適用で配置する。
- 配布元 (`source`) は4種。
- `modrinth:<project>`: Modrinth。版は loader が Paper 系の release から選ぶ。公開ハッシュは
ファイルの sha512。環境変数 `AUP_GAME_VERSION` があればゲーム版でも絞る。
- `github:<owner/repo>`: GitHub Releases。アセットは glob で選ぶ。公開ハッシュはアセットの
digest (sha256)。古いアセットには digest が無いものがあり、その場合は取ったものの
sha256 を lock として照合する。
- `compat`: toro-plugin-compat のパッチ済みビルド (CoreProtect、Shopkeepers、EssentialsX、
MyPet、Vehicles)。上流の自動更新で上書きしてはいけないため自動処理から外す。
- `manual`: 検証できる公開ハッシュを持つ配布元が無いもの (スナップショット、閉源、公式
サイト配布) と内製プラグイン。自動処理から外し、理由を note に書く。
- Velocity のプラグインは TORO-Proxy の `ops/both-service/plugins.lock.json` が担うため、
ここには入れない。
- SignedVelocity-Paper は本番からの撤去が決まっているため収載していない
(撤去はゲーム設定 Critical 対応の段階適用で行う)。

## lock の初期値について

初期の版とハッシュは、本番の全 jar の出所を実測した plugin-provenance 監査 (2026-11-06) の
結果を種にし、Modrinth と GitHub の実 API で解決して実ダウンロードと照合して埋めた。
自動対象は Modrinth 17件と GitHub 4件、compat 5件、manual 37件の計63件
(本番の64本から SignedVelocity-Paper を除いた数と一致する)。

## CI

- `ci.yml`: 単体テスト (ネットワークなし) と lock の形の検証。
- `plugin-lock.yml`: lock に触れる PR では `check` を実行。週1回と手動では `update` を
実行し、差分があれば PR を作る。

## 使い方

```
python3 auto_update_plugins.py check
python3 auto_update_plugins.py update
python3 auto_update_plugins.py fetch /path/to/staging
```

GitHub API の回数制限を避ける場合は環境変数 `GH_TOKEN` を設定する。
Loading
Loading