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
44 changes: 6 additions & 38 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
version: 2 # circle ci のversion
# CircleCI is deprecated for this repository.
# CI runs on GitHub Actions: .github/workflows/ci.yml
version: 2.1

jobs:
build:
docker:
- image: circleci/python:3.8
environment:
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=hometask
- DB_USERNAME=root
- DB_PASSWORD=root

working_directory: ~/hometamon

steps:
- checkout # code to docker image

- run:
name: install dependencies
command: |
pip install tweepy==3.8.0
pip install pytest==5.4.1
pip install pytest-mock==3.1.0
pip install python-dotenv==0.10.5
pip install mysqlclient==2.0.1

- run:
name: Test
# cd でテストの領域を指定
command: |
mkdir test-reports
cd main
pytest

# --junitxml=test-reports/junit.xml

- store_test_results:
path: test-reports
workflows:
disabled:
jobs: []
48 changes: 19 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
name: GitHub CI
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
name: CI

on:
push:
pull_request:

jobs:
Explore-GitHub-Actions:
test:
runs-on: ubuntu-latest

steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
uses: actions/checkout@v4

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker Layers
id: cache
uses: actions/cache@v3
with:
path: /tmp/.build-cache
key: ${{ github.ref }}-${{ github.sha }}
restore-keys:
${{ runner.os }}-buildx-
uses: docker/setup-buildx-action@v3

- name: Docker Build
run:
docker-compose build
- name: Build containers
run: docker compose build

- name: Run Test
- name: Run tests in container
run: |
docker-compose up -d
docker exec hometamon pytest tests
docker compose up -d
docker exec hometamon pytest tests

- name: Tear down
if: always()
run: docker compose down
1 change: 0 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ jobs:
# Change reporter level if you need.
# GitHub Status Check won't become failure with a warning.
level: warning

1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# AGETNT.md
50 changes: 50 additions & 0 deletions CURRENT_STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 褒めたもん(metamon_code)現状整理メモ

最終更新: 2026-02-15(Codex調査)

## 1. 目的と実行の流れ
- `main/src/hometamon.py` の `main()` がエントリポイント。
- Home Timeline を取得し、条件に応じて以下を実行する構成。
- 挨拶リプ(おはよう / おやすみ)
- 褒めリプ(キーワードベース)
- 15時のおやつツイート
- フォローバック管理
- 実行件数のDMレポート送信
- Docker運用時は `main/crontab` で **6分ごと** に `python3 /src/hometamon.py` を叩く設計。

## 2. 現在のランタイム/依存の特徴
- READMEの依存記載が古め(Django など現状未使用の記載が残る)。
- 実際のコンテナ依存は `main/Dockerfile` 側がソースオブトゥルースに近い。
- `python-dotenv==1.0.0`
- `tweepy==3.8.0`(v1.1 API時代)
- `pytest==5.4.1`, `pytest-mock==3.1.0`
- ローカル直実行では `dotenv` など未導入環境だとテスト収集時に失敗する。

## 3. CI/CD の状態
- GitHub Actions が2本。
- `ci.yml`: push時に docker-compose build → コンテナ内pytest
- `linter.yml`: PR時に black + reviewdog
- 直近履歴でも CI / linter の調整コミットが入っており、保守は継続されていた形跡あり。

## 4. いま見えている技術的リスク
- `main/src/hometamon.py` の `main()` 内で `hometamon.tweet_linestamp()` を呼んでいるが、定義されているのは `test_tweet_linestamp()`。
- 指定日時に到達すると `AttributeError` になる可能性が高い。
- Twitter APIが古い実装(`tweepy==3.8.0` + v1.1想定)で、現行運用時は権限・API仕様差分を要確認。
- 除外ワードや分類はハードコード中心で、運用ルール変更時にコード修正が必要。
- READMEの手順・依存情報と実態の乖離あり(再起動時のオンボーディング負荷が高い)。

## 5. テスト現状(この調査での実行)
- `pytest -q` は、環境に `python-dotenv` が無いため import error で停止。
- Docker経由テストは、この実行環境に Docker コマンドが無く未実施。

## 6. リリース再開に向けた優先TODO(提案)
1. **クリティカルバグ修正**: `tweet_linestamp` 呼び出し不整合を解消。
2. **Secrets/Env棚卸し**: `.env` 必須値(APIキー、管理者ID等)を再確認。
3. **実行確認**: `--test` 相当の安全モード(投稿しないdry-run)を用意して疎通確認。
4. **README更新**: 実行手順を Docker中心に一本化、依存記載を最新化。
5. **段階リリース**: まず cron 無効 + 手動単発、次に cron 有効化。

## 7. 現状理解サマリ(短く)
- Botの基本機能は保たれているが、**そのまま本番再開はやや危険**。
- 特に `tweet_linestamp` 名称不整合は先に潰すべき。
- 依存と運用手順の再整備をした上で、段階的に復帰するのが安全。
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# 開発環境起動
dev:
docker compose build --no-cache
docker compose up -d

# 本番用
compose/build:
docker-compose build --no-cache
docker compose build --no-cache

compose/up:
docker-compose up
docker compose up

re-run:
docker-compose down
docker-compose build --no-cache
docker-compose up -d
docker compose down
docker compose build --no-cache
docker compose up -d

exec:
docker exec -it hometamon /bin/sh

test:
docker-compose down
docker-compose build
docker-compose up -d
docker compose down
docker compose build
docker compose up -d
docker exec hometamon pytest tests
docker-compose down

# run:
# python3 main/src/hometamon.py --test 1
docker compose down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ src = "main/images/icon.jpg"
width = "150"
align = "middle">

[![CircleCI](https://circleci.com/gh/seven320/metamon_code.svg?style=svg)](https://circleci.com/gh/seven320/metamon_code)
[![GitHub Actions CI](https://github.com/seven320/metamon_code/actions/workflows/ci.yml/badge.svg)](https://github.com/seven320/metamon_code/actions/workflows/ci.yml)
[![License](https://img.shields.io/github/license/seven320/metamon_code)](https://github.com/seven320/metamon_code/stargazers)

Expand All @@ -15,13 +14,7 @@ align = "middle">

## Requirement
~~~
tweepy == 3.8.0
python-dotenv == 0.10.5
pytest == 5.4.1
pytest-mock == 3.1.0
Django == 3.1
django-filter == 2.3.0
djangorestframework == 3.11.2
see `main/requirements.txt` (installed by uv in Docker)
~~~

## How to USE(使い方)
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'

services:
metamon:
build:
context: ./main
target: dev
volumes:
- ./main/src:/app/src
- ./main/tests:/app/tests
- ./main/images:/app/images
- ./main/env:/app/env
command: sh
30 changes: 0 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,3 @@ services:
tty: true
environment:
TZ: Asia/Tokyo

# web:
# build: ./Django/main
# container_name: hometask
# command: python3 manage.py runserver 0.0.0.0:8001
# volumes:
# - ./Django/main:/code
# ports:
# - "8001:8001"
# environment:
# TZ: Asia/Tokyo

# database:
# image: mysql:5.7
# container_name: mysql_host
# environment:
# MYSQL_ROOT_PASSWORD: root
# MYSQL_PASSWORD: docker
# TZ: 'Asia/Tokyo'
# command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
# # restart: always
# # 永続化
# volumes:
# # - ./database/mysql_data:/var/lib/mysql
# - ./database/my.cnf:/etc/mysql/conf.d/my.cnf
# tty: true

# ports:
# - 3307:3307

39 changes: 21 additions & 18 deletions main/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-alpine
FROM python:3.13-alpine AS base

RUN apk update && \
apk --no-cache add \
Expand All @@ -10,25 +10,28 @@ RUN apk update && \
tree \
busybox-static

WORKDIR /app

# library
RUN pip install --upgrade pip
RUN pip install \
tweepy==3.8.0 \
tqdm==4.36.1\
pykakasi==1.2\
python-dotenv==1.0.0\
pytest==5.4.1\
pytest-mock==3.1.0

# RUN service cron start
# RUN git clone https://github.com/seven320/metamon_code.git
COPY ./src src
COPY ./tests tests
COPY ./images images
COPY ./env env
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"
ENV UV_SYSTEM_PYTHON=1

COPY ./requirements.txt /tmp/requirements.txt
RUN uv pip install --no-cache -r /tmp/requirements.txt

COPY ./src ./src
COPY ./tests ./tests
COPY ./images ./images
COPY ./env ./env
COPY ./crontab /var/spool/cron/crontabs/root
CMD ["busybox", "crond", "-l", "2", "-L", "/dev/stderr", "-f"]

ENV USER mother
ENV HOME /home/${USER}
ENV SHELL /bin/sh
ENV SHELL /bin/sh

FROM base AS dev
CMD ["sh"]

FROM base AS prd
CMD ["busybox", "crond", "-l", "2", "-L", "/dev/stderr", "-f"]
Binary file modified main/images/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions main/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tweepy==3.8.0
tqdm==4.36.1
pykakasi==1.2
python-dotenv==1.0.0
pytest==8.3.4
pytest-mock==3.14.0