Skip to content

Commit 9ac914a

Browse files
getjumpclaude
andcommitted
Update CI/CD, Docker, Makefile, README for Go
- Add ci.yml: lint, test, build + publish to ghcr.io + deploy - Rewrite Dockerfile for Go multi-stage build - Update docker-compose files for Go - Rewrite Makefile with Go targets - Rewrite README.md for Go project - Update example.env with Go-relevant variables Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e5da6ac commit 9ac914a

File tree

7 files changed

+209
-139
lines changed

7 files changed

+209
-139
lines changed

.github/workflows/ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main, "feat/**"]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.23"
18+
- uses: golangci/golangci-lint-action@v6
19+
with:
20+
version: latest
21+
22+
test:
23+
name: Test
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-go@v5
28+
with:
29+
go-version: "1.23"
30+
- name: Run tests
31+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
32+
- name: Upload coverage
33+
uses: codecov/codecov-action@v4
34+
with:
35+
file: coverage.out
36+
continue-on-error: true
37+
38+
build:
39+
name: Build
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version: "1.23"
46+
- name: Build
47+
run: go build -o vldc-bot ./cmd/bot
48+
49+
publish:
50+
name: Publish & Deploy
51+
runs-on: ubuntu-latest
52+
needs: [lint, test, build]
53+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Publish to Registry
57+
uses: elgohr/Publish-Docker-Github-Action@v5
58+
with:
59+
name: vldc-hq/vldc-bot/bot
60+
username: ${{ secrets.DOCKER_USERNAME }}
61+
password: ${{ secrets.DOCKER_PASSWORD }}
62+
registry: ghcr.io
63+
- name: Trigger deploy
64+
env:
65+
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
66+
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY_PROD }}
67+
run: |
68+
curl --fail --insecure --max-time 300 "https://$DEPLOY_HOST/deploy/bot-prod?secret=$DEPLOY_KEY"'&sync=true'

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.23-alpine AS builder
2+
3+
WORKDIR /app
4+
COPY go.mod go.sum ./
5+
RUN go mod download
6+
COPY . .
7+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /vldc-bot ./cmd/bot
8+
9+
FROM alpine:3.20
10+
RUN apk add --no-cache ca-certificates tzdata
11+
COPY --from=builder /vldc-bot /vldc-bot
12+
13+
ENTRYPOINT ["/vldc-bot"]

Makefile

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
SHELL = /bin/bash
22

33
.DEFAULT_GOAL := help
4-
.PHONY: dev test lint start dev_build dev_start dev_test venv
4+
.PHONY: build test lint format run docker-build docker-up docker-down help
55

6+
## Go targets
67

7-
build: ## Build all
8-
docker-compose -f docker-compose-dev.yml build
8+
build: ## Build the bot binary
9+
go build -o bin/vldc-bot ./cmd/bot
910

10-
up: ## Up All and show logs
11-
docker-compose -f docker-compose-dev.yml up -d && docker-compose -f docker-compose-dev.yml logs -f --tail=10
11+
run: ## Run the bot locally
12+
go run ./cmd/bot
1213

13-
update: ## Restart bot after files changing
14-
docker-compose -f docker-compose-dev.yml restart bot && make up
14+
test: ## Run all tests
15+
go test -race -count=1 ./...
1516

16-
stop: ## Stop all
17-
docker-compose -f docker-compose-dev.yml stop
17+
test-cover: ## Run tests with coverage report
18+
go test -race -coverprofile=coverage.out -covermode=atomic ./...
19+
go tool cover -html=coverage.out -o coverage.html
1820

19-
down: ## Down all
20-
docker-compose -f docker-compose-dev.yml down
21+
lint: ## Run golangci-lint
22+
golangci-lint run ./...
2123

22-
test: ## Run tests locally
23-
export PYTHONPATH=./bot && pytest bot/tests
24+
format: ## Format code with goimports
25+
goimports -w .
2426

25-
test_docker: ## Run tests in docker
26-
docker-compose -f docker-compose-dev.yml run --rm bot pytest bot/tests
27+
tidy: ## Run go mod tidy
28+
go mod tidy
2729

28-
lint: ## Run linters (black, flake8, mypy, pylint)
29-
black ./bot --check --diff
30-
pylint ./bot --rcfile .pylintrc
31-
flake8 ./bot --config .flake8 --count --show-source --statistics
32-
mypy --config-file mypy.ini ./bot
33-
pyright ./bot
30+
## Docker targets
3431

35-
format: ## Format code (black)
36-
black ./bot
32+
docker-build: ## Build Docker image
33+
docker build -t vldc-bot .
3734

38-
venv: ## Create local .venv and install deps (uv)
39-
python3 -m venv .venv
40-
. .venv/bin/activate && python -m pip install -U pip
41-
. .venv/bin/activate && python -m pip install -U uv
42-
. .venv/bin/activate && uv sync --active --dev --no-install-project
35+
docker-up: ## Run with docker-compose
36+
docker-compose up -d && docker-compose logs -f --tail=10
37+
38+
docker-down: ## Stop docker-compose
39+
docker-compose down
4340

4441
## Help
4542

README.md

Lines changed: 76 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,113 @@
11
# VLDC nyan bot ^_^
22

3-
The official [VLDC](https://vldc.org) telegram group bot.
3+
The official [VLDC](https://vldc.org) telegram group bot. Written in Go.
44

55
![nyan](img/VLDC_nyan-tiger-in-anaglyph-glasses.png)
66

7-
[![Build Status](https://github.com/vldc-hq/vldc-bot/workflows/Nyan%20Bot/badge.svg)](https://github.com/vldc-hq/vldc-bot/actions?query=workflow%3A%22Nyan+Bot%22)
8-
[![Maintainability](https://api.codeclimate.com/v1/badges/5941349dbc55ce7096fb/maintainability)](https://codeclimate.com/github/vldc-hq/vldc-bot/maintainability)
9-
7+
[![CI](https://github.com/vldc-hq/vldc-bot/actions/workflows/ci.yml/badge.svg)](https://github.com/vldc-hq/vldc-bot/actions/workflows/ci.yml)
108

119
### Skills
12-
* 😼 core – core
13-
* 😼 version – show this message
14-
* 😻 still – do u remember it?
15-
* 😾 uwu – don't uwu!
16-
* 🤭 mute – mute user for N minutes
17-
* 🔫 roll – life is so cruel... isn't it?
18-
* ⚔️ banme – commit sudoku
19-
* 🔪 ban – ban! ban! ban!
20-
* 🎄 tree – advent of code time!
21-
* ⛔🤬 coc – VLDC/GDG VL Code of Conduct
22-
* 🛠 more than 70k? – try to hire!
23-
* 💻 got sk1lzz? – put them to use!
24-
* 👁 smell like PRISM? nononono!
25-
* 💰 kozula Don't argue with kozula rate!
26-
* 🤫 buktopuha Let's play a game 🤡
10+
* core - core bot functionality
11+
* version - show bot version
12+
* still - do u remember it?
13+
* uwu - don't uwu!
14+
* mute - mute user for N minutes
15+
* roll - life is so cruel... isn't it?
16+
* banme - commit sudoku
17+
* ban - ban! ban! ban!
18+
* tree - Advent of Code time!
19+
* coc - VLDC/GDG VL Code of Conduct
20+
* 70k - try to hire!
21+
* pr - got sk1lzz? put them to use!
22+
* prism - smell like PRISM? nononono!
23+
* kozula - Don't argue with kozula rate!
24+
* buktopuha - Let's play a game
25+
* length - measure your instrument
26+
* nya - Simon says wat?
27+
* trusted - in god we trust
28+
* aoc - Advent of Code tracker
2729

2830
### Modes
29-
* 😼 smile mode – allow only stickers in the chat
30-
* 🛠 since mode – under construction
31-
* 🧼 towel mode – anti bot
32-
* 🙃 fools mode – what? not again!
33-
* 🤫 nastya mode – stop. just stop
34-
* 🙃 chat mode - chatty Nyan
35-
36-
## Usage via VS Code (Easy Way)
37-
Clone repository locally and open it up via VS Code and click Open in Container. Create `.env` file as described below.
38-
Mongo will be available at `MONGO_HOST=localhost`. And you're done, you can run bot by clicking `F5` or `Run -> Launch Bot`.
31+
* smile mode - allow only stickers in the chat
32+
* since mode - under construction
33+
* towel mode - anti bot
34+
* fools mode - what? not again!
35+
* nastya mode - stop. just stop
36+
* chat mode - chatty Nyan
3937

40-
Other option is to use [Codespaces](https://github.com/vldc-hq/vldc-bot/codespaces) from GitHub itself.
41-
42-
## Usage
43-
Setup your env vars in `example.env` and rename it to `.env`. Don't push `.env` to public repos!
38+
## Quick Start
4439

40+
1. Copy `example.env` to `.env` and fill in your bot token and chat ID:
4541
```
46-
make up
42+
cp example.env .env
4743
```
4844

49-
## Local venv (no Docker)
50-
Create a virtual environment and install dependencies locally:
51-
45+
2. Run with Docker:
5246
```
53-
make venv
54-
source .venv/bin/activate
47+
docker-compose -f docker-compose-dev.yml up
5548
```
5649

57-
Run the bot locally:
50+
Or run locally:
5851
```
59-
PYTHONPATH=./bot python bot/main.py
52+
make run
6053
```
6154

62-
Then run linters/tests with:
63-
```
64-
make lint
65-
make test
66-
```
55+
## Usage
6756

68-
## Build local image
57+
### Environment Variables
58+
59+
| Variable | Required | Description |
60+
|---|---|---|
61+
| `TOKEN` | Yes | Telegram bot token |
62+
| `CHAT_ID` | Yes | Telegram group chat ID |
63+
| `SQLITE_DB_PATH` | No | Path to SQLite database (default: `bot.db`) |
64+
| `SENTRY_DSN` | No | Sentry DSN for error tracking |
65+
| `AOC_SESSION` | No | Advent of Code session cookie |
66+
| `GOOGLE_PROJECT_ID` | No | Google Cloud project ID (for translation) |
67+
| `GOOGLE_APPLICATION_CREDENTIALS` | No | Path to Google service account JSON |
68+
| `GEMINI_API_KEY` | No | Gemini API key (translation fallback) |
69+
| `OPENAI_API_KEY` | No | OpenAI API key |
70+
| `DEBUG` | No | Enable debug logging |
71+
72+
### Make targets
6973

7074
```
71-
make build
75+
make build Build the bot binary
76+
make run Run the bot locally
77+
make test Run all tests
78+
make test-cover Run tests with coverage report
79+
make lint Run golangci-lint
80+
make format Format code with goimports
81+
make tidy Run go mod tidy
82+
make docker-build Build Docker image
83+
make docker-up Run with docker-compose
84+
make docker-down Stop docker-compose
7285
```
7386

7487
## Developing
75-
Create test Telegram bot, and store TOKEN and chat id, you will need it for developing.
76-
77-
User `make` to up dev services:
7888

79-
```shell script
80-
Usage: make [task]
89+
Create a test Telegram bot via [@BotFather](https://t.me/BotFather), store the token and your chat ID in `.env`.
8190

82-
task help
83-
------ ----
84-
build Build all
85-
up Up All and show logs
86-
update Restart bot after files changing
87-
stop Stop all
88-
down Down all
89-
test Run tests
90-
lint Run linters (black, flake8, mypy, pylint)
91-
format Format code (black)
92-
93-
help Show help message
91+
Run linters and tests before committing:
92+
```
93+
make lint
94+
make test
9495
```
9596

96-
Don't forget run `make lint` and `make test` before commit! For code formatting we are use [black](https://github.com/psf/black), so, just run `make format` to fire it :3
97-
98-
### Setting Up Debugger in VS Code
97+
## Project Structure
9998

100-
Create `launch.json` under your `.vscode` directory in project, add the following content onto it:
10199
```
102-
{
103-
"version": "0.2.0",
104-
"configurations": [
105-
{
106-
"name": "Docker Python",
107-
"type": "python",
108-
"request": "attach",
109-
"port": 5678,
110-
"host": "localhost",
111-
"pathMappings": [
112-
{
113-
"localRoot": "${workspaceFolder}",
114-
"remoteRoot": "/app"
115-
}
116-
],
117-
}
118-
]
119-
}
100+
cmd/bot/ - entry point
101+
internal/
102+
bot/ - bot core, skill registration, middleware
103+
config/ - configuration loading
104+
db/ - SQLite database layer
105+
mode/ - mode state management
106+
skill/ - all bot skills (one file per skill)
107+
util/ - shared utilities (cleanup, etc.)
108+
ai/ - AI client helpers
120109
```
121110

122-
Also, put `DEBUGGER=True` into your `.env` file. After that you can do debugging with VS Code, by running containerized application and hitting `Run -> Start Debugging` or `F5` button.
123-
124111
# Contributing
125112
Bug reports, bug fixes and new features are always welcome.
126113
Please open issues and submit pull requests for any new code.

docker-compose-dev.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
services:
22
bot:
3-
build:
4-
context: .
5-
dockerfile: ./compose/dev/Dockerfile
6-
ports:
7-
- "5678:5678"
8-
volumes:
9-
- .:/app
10-
- .:/opt/gcloud
3+
build: .
4+
restart: unless-stopped
115
env_file:
126
- ./.env
7+
volumes:
8+
- bot-data:/data
139
environment:
14-
- PYTHONPATH=./bot
15-
- PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
16-
- PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
10+
- SQLITE_DB_PATH=/data/bot.db
11+
- DEBUG=true
1712
logging:
1813
options:
1914
max-size: "1M"
2015
max-file: "10"
16+
17+
volumes:
18+
bot-data:

0 commit comments

Comments
 (0)