LeetDaily は、LeetCode の無料問題を毎日 Discord フォーラムへ投稿する Go サービスです。
このリポジトリは単一の Discord サーバーで運用する前提に寄せており、Discord のチャンネル ID などは手動で設定します。
/setup のような対話的な初期設定は使わず、常駐の Discord interaction endpoint も持ちません。
aqua i
mise trust
mise install
make hooks-install
make verify
make workflow-lint
make terraform-check
make build
go run ./cmd/leetdailymake verify は以下を順に実行します。
gofmt -l .go vet ./...go test ./...
make workflow-lint は actionlint と pinact run --check を使って GitHub Actions workflow を検証します。
make terraform-check は infra/bootstrap と infra/terraform の両方で terraform fmt -check -recursive と terraform validate を実行し、infra/bootstrap では naming 契約の terraform test も実行します。
CI では通常変更に make ci を実行し、Go の検証に加えて workflow lint と Terraform validate も通します。renovate.json / renovate.json5 だけを変更した pull request では、専用 workflow で Renovate 設定の軽量バリデーションだけを実行します。
renovate.json を置いているので、Renovate App をこの repository にインストールすれば GitHub Actions / Go modules / Terraform / aqua.yaml の更新提案を自動化できます。
HTTP mode is optional and mainly useful for local smoke tests.
GET /healthzPOST /run
- Install repo-managed CLIs with
aqua i. - Trust the checked-in
mise.tomlwithmise trust. - Install the Go runtime from
mise.tomlwithmise install. - Install the shared Git hooks with
make hooks-install. - Activate
misein your shell, or prefix commands withmise x --. - Run
go test ./.... - Build with
go build ./cmd/leetdaily. - Prepare
config.jsonfor global settings andguilds.jsonfor the single server's Discord settings. - Start the daily job with the required env vars:
eval "$(mise activate zsh)"If you do not want to activate mise in your shell, you can run commands through mise directly:
mise x -- go test ./...
mise x -- go build ./cmd/leetdaily
mise x -- make hooks-installLefthook manages the repository Git hooks. The checked-in defaults are:
pre-commit: staged Go files rungofmt -w; stagedinfra/bootstrap/**/*.tfandinfra/terraform/**/*.tfchanges runterraform fmt -check -recursive; staged workflow changes runmake workflow-lintpre-push: pushed Go changes runmake fmtcheck,make vet, andmake testin parallel; pushed workflow changes runmake workflow-lint; pushed Terraform changes runmake terraform-checkcommit-msg:commitlint-rsenforces Conventional Commits withfeat,fix,docs,style,refactor,test,chore,ci,build,perf, andrevertpost-checkout/post-merge: whengo.modorgo.sumchanged, rungo mod download; failures warn and keep the hook non-blocking
pre-commit stays focused on staged-file feedback. pre-push runs the heavier validation jobs in parallel and only when the pushed files require them. commit-msg enforces Conventional Commits for local commits. post-checkout and post-merge keep the module cache in sync after dependency changes.
With mise activated, the default one-shot job mode looks like this:
DISCORD_BOT_TOKEN=dummy \
LEETDAILY_RUNTIME=job \
go run ./cmd/leetdailyIf you want the optional HTTP runtime for local smoke tests, use:
DISCORD_BOT_TOKEN=dummy \
LEETDAILY_RUNTIME=http \
PORT=8080 \
go run ./cmd/leetdailyconfig.json keeps global runtime behavior such as timezone, retry policy, and cache threshold. Discord channel settings live in guilds.json and are edited manually.
Example guilds.json for the single-server setup:
{
"guilds": [
{
"guild_id": "123456789012345678",
"enabled": true,
"forum_channel_id": "234567890123456789",
"notification_channel_id": "345678901234567890",
"start_problem_number": 1
}
]
}The manual configuration keeps the runtime simpler and avoids carrying a Discord interaction endpoint just for first-run setup. Production uses a Cloud Run job triggered by Cloud Scheduler, so the bot does not need a continuously running HTTP service.
docker build -t leetdaily .
docker run --rm \
-e DISCORD_BOT_TOKEN=dummy \
-e LEETDAILY_RUNTIME=job \
leetdailySee docs/runbook.md for deploy and operations guidance.
infra/bootstrapは Terraform backend 用 GCS bucket と GitHub OIDC / Workload Identity Federation の初期資材を作成しますinfra/terraformは GCS backend を使ってアプリ本体の infra を管理します- PR では
terraform-planworkflow がinfra/terraformの plan を実行します - apply は
terraform-applyworkflow を手動実行し、productionenvironment の承認で gate する前提です terraform-plan-skippedが pass の場合は、CI 自体は成功でも Terraform plan はまだ実行されていません
必要な GitHub repository variables は以下です。
GCP_PROJECT_IDGCP_TERRAFORM_PLAN_WORKLOAD_IDENTITY_PROVIDERGCP_TERRAFORM_APPLY_WORKLOAD_IDENTITY_PROVIDERLEETDAILY_CONTAINER_IMAGELEETDAILY_DISCORD_TOKEN_SECRET_IDTF_STATE_BUCKET
infra/bootstrap 適用後は、上記 variables を設定して terraform-plan が skip ではなく実行されることを確認してください。