Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions .github/workflows/api-inventory-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# WEKO3 リポジトリ(RCOSDP/weko)の .github/workflows/ に配置する。
#
# 台帳ツールの単体テスト。**Docker も実機も台帳も要らない**ので数秒で終わる。
# api-inventory-drift.yml(実機を起こして突き合わせる。60分枠)とは役割が違う:
#
# このワークフロー … 台帳を作る側(スクリプト・手順書)が壊れていないか
# drift ワークフロー … 台帳の中身が実機とずれていないか
#
# ツールが壊れたまま drift だけ回すと、検知器が黙って死んでいても緑で通る。
# 先にこちらを通すこと。Secret も不要なので fork からの PR でも動く。

name: API Inventory Tests

# 対象は tools/api-inventory/ だけなので、そこを触ったときだけ回す。
# push と pull_request でパスの並びを揃えること(片方だけ古びると、
# 「PR では回るが push では回らない」といった説明のつかない差になる)。
on:
pull_request:
paths: &paths
- 'tools/api-inventory/**'
- '.github/workflows/api-inventory-tests.yml'
push:
branches: ['**']
paths: *paths
Comment on lines +19 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The workflow relies on a YAML anchor defined under pull_request.paths and an alias under push.paths; GitHub Actions rejects YAML anchors/aliases in workflow syntax, so the workflow fails validation before any job starts.

Suggested fix: Use a duplicated paths list, or use a GitHub Actions-supported reusable configuration mechanism instead of YAML anchors.

Suggested change
paths: &paths
- 'tools/api-inventory/**'
- '.github/workflows/api-inventory-tests.yml'
push:
branches: ['**']
paths: *paths
paths:
- 'tools/api-inventory/**'
- '.github/workflows/api-inventory-tests.yml'
push:
branches: ['**']
paths:
- 'tools/api-inventory/**'
- '.github/workflows/api-inventory-tests.yml'

Comment thread
sourcery-ai[bot] marked this conversation as resolved.
workflow_dispatch:

jobs:
unit:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pytest
run: python3 -m pip install --disable-pip-version-check pytest

- name: Run unit tests
working-directory: tools/api-inventory
run: python3 -m pytest -q

# 台帳が無くても、ソースからの経路検知そのものは動く。
# 検知件数が 0 に落ちていれば、検知器が壊れている。
- name: Smoke check the static detector
run: |
set -o pipefail
python3 tools/api-inventory/scripts/detect_routes.py \
--weko-root "$PWD" --summary-only | tee /tmp/detect.md
python3 - <<'PY'
import re, sys
text = open('/tmp/detect.md', encoding='utf-8').read()
total = int(re.search(r'\*\*計\*\* \| \*\*(\d+)\*\*', text).group(1))
print(f'detections={total}')
# 経路が数百ある前提のリポジトリ。2桁に落ちたら検知器の故障を疑う。
sys.exit(0 if total >= 300 else 1)
PY
7 changes: 5 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ユニットテスト。
#
# 【設計】本体イメージは「1回だけ」ビルドして GHCR に置き、45個のマトリクス
# 【設計】本体イメージは「1回だけ」ビルドして GHCR に置き、47個のマトリクス
# ジョブはそれを pull するだけにしている。
#
# - イメージの用意は ci-images.yml (UIテストと共通) に委譲している。
Expand Down Expand Up @@ -95,17 +95,20 @@ jobs:
- weko-items-ui
- weko-itemtypes-ui
- weko-logging
- weko-notifications
- weko-plugins
- weko-records-ui
- weko-records
- weko-redis
- weko-schema-ui
- weko-search-ui
- weko-signposting
- weko-sitemap
- weko-swordserver
- weko-theme
- weko-user-profiles
- weko-workflow
- weko-workspace

steps:
- name: Checkout code
Expand Down Expand Up @@ -199,7 +202,7 @@ jobs:
[ -d .ci-cache ] || exit 0
sudo chown -R "$(id -u):$(id -g)" .ci-cache

# 45ジョブが同じキーで保存を試みるが、先着1つだけが保存され残りは
# 47ジョブが同じキーで保存を試みるが、先着1つだけが保存され残りは
# 予約に失敗してスキップされる(警告のみ)。モジュール間で
# requirements2.txt はほぼ同一なので、1つ保存されれば全体に効く。
- name: Save pip cache
Expand Down
5 changes: 4 additions & 1 deletion tools/api-inventory/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ python3 tools/api-inventory/scripts/reconcile.py --gate
# 測定条件は $WEKO_API_INVENTORY_DIR/measure_profile.json に置く。
tools/api-inventory/scripts/measure.sh --nos 34,925,25

# 5) ワークフローを配置
# 5) ワークフローを配置(2本とも)
# ここに置いただけでは動かない。.github/workflows/ が実体で、ci/ 配下は原本。
# 片方だけ直すとずれるので、変更したら必ず両方に反映する。
cp tools/api-inventory/ci/api-inventory-tests.yml .github/workflows/ # Secret 不要。先に入れる
cp tools/api-inventory/ci/api-inventory-drift.yml .github/workflows/

# 6) GitHub に Secret を登録する
Expand Down
8 changes: 5 additions & 3 deletions tools/api-inventory/ci/api-inventory-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@

name: API Inventory Tests

# 対象は tools/api-inventory/ だけなので、そこを触ったときだけ回す。
# push と pull_request でパスの並びを揃えること(片方だけ古びると、
# 「PR では回るが push では回らない」といった説明のつかない差になる)。
on:
pull_request:
paths:
paths: &paths
- 'tools/api-inventory/**'
- '.github/workflows/api-inventory-tests.yml'
push:
branches: ['**']
paths:
- 'tools/api-inventory/**'
paths: *paths
workflow_dispatch:

jobs:
Expand Down
Loading