From 2480cc09e75d07b36a372f366c3dd61db8f7de28 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 11:04:37 +0000 Subject: [PATCH] Improve code quality and update documentation Code improvements: - Fix ShellCheck warnings: add error handling for cd command - Separate variable declaration from assignment to avoid masking return values - All ShellCheck warnings resolved (SC2164, SC2155) Documentation updates: - Add comprehensive testing section to README (Russian & English) - Document all CI/CD test suites: main tests, multi-platform, alternative OS, code quality - Include local testing commands for contributors - Update CONTRIBUTING.md with testing guidelines - Add automated CI/CD testing information - Provide clear instructions for running ShellCheck and syntax checks Testing improvements: - Verified all existing automated tests are working - Script passes ShellCheck with no warnings - Bash syntax validation passes - Ready for CI/CD pipeline execution --- CONTRIBUTING.md | 56 +++++++++++++++++++++++++ README.md | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ cert_manager.sh | 8 ++-- 3 files changed, 169 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cfb258e..2571f8d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,6 +80,34 @@ install_dependencies() { 3. Проверьте совместимость с разными ОС 4. Проверьте, что не сломались существующие функции +### Локальное тестирование + +Запустите следующие тесты локально перед отправкой PR: + +```bash +# Проверка синтаксиса Bash +bash -n cert_manager.sh + +# ShellCheck анализ (требует установки shellcheck) +sudo apt-get install shellcheck # на Ubuntu/Debian +shellcheck -S warning cert_manager.sh + +# Базовый функциональный тест +echo "0" | sudo ./cert_manager.sh +``` + +### Автоматическое тестирование CI/CD + +При создании Pull Request автоматически запускаются следующие тесты: + +- **ShellCheck** - статический анализ кода Bash +- **Синтаксис** - проверка корректности синтаксиса +- **Безопасность** - сканирование на потенциальные уязвимости +- **Мультиплатформенность** - тесты на Ubuntu, Debian, CentOS, Fedora, Arch, openSUSE +- **Качество кода** - анализ стиля и лучших практик + +Все тесты должны пройти успешно перед слиянием PR. + ## 📝 Документация - Обновляйте README.md при изменении функциональности @@ -181,6 +209,34 @@ Before submitting PR: 3. Check compatibility with different OS 4. Verify existing functions aren't broken +### Local Testing + +Run the following tests locally before submitting PR: + +```bash +# Bash syntax check +bash -n cert_manager.sh + +# ShellCheck analysis (requires shellcheck installation) +sudo apt-get install shellcheck # on Ubuntu/Debian +shellcheck -S warning cert_manager.sh + +# Basic functional test +echo "0" | sudo ./cert_manager.sh +``` + +### Automated CI/CD Testing + +When creating a Pull Request, the following tests run automatically: + +- **ShellCheck** - static analysis of Bash code +- **Syntax** - validation of script syntax +- **Security** - scanning for potential vulnerabilities +- **Multi-platform** - tests on Ubuntu, Debian, CentOS, Fedora, Arch, openSUSE +- **Code Quality** - analysis of style and best practices + +All tests must pass successfully before PR can be merged. + ## 📝 Documentation - Update README.md when changing functionality diff --git a/README.md b/README.md index 0ae752f..9b9cfa2 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,60 @@ Please enter your selection [0-8]: 8 | `check` | Проверить статус автообновления | | `setup-renewal` | Настроить автоматическое продление | +## 🧪 Тестирование + +Проект включает комплексную систему автоматического тестирования через GitHub Actions: + +### Тестовые наборы + +1. **Основные тесты** (`test.yml`) - выполняются при каждом push/PR: + - ✅ ShellCheck анализ кода + - ✅ Проверка синтаксиса Bash + - ✅ Тесты базовой функциональности + - ✅ Проверка установки зависимостей + - ✅ Анализ безопасности + - ✅ Проверка документации + - ✅ Интеграционные тесты + - ✅ Тесты производительности + +2. **Мультиплатформенные тесты** (`multi-os-test.yml`): + - Ubuntu 20.04, 22.04, 24.04 + - Debian 11, 12 + - CentOS Stream 8, 9 + - AlmaLinux 9 + - Rocky Linux 9 + - Fedora 38, 39, 40 + - Arch Linux + - openSUSE Tumbleweed + +3. **Альтернативные тесты** (`alt-os-test.yml`): + - Amazon Linux 2023 + - Oracle Linux 8, 9 + - Red Hat UBI 8, 9 + - Alpine Linux + - BusyBox + +4. **Проверка качества кода** (`code-quality.yml`): + - ShellCheck с разными уровнями строгости + - Сканирование безопасности + - Проверка стиля кода + - Анализ зависимостей + +### Локальное тестирование + +Перед коммитом рекомендуется запустить локальные тесты: + +```bash +# Проверка синтаксиса +bash -n cert_manager.sh + +# ShellCheck анализ (требует установки shellcheck) +shellcheck -S warning cert_manager.sh + +# Базовый функциональный тест +echo "0" | sudo ./cert_manager.sh +``` + ## 🔧 Примеры использования ### Выпуск обычного сертификата @@ -453,6 +507,60 @@ Please enter your selection [0-8]: 8 | `check` | Check auto-renewal status | | `setup-renewal` | Setup automatic renewal | +## 🧪 Testing + +The project includes a comprehensive automated testing system via GitHub Actions: + +### Test Suites + +1. **Main Tests** (`test.yml`) - run on every push/PR: + - ✅ ShellCheck code analysis + - ✅ Bash syntax validation + - ✅ Basic functionality tests + - ✅ Dependency installation tests + - ✅ Security analysis + - ✅ Documentation checks + - ✅ Integration tests + - ✅ Performance tests + +2. **Multi-Platform Tests** (`multi-os-test.yml`): + - Ubuntu 20.04, 22.04, 24.04 + - Debian 11, 12 + - CentOS Stream 8, 9 + - AlmaLinux 9 + - Rocky Linux 9 + - Fedora 38, 39, 40 + - Arch Linux + - openSUSE Tumbleweed + +3. **Alternative OS Tests** (`alt-os-test.yml`): + - Amazon Linux 2023 + - Oracle Linux 8, 9 + - Red Hat UBI 8, 9 + - Alpine Linux + - BusyBox + +4. **Code Quality Checks** (`code-quality.yml`): + - ShellCheck with different severity levels + - Security scanning + - Code style verification + - Dependency analysis + +### Local Testing + +Before committing, it's recommended to run local tests: + +```bash +# Syntax check +bash -n cert_manager.sh + +# ShellCheck analysis (requires shellcheck installation) +shellcheck -S warning cert_manager.sh + +# Basic functional test +echo "0" | sudo ./cert_manager.sh +``` + ## 🔧 Usage Examples ### Issue Regular Certificate diff --git a/cert_manager.sh b/cert_manager.sh index 749d73b..c299a9d 100644 --- a/cert_manager.sh +++ b/cert_manager.sh @@ -153,7 +153,7 @@ install_dependencies() { } install_acme() { - cd ~ + cd ~ || return 1 LOGI "Installing acme.sh..." curl https://get.acme.sh | sh if [ $? -ne 0 ]; then @@ -212,10 +212,12 @@ ssl_cert_issue() { LOGD "Your domain is: ${domain}, checking it..." # here we need to judge whether there exists cert already - local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}') + local currentCert + currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}') if [ "${currentCert}" == "${domain}" ]; then - local certInfo=$(~/.acme.sh/acme.sh --list) + local certInfo + certInfo=$(~/.acme.sh/acme.sh --list) LOGE "System already has certificates for this domain, cannot issue again. Current certificates details:" LOGI "$certInfo" exit 1