Skip to content

Commit 2480cc0

Browse files
committed
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
1 parent 32bb2ed commit 2480cc0

File tree

3 files changed

+169
-3
lines changed

3 files changed

+169
-3
lines changed

CONTRIBUTING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ install_dependencies() {
8080
3. Проверьте совместимость с разными ОС
8181
4. Проверьте, что не сломались существующие функции
8282

83+
### Локальное тестирование
84+
85+
Запустите следующие тесты локально перед отправкой PR:
86+
87+
```bash
88+
# Проверка синтаксиса Bash
89+
bash -n cert_manager.sh
90+
91+
# ShellCheck анализ (требует установки shellcheck)
92+
sudo apt-get install shellcheck # на Ubuntu/Debian
93+
shellcheck -S warning cert_manager.sh
94+
95+
# Базовый функциональный тест
96+
echo "0" | sudo ./cert_manager.sh
97+
```
98+
99+
### Автоматическое тестирование CI/CD
100+
101+
При создании Pull Request автоматически запускаются следующие тесты:
102+
103+
- **ShellCheck** - статический анализ кода Bash
104+
- **Синтаксис** - проверка корректности синтаксиса
105+
- **Безопасность** - сканирование на потенциальные уязвимости
106+
- **Мультиплатформенность** - тесты на Ubuntu, Debian, CentOS, Fedora, Arch, openSUSE
107+
- **Качество кода** - анализ стиля и лучших практик
108+
109+
Все тесты должны пройти успешно перед слиянием PR.
110+
83111
## 📝 Документация
84112

85113
- Обновляйте README.md при изменении функциональности
@@ -181,6 +209,34 @@ Before submitting PR:
181209
3. Check compatibility with different OS
182210
4. Verify existing functions aren't broken
183211

212+
### Local Testing
213+
214+
Run the following tests locally before submitting PR:
215+
216+
```bash
217+
# Bash syntax check
218+
bash -n cert_manager.sh
219+
220+
# ShellCheck analysis (requires shellcheck installation)
221+
sudo apt-get install shellcheck # on Ubuntu/Debian
222+
shellcheck -S warning cert_manager.sh
223+
224+
# Basic functional test
225+
echo "0" | sudo ./cert_manager.sh
226+
```
227+
228+
### Automated CI/CD Testing
229+
230+
When creating a Pull Request, the following tests run automatically:
231+
232+
- **ShellCheck** - static analysis of Bash code
233+
- **Syntax** - validation of script syntax
234+
- **Security** - scanning for potential vulnerabilities
235+
- **Multi-platform** - tests on Ubuntu, Debian, CentOS, Fedora, Arch, openSUSE
236+
- **Code Quality** - analysis of style and best practices
237+
238+
All tests must pass successfully before PR can be merged.
239+
184240
## 📝 Documentation
185241

186242
- Update README.md when changing functionality

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,60 @@ Please enter your selection [0-8]: 8
168168
| `check` | Проверить статус автообновления |
169169
| `setup-renewal` | Настроить автоматическое продление |
170170

171+
## 🧪 Тестирование
172+
173+
Проект включает комплексную систему автоматического тестирования через GitHub Actions:
174+
175+
### Тестовые наборы
176+
177+
1. **Основные тесты** (`test.yml`) - выполняются при каждом push/PR:
178+
- ✅ ShellCheck анализ кода
179+
- ✅ Проверка синтаксиса Bash
180+
- ✅ Тесты базовой функциональности
181+
- ✅ Проверка установки зависимостей
182+
- ✅ Анализ безопасности
183+
- ✅ Проверка документации
184+
- ✅ Интеграционные тесты
185+
- ✅ Тесты производительности
186+
187+
2. **Мультиплатформенные тесты** (`multi-os-test.yml`):
188+
- Ubuntu 20.04, 22.04, 24.04
189+
- Debian 11, 12
190+
- CentOS Stream 8, 9
191+
- AlmaLinux 9
192+
- Rocky Linux 9
193+
- Fedora 38, 39, 40
194+
- Arch Linux
195+
- openSUSE Tumbleweed
196+
197+
3. **Альтернативные тесты** (`alt-os-test.yml`):
198+
- Amazon Linux 2023
199+
- Oracle Linux 8, 9
200+
- Red Hat UBI 8, 9
201+
- Alpine Linux
202+
- BusyBox
203+
204+
4. **Проверка качества кода** (`code-quality.yml`):
205+
- ShellCheck с разными уровнями строгости
206+
- Сканирование безопасности
207+
- Проверка стиля кода
208+
- Анализ зависимостей
209+
210+
### Локальное тестирование
211+
212+
Перед коммитом рекомендуется запустить локальные тесты:
213+
214+
```bash
215+
# Проверка синтаксиса
216+
bash -n cert_manager.sh
217+
218+
# ShellCheck анализ (требует установки shellcheck)
219+
shellcheck -S warning cert_manager.sh
220+
221+
# Базовый функциональный тест
222+
echo "0" | sudo ./cert_manager.sh
223+
```
224+
171225
## 🔧 Примеры использования
172226

173227
### Выпуск обычного сертификата
@@ -453,6 +507,60 @@ Please enter your selection [0-8]: 8
453507
| `check` | Check auto-renewal status |
454508
| `setup-renewal` | Setup automatic renewal |
455509

510+
## 🧪 Testing
511+
512+
The project includes a comprehensive automated testing system via GitHub Actions:
513+
514+
### Test Suites
515+
516+
1. **Main Tests** (`test.yml`) - run on every push/PR:
517+
- ✅ ShellCheck code analysis
518+
- ✅ Bash syntax validation
519+
- ✅ Basic functionality tests
520+
- ✅ Dependency installation tests
521+
- ✅ Security analysis
522+
- ✅ Documentation checks
523+
- ✅ Integration tests
524+
- ✅ Performance tests
525+
526+
2. **Multi-Platform Tests** (`multi-os-test.yml`):
527+
- Ubuntu 20.04, 22.04, 24.04
528+
- Debian 11, 12
529+
- CentOS Stream 8, 9
530+
- AlmaLinux 9
531+
- Rocky Linux 9
532+
- Fedora 38, 39, 40
533+
- Arch Linux
534+
- openSUSE Tumbleweed
535+
536+
3. **Alternative OS Tests** (`alt-os-test.yml`):
537+
- Amazon Linux 2023
538+
- Oracle Linux 8, 9
539+
- Red Hat UBI 8, 9
540+
- Alpine Linux
541+
- BusyBox
542+
543+
4. **Code Quality Checks** (`code-quality.yml`):
544+
- ShellCheck with different severity levels
545+
- Security scanning
546+
- Code style verification
547+
- Dependency analysis
548+
549+
### Local Testing
550+
551+
Before committing, it's recommended to run local tests:
552+
553+
```bash
554+
# Syntax check
555+
bash -n cert_manager.sh
556+
557+
# ShellCheck analysis (requires shellcheck installation)
558+
shellcheck -S warning cert_manager.sh
559+
560+
# Basic functional test
561+
echo "0" | sudo ./cert_manager.sh
562+
```
563+
456564
## 🔧 Usage Examples
457565

458566
### Issue Regular Certificate

cert_manager.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ install_dependencies() {
153153
}
154154

155155
install_acme() {
156-
cd ~
156+
cd ~ || return 1
157157
LOGI "Installing acme.sh..."
158158
curl https://get.acme.sh | sh
159159
if [ $? -ne 0 ]; then
@@ -212,10 +212,12 @@ ssl_cert_issue() {
212212
LOGD "Your domain is: ${domain}, checking it..."
213213

214214
# here we need to judge whether there exists cert already
215-
local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
215+
local currentCert
216+
currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
216217

217218
if [ "${currentCert}" == "${domain}" ]; then
218-
local certInfo=$(~/.acme.sh/acme.sh --list)
219+
local certInfo
220+
certInfo=$(~/.acme.sh/acme.sh --list)
219221
LOGE "System already has certificates for this domain, cannot issue again. Current certificates details:"
220222
LOGI "$certInfo"
221223
exit 1

0 commit comments

Comments
 (0)