このガイドでは、GitHub Actions を使って独自スクリプトをスケジュール実行し、タスクを自動化する方法を示します。

SakeSaySo は 2023 年以降の LLM によるコンテンツ生成の流れを取り入れ、ニュース集約プロセスで Anthropic AI を活用しています。私たちは Python より Go ベースのツールやスクリプトを好むため、GitHub Actions と組み合わせてこの種の処理を自動化しています。以下の設定は、cron スケジュールを含む構成例であり、同様の仕組みを自分用に再現する際の参考になります。

name: Go Scheduled Newswriter

on:
  push:
    branches: [ master ]
  schedule:
    - cron: '0 21 * * *'  # Runs at 21:00 UTC (6 AM JST)

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Current Repository
      uses: actions/checkout@v2

    - name: Checkout sakesayso/news Repository
      uses: actions/checkout@v2
      with:
        repository: 'sakesayso/news'
        token: ${{ secrets.SAKESAYSO_WRITER_PAT }}
        path: 'news'

    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: '1.21'

    - name: Run Newswriter A
      env:
        ANTHROPIC_TOKEN: ${{ secrets.ANTHROPIC_TOKEN }}
      run: go run cmd/newswriter/main.go

    - name: Commit and Push Changes
      run: |
        cd news
        git config --global user.name 'sakebot'
        git config --global user.email '[email protected]'
        git add .
        git commit -m "Update from newswriter" || true
        git push

この設定例では、リポジトリのチェックアウトから Go スクリプトの実行、更新の push までの流れを示しています。