Добавлены скрипты и документация для автоматической синхронизации с GitHub после push в Gitea
This commit is contained in:
@@ -7,8 +7,8 @@ tmp_dir = "tmp"
|
||||
|
||||
[build]
|
||||
args_bin = []
|
||||
bin = "./tmp/main"
|
||||
cmd = "go build -o ./tmp/main cmd/main.go"
|
||||
bin = "./tmp/main.exe"
|
||||
cmd = "go build -o ./tmp/main.exe ./cmd"
|
||||
delay = 1000
|
||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "test_pdfs", "compressed_pdfs", "output", "logs", "bin", "build", "coverage"]
|
||||
exclude_file = []
|
||||
|
||||
14
Makefile
14
Makefile
@@ -123,13 +123,13 @@ clean:
|
||||
## dev: Development mode with auto-reload
|
||||
dev:
|
||||
@echo "$(BLUE)🔥 Development mode (Ctrl+C to exit)$(RESET)"
|
||||
@if command -v air >/dev/null 2>&1; then \
|
||||
air; \
|
||||
else \
|
||||
echo "$(YELLOW)⚠️ air not installed, using regular run$(RESET)"; \
|
||||
echo "Install air: go install github.com/cosmtrek/air@latest"; \
|
||||
make run; \
|
||||
fi
|
||||
@where air >nul 2>&1 && ( \
|
||||
air \
|
||||
) || ( \
|
||||
echo "$(YELLOW)⚠️ air not installed, using regular run$(RESET)" && \
|
||||
echo "Install air: go install github.com/cosmtrek/air@latest" && \
|
||||
$(MAKE) run \
|
||||
)
|
||||
|
||||
## docker: Docker build
|
||||
docker:
|
||||
|
||||
168
gitea-hooks/README.md
Normal file
168
gitea-hooks/README.md
Normal file
@@ -0,0 +1,168 @@
|
||||
# Git Hooks для Gitea
|
||||
|
||||
Автоматическая синхронизация с GitHub после push в Gitea.
|
||||
|
||||
## 📁 Файлы
|
||||
|
||||
- **post-receive** - Hook для автоматического push в GitHub
|
||||
|
||||
## 🚀 Установка
|
||||
|
||||
### 1. Найдите путь к репозиторию на сервере Gitea
|
||||
|
||||
```bash
|
||||
# Обычно это один из путей:
|
||||
/var/lib/gitea/data/gitea-repositories/username/configure_nginx_manager.git
|
||||
# или
|
||||
/home/git/gitea-repositories/username/configure_nginx_manager.git
|
||||
```
|
||||
|
||||
### 2. Скопируйте hook
|
||||
|
||||
```bash
|
||||
# На сервере Gitea
|
||||
cd /path/to/gitea-repositories/username/configure_nginx_manager.git/hooks/
|
||||
|
||||
# Скопируйте файл
|
||||
cp /path/to/this/repo/gitea-hooks/post-receive ./
|
||||
|
||||
# Или загрузите напрямую
|
||||
wget https://raw.githubusercontent.com/username/configure_nginx_manager/main/gitea-hooks/post-receive
|
||||
```
|
||||
|
||||
### 3. Настройте hook
|
||||
|
||||
```bash
|
||||
nano post-receive
|
||||
```
|
||||
|
||||
Измените:
|
||||
```bash
|
||||
GITHUB_REPO="git@github.com:YOUR_USERNAME/configure_nginx_manager.git"
|
||||
```
|
||||
|
||||
### 4. Сделайте исполняемым
|
||||
|
||||
```bash
|
||||
chmod +x post-receive
|
||||
chown git:git post-receive
|
||||
```
|
||||
|
||||
### 5. Создайте директорию для логов
|
||||
|
||||
```bash
|
||||
mkdir -p /var/log/gitea
|
||||
chown git:git /var/log/gitea
|
||||
```
|
||||
|
||||
## 🔑 Настройка аутентификации
|
||||
|
||||
### Вариант A: SSH (Рекомендуется)
|
||||
|
||||
```bash
|
||||
# На сервере Gitea под пользователем git
|
||||
sudo su - git
|
||||
ssh-keygen -t ed25519 -C "gitea-sync"
|
||||
|
||||
# Скопируйте публичный ключ
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
|
||||
# Добавьте на GitHub:
|
||||
# Settings → SSH and GPG keys → New SSH key
|
||||
|
||||
# Проверьте
|
||||
ssh -T git@github.com
|
||||
```
|
||||
|
||||
### Вариант B: HTTPS с токеном
|
||||
|
||||
1. Создайте Personal Access Token на GitHub
|
||||
- Settings → Developer settings → Personal access tokens
|
||||
- Scope: `repo`
|
||||
|
||||
2. Используйте в hook:
|
||||
```bash
|
||||
GITHUB_REPO="https://YOUR_TOKEN@github.com/username/configure_nginx_manager.git"
|
||||
```
|
||||
|
||||
## ✅ Проверка
|
||||
|
||||
```bash
|
||||
# Тестовый push
|
||||
cd /tmp
|
||||
git clone http://gitea.example.com/username/configure_nginx_manager.git
|
||||
cd configure_nginx_manager
|
||||
echo "test" >> README.md
|
||||
git add README.md
|
||||
git commit -m "Test sync"
|
||||
git push
|
||||
|
||||
# Проверьте лог
|
||||
tail -f /var/log/gitea/github-sync.log
|
||||
|
||||
# Проверьте GitHub - изменения должны появиться через 1-2 секунды
|
||||
```
|
||||
|
||||
## 📊 Что делает hook
|
||||
|
||||
1. ✅ Отслеживает push в ветки `main` и `master`
|
||||
2. ✅ Автоматически пушит в GitHub
|
||||
3. ✅ Синхронизирует теги
|
||||
4. ✅ Логирует все операции
|
||||
5. ✅ Показывает красивый вывод с эмодзи
|
||||
|
||||
## 🐛 Устранение проблем
|
||||
|
||||
### Hook не срабатывает
|
||||
|
||||
```bash
|
||||
# Проверьте права
|
||||
ls -la post-receive
|
||||
# Должно быть: -rwxr-xr-x
|
||||
|
||||
# Проверьте владельца
|
||||
chown git:git post-receive
|
||||
|
||||
# Проверьте синтаксис
|
||||
bash -n post-receive
|
||||
```
|
||||
|
||||
### Permission denied
|
||||
|
||||
```bash
|
||||
# Для SSH
|
||||
ssh -T git@github.com
|
||||
|
||||
# Проверьте права на ключ
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
|
||||
# Для HTTPS - проверьте токен
|
||||
```
|
||||
|
||||
### Не находит git
|
||||
|
||||
```bash
|
||||
# Добавьте PATH в начало hook:
|
||||
export PATH=/usr/bin:/usr/local/bin:$PATH
|
||||
```
|
||||
|
||||
## 📝 Логи
|
||||
|
||||
```bash
|
||||
# Просмотр логов синхронизации
|
||||
tail -f /var/log/gitea/github-sync.log
|
||||
|
||||
# Очистка старых логов
|
||||
> /var/log/gitea/github-sync.log
|
||||
```
|
||||
|
||||
## 🔄 Альтернативы
|
||||
|
||||
Если Git Hook не подходит, см. другие методы в [GITEA_SYNC.md](../GITEA_SYNC.md):
|
||||
- GitHub Actions (каждый час)
|
||||
- Gitea Mirror (встроенная функция)
|
||||
- Двойной remote (локально)
|
||||
|
||||
---
|
||||
|
||||
**См. также**: [GITEA_SYNC.md](../GITEA_SYNC.md) для подробной документации
|
||||
168
gitea-hooks/README_EN.md
Normal file
168
gitea-hooks/README_EN.md
Normal file
@@ -0,0 +1,168 @@
|
||||
# Git Hooks for Gitea
|
||||
|
||||
Automatic synchronization with GitHub after push to Gitea.
|
||||
|
||||
## 📁 Files
|
||||
|
||||
- **post-receive** - Hook for automatic push to GitHub
|
||||
|
||||
## 🚀 Installation
|
||||
|
||||
### 1. Find Repository Path on Gitea Server
|
||||
|
||||
```bash
|
||||
# Usually one of these paths:
|
||||
/var/lib/gitea/data/gitea-repositories/username/configure_nginx_manager.git
|
||||
# or
|
||||
/home/git/gitea-repositories/username/configure_nginx_manager.git
|
||||
```
|
||||
|
||||
### 2. Copy Hook
|
||||
|
||||
```bash
|
||||
# On Gitea server
|
||||
cd /path/to/gitea-repositories/username/configure_nginx_manager.git/hooks/
|
||||
|
||||
# Copy file
|
||||
cp /path/to/this/repo/gitea-hooks/post-receive ./
|
||||
|
||||
# Or download directly
|
||||
wget https://raw.githubusercontent.com/username/configure_nginx_manager/main/gitea-hooks/post-receive
|
||||
```
|
||||
|
||||
### 3. Configure Hook
|
||||
|
||||
```bash
|
||||
nano post-receive
|
||||
```
|
||||
|
||||
Change:
|
||||
```bash
|
||||
GITHUB_REPO="git@github.com:YOUR_USERNAME/configure_nginx_manager.git"
|
||||
```
|
||||
|
||||
### 4. Make Executable
|
||||
|
||||
```bash
|
||||
chmod +x post-receive
|
||||
chown git:git post-receive
|
||||
```
|
||||
|
||||
### 5. Create Log Directory
|
||||
|
||||
```bash
|
||||
mkdir -p /var/log/gitea
|
||||
chown git:git /var/log/gitea
|
||||
```
|
||||
|
||||
## 🔑 Authentication Setup
|
||||
|
||||
### Option A: SSH (Recommended)
|
||||
|
||||
```bash
|
||||
# On Gitea server as git user
|
||||
sudo su - git
|
||||
ssh-keygen -t ed25519 -C "gitea-sync"
|
||||
|
||||
# Copy public key
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
|
||||
# Add to GitHub:
|
||||
# Settings → SSH and GPG keys → New SSH key
|
||||
|
||||
# Verify
|
||||
ssh -T git@github.com
|
||||
```
|
||||
|
||||
### Option B: HTTPS with Token
|
||||
|
||||
1. Create Personal Access Token on GitHub
|
||||
- Settings → Developer settings → Personal access tokens
|
||||
- Scope: `repo`
|
||||
|
||||
2. Use in hook:
|
||||
```bash
|
||||
GITHUB_REPO="https://YOUR_TOKEN@github.com/username/configure_nginx_manager.git"
|
||||
```
|
||||
|
||||
## ✅ Verification
|
||||
|
||||
```bash
|
||||
# Test push
|
||||
cd /tmp
|
||||
git clone http://gitea.example.com/username/configure_nginx_manager.git
|
||||
cd configure_nginx_manager
|
||||
echo "test" >> README.md
|
||||
git add README.md
|
||||
git commit -m "Test sync"
|
||||
git push
|
||||
|
||||
# Check log
|
||||
tail -f /var/log/gitea/github-sync.log
|
||||
|
||||
# Check GitHub - changes should appear in 1-2 seconds
|
||||
```
|
||||
|
||||
## 📊 What Hook Does
|
||||
|
||||
1. ✅ Monitors pushes to `main` and `master` branches
|
||||
2. ✅ Automatically pushes to GitHub
|
||||
3. ✅ Synchronizes tags
|
||||
4. ✅ Logs all operations
|
||||
5. ✅ Shows beautiful output with emojis
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Hook Not Firing
|
||||
|
||||
```bash
|
||||
# Check permissions
|
||||
ls -la post-receive
|
||||
# Should be: -rwxr-xr-x
|
||||
|
||||
# Check owner
|
||||
chown git:git post-receive
|
||||
|
||||
# Check syntax
|
||||
bash -n post-receive
|
||||
```
|
||||
|
||||
### Permission Denied
|
||||
|
||||
```bash
|
||||
# For SSH
|
||||
ssh -T git@github.com
|
||||
|
||||
# Check key permissions
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
|
||||
# For HTTPS - check token
|
||||
```
|
||||
|
||||
### Can't Find Git
|
||||
|
||||
```bash
|
||||
# Add PATH to beginning of hook:
|
||||
export PATH=/usr/bin:/usr/local/bin:$PATH
|
||||
```
|
||||
|
||||
## 📝 Logs
|
||||
|
||||
```bash
|
||||
# View sync logs
|
||||
tail -f /var/log/gitea/github-sync.log
|
||||
|
||||
# Clear old logs
|
||||
> /var/log/gitea/github-sync.log
|
||||
```
|
||||
|
||||
## 🔄 Alternatives
|
||||
|
||||
If Git Hook doesn't work, see other methods in [GITEA_SYNC_EN.md](../GITEA_SYNC_EN.md):
|
||||
- GitHub Actions (every hour)
|
||||
- Gitea Mirror (built-in feature)
|
||||
- Double remote (locally)
|
||||
|
||||
---
|
||||
|
||||
**See also**: [GITEA_SYNC_EN.md](../GITEA_SYNC_EN.md) for detailed documentation
|
||||
83
gitea-hooks/post-receive
Normal file
83
gitea-hooks/post-receive
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==============================================================================
|
||||
# Post-receive hook для Gitea
|
||||
# Автоматически синхронизирует изменения с GitHub после push
|
||||
#
|
||||
# Установка:
|
||||
# 1. Разместить в: /path/to/gitea/data/gitea-repositories/username/repo.git/hooks/
|
||||
# 2. Переименовать в: post-receive
|
||||
# 3. chmod +x post-receive
|
||||
# 4. Настроить переменные ниже
|
||||
# ==============================================================================
|
||||
|
||||
# Конфигурация
|
||||
GITHUB_REPO="git@github.com:username/compressor.git"
|
||||
# Или с HTTPS и токеном:
|
||||
# GITHUB_REPO="https://YOUR_GITHUB_TOKEN@github.com/username/compressor.git"
|
||||
|
||||
LOG_FILE="/var/log/gitea/github-sync.log"
|
||||
|
||||
# Цвета для логов
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# ==============================================================================
|
||||
# Функция логирования
|
||||
# ==============================================================================
|
||||
log() {
|
||||
echo -e "${2:-$NC}[$(date +'%d.%m.%Y %H:%M:%S')] $1${NC}" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# ==============================================================================
|
||||
# Основная логика
|
||||
# ==============================================================================
|
||||
|
||||
log "═══════════════════════════════════════════════════════════════" "$GREEN"
|
||||
log "🔄 Начало синхронизации с GitHub" "$GREEN"
|
||||
log "═══════════════════════════════════════════════════════════════" "$GREEN"
|
||||
|
||||
# Читаем информацию о push
|
||||
while read oldrev newrev refname; do
|
||||
log "📝 Изменения обнаружены:" "$YELLOW"
|
||||
log " Branch: ${refname#refs/heads/}"
|
||||
log " Old commit: ${oldrev:0:8}"
|
||||
log " New commit: ${newrev:0:8}"
|
||||
|
||||
# Проверяем наличие GitHub remote
|
||||
if ! git remote | grep -q github; then
|
||||
log "➕ Добавление GitHub remote..." "$YELLOW"
|
||||
git remote add github "$GITHUB_REPO" 2>&1 | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Пушим в GitHub
|
||||
log "⬆️ Отправка изменений в GitHub..." "$YELLOW"
|
||||
|
||||
# Только для main/master веток
|
||||
if [[ "$refname" == "refs/heads/main" ]] || [[ "$refname" == "refs/heads/master" ]]; then
|
||||
if git push github "$refname" --force 2>&1 | tee -a "$LOG_FILE"; then
|
||||
log "✅ Успешно синхронизировано с GitHub" "$GREEN"
|
||||
else
|
||||
log "❌ Ошибка при синхронизации с GitHub" "$RED"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Пушим теги
|
||||
log "🏷️ Отправка тегов..." "$YELLOW"
|
||||
if git push github --tags 2>&1 | tee -a "$LOG_FILE"; then
|
||||
log "✅ Теги синхронизированы" "$GREEN"
|
||||
else
|
||||
log "⚠️ Не удалось синхронизировать теги" "$YELLOW"
|
||||
fi
|
||||
else
|
||||
log "ℹ️ Ветка ${refname#refs/heads/} игнорируется (не main/master)" "$YELLOW"
|
||||
fi
|
||||
done
|
||||
|
||||
log "═══════════════════════════════════════════════════════════════" "$GREEN"
|
||||
log "✅ Синхронизация завершена" "$GREEN"
|
||||
log "═══════════════════════════════════════════════════════════════" "$GREEN"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user