Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 5b70235

Browse files
committed
feat: [#10] implement comprehensive linting infrastructure
- Add comprehensive linting script (scripts/lint.sh) with yamllint, shellcheck, and markdownlint - Simplify GitHub Actions workflow to focus only on linting checks - Add Makefile targets for linting (lint, lint-yaml, lint-shell, lint-markdown) - Fix all ShellCheck issues in shell scripts: - Quote variables properly in monitor-cloud-init.sh - Fix sed command in test-local-setup.sh - Use array handling for yamllint config - Fix markdown line length issues in documentation files - Update yamllint config to support GitHub Actions syntax - Add linting documentation to main README - Remove empty test file and cleanup directory structure All linting checks now pass successfully, providing a solid foundation for maintaining code quality across the entire project.
1 parent fdf1a95 commit 5b70235

File tree

15 files changed

+407
-120
lines changed

15 files changed

+407
-120
lines changed

.github/workflows/infrastructure.yml

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,41 @@ on:
55
branches: [main, develop]
66
paths:
77
- "infrastructure/**"
8-
- "infrastructure/tests/**"
8+
- "application/**"
9+
- "scripts/**"
910
- "Makefile"
1011
- ".github/workflows/infrastructure.yml"
12+
- "**/*.md"
13+
- "**/*.yml"
14+
- "**/*.yaml"
15+
- "**/*.sh"
1116
pull_request:
1217
branches: [main, develop]
1318
paths:
1419
- "infrastructure/**"
15-
- "infrastructure/tests/**"
20+
- "application/**"
21+
- "scripts/**"
1622
- "Makefile"
1723
- ".github/workflows/infrastructure.yml"
24+
- "**/*.md"
25+
- "**/*.yml"
26+
- "**/*.yaml"
27+
- "**/*.sh"
1828

1929
jobs:
20-
validate-infrastructure:
30+
lint:
2131
runs-on: ubuntu-22.04
2232

2333
steps:
2434
- name: Checkout code
2535
uses: actions/checkout@v4
2636

27-
- name: Install OpenTofu
28-
run: |
29-
curl -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
30-
chmod +x install-opentofu.sh
31-
sudo ./install-opentofu.sh --install-method deb
32-
rm install-opentofu.sh
33-
tofu version
34-
35-
- name: Install yamllint
37+
- name: Install linting tools
3638
run: |
3739
sudo apt-get update
38-
sudo apt-get install -y yamllint
39-
40-
- name: Test script permissions
41-
run: |
42-
test -x infrastructure/tests/test-local-setup.sh
43-
test -x infrastructure/tests/test-integration.sh
40+
sudo apt-get install -y yamllint shellcheck
41+
sudo npm install -g markdownlint-cli
4442
45-
- name: Run syntax tests
46-
env:
47-
CI: true
43+
- name: Run linting script
4844
run: |
49-
make ci-test-syntax
50-
51-
- name: Validate Makefile targets
52-
run: |
53-
make help
54-
make workflow-help
55-
56-
# Note: Full VM testing is not run in CI as it requires KVM/nested virtualization
57-
# which is not available in GitHub Actions runners
58-
documentation-check:
59-
runs-on: ubuntu-22.04
60-
61-
steps:
62-
- name: Checkout code
63-
uses: actions/checkout@v4
64-
65-
- name: Check documentation links
66-
run: |
67-
# Verify documentation files exist
68-
test -f infrastructure/docs/quick-start.md
69-
test -f infrastructure/docs/local-testing-setup.md
70-
test -f infrastructure/README.md
71-
test -f application/README.md
72-
73-
# Check for common documentation issues
74-
grep -q "Quick Start" infrastructure/docs/quick-start.md
75-
grep -q "OpenTofu" infrastructure/docs/local-testing-setup.md
76-
grep -q "make" README.md
45+
./scripts/lint.sh

.yamllint-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ rules:
77
min-spaces-from-content: 1 # Allow single space before comments
88
document-start: disable # Cloud-init files don't need --- start
99
truthy:
10-
allowed-values: ["true", "false", "yes", "no"] # Allow cloud-init common values
10+
allowed-values: ["true", "false", "yes", "no", "on", "off"] # Allow cloud-init and GitHub Actions common values

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for Torrust Tracker Local Testing Infrastructure
2-
.PHONY: help init plan apply destroy test clean status ssh install-deps console vm-console
2+
.PHONY: help init plan apply destroy test clean status ssh install-deps console vm-console lint lint-yaml lint-shell lint-markdown
33

44
# Default variables
55
VM_NAME ?= torrust-tracker-demo
@@ -140,6 +140,22 @@ test-syntax: ## Test configuration syntax only
140140
@echo "Testing configuration syntax..."
141141
$(TESTS_DIR)/test-local-setup.sh syntax
142142

143+
lint: ## Run all linting checks (yamllint, shellcheck, markdownlint)
144+
@echo "Running linting checks..."
145+
./scripts/lint.sh
146+
147+
lint-yaml: ## Run only yamllint
148+
@echo "Running yamllint..."
149+
./scripts/lint.sh --yaml
150+
151+
lint-shell: ## Run only shellcheck
152+
@echo "Running shellcheck..."
153+
./scripts/lint.sh --shell
154+
155+
lint-markdown: ## Run only markdownlint
156+
@echo "Running markdownlint..."
157+
./scripts/lint.sh --markdown
158+
143159
test-integration: ## Run integration tests (requires deployed VM)
144160
@echo "Running integration tests..."
145161
$(TESTS_DIR)/test-integration.sh full-test

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ For contributors and developers:
118118
- **General contributing guidelines**: See [`.github/copilot-instructions.md`](.github/copilot-instructions.md)
119119
- **Architecture decisions**: See [`docs/adr/`](docs/adr/) for design rationale
120120

121+
### Code Quality and Linting
122+
123+
The project uses automated linting to ensure code quality and consistency:
124+
125+
```bash
126+
# Run all linting checks
127+
make lint
128+
129+
# Run individual linters
130+
make lint-yaml # YAML files (yamllint)
131+
make lint-shell # Shell scripts (shellcheck)
132+
make lint-markdown # Markdown files (markdownlint)
133+
```
134+
135+
**Required tools:**
136+
137+
- `yamllint` - YAML syntax and style checking
138+
- `shellcheck` - Shell script analysis
139+
- `markdownlint` - Markdown style and structure checking
140+
141+
**Installation:**
142+
143+
```bash
144+
# Ubuntu/Debian
145+
sudo apt-get install yamllint shellcheck
146+
sudo npm install -g markdownlint-cli
147+
148+
# Or install all project dependencies
149+
make install-deps
150+
```
151+
152+
Linting is automatically run in CI/CD pipelines to validate all contributions.
153+
121154
> **Note**: The main `Makefile` is kept at the root level to serve as the
122155
> project's primary interface. See [ADR-001](docs/adr/001-makefile-location.md)
123156
> for the full rationale.

application/docs/backups.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```bash
66
cd /home/torrust/github/torrust/torrust-tracker-demo/
7-
./share/bin/tracker-db-backup.sh
7+
./share/bin/tracker-db-backup.sh
88
```
99

1010
## Check Backups Crontab Configuration
@@ -13,7 +13,9 @@ cd /home/torrust/github/torrust/torrust-tracker-demo/
1313
sudo crontab -e
1414
```
1515

16-
You should see the [crontab.conf](../share/container/default/config/crontab.conf) configuration file.
16+
You should see the
17+
[crontab.conf](../share/container/default/config/crontab.conf) configuration
18+
file.
1719

1820
## Check Backups
1921

application/docs/deployment.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,43 @@
44
2. Execute the deployment script: `./bin/deploy-torrust-tracker-demo.com.sh`.
55
3. Execute the smoke tests:
66

7-
```console
8-
# Clone Torrust Tracker
9-
[email protected]:torrust/torrust-tracker.git
10-
cd torrust-tracker
11-
```
7+
```console
8+
# Clone Torrust Tracker
9+
[email protected]:torrust/torrust-tracker.git
10+
cd torrust-tracker
11+
```
1212

13-
Execute the following commands to run the tracker client and checker.
13+
Execute the following commands to run the tracker client and checker.
1414

15-
Simulate a torrent announce to the tracker using UDP:
15+
Simulate a torrent announce to the tracker using UDP:
1616

17-
```console
18-
cargo run -p torrust-tracker-client --bin udp_tracker_client announce udp://tracker.torrust-demo.com:6969/announce 9c38422213e30bff212b30c360d26f9a02136422 | jq
19-
```
17+
```console
18+
cargo run -p torrust-tracker-client --bin udp_tracker_client announce \
19+
udp://tracker.torrust-demo.com:6969/announce \
20+
9c38422213e30bff212b30c360d26f9a02136422 | jq
21+
```
2022

21-
Simulate a torrent scrape to the tracker using HTTP:
23+
Simulate a torrent scrape to the tracker using HTTP:
2224

23-
```console
24-
cargo run -p torrust-tracker-client --bin http_tracker_client announce https://tracker.torrust-demo.com 9c38422213e30bff212b30c360d26f9a02136422 | jq
25-
```
25+
```console
26+
cargo run -p torrust-tracker-client --bin http_tracker_client announce \
27+
https://tracker.torrust-demo.com \
28+
9c38422213e30bff212b30c360d26f9a02136422 | jq
29+
```
2630

27-
Make a request to the health check endpoint:
31+
Make a request to the health check endpoint:
2832

29-
```console
30-
TORRUST_CHECKER_CONFIG='{
31-
"udp_trackers": ["udp://tracker.torrust-demo.com:6969/announce"],
32-
"http_trackers": ["https://tracker.torrust-demo.com"],
33-
"health_checks": ["https://tracker.torrust-demo.com/api/health_check"]
34-
}' cargo run -p torrust-tracker-client --bin tracker_checker
33+
```console
34+
TORRUST_CHECKER_CONFIG='{
35+
"udp_trackers": ["udp://tracker.torrust-demo.com:6969/announce"],
36+
"http_trackers": ["https://tracker.torrust-demo.com"],
37+
"health_checks": ["https://tracker.torrust-demo.com/api/health_check"]
38+
}' cargo run -p torrust-tracker-client --bin tracker_checker
3539

36-
```
40+
```
3741

3842
4. Check the logs of the tracker container to see if everything is working:
3943

40-
```console
41-
./share/bin/tracker-filtered-logs.sh
42-
```
44+
```console
45+
./share/bin/tracker-filtered-logs.sh
46+
```

application/docs/rollbacks.md

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
# Rollbacks
22

3-
If you have a problems after a [deployment](deployment.md), you can rollback to the previous version of the app.
3+
If you have a problems after a [deployment](deployment.md), you can rollback
4+
to the previous version of the app.
45

56
1. SSH into the server.
67

78
2. Check the docker images to see the previous version of the app:
89

9-
```console
10-
docker images torrust/tracker
11-
REPOSITORY TAG IMAGE ID CREATED SIZE
12-
torrust/tracker develop b081a7499542 19 minutes ago 133MB
13-
torrust/tracker <none> 7dbdad453cf3 6 hours ago 133MB
14-
```
10+
```console
11+
docker images torrust/tracker
12+
REPOSITORY TAG IMAGE ID CREATED SIZE
13+
torrust/tracker develop b081a7499542 19 minutes ago 133MB
14+
torrust/tracker <none> 7dbdad453cf3 6 hours ago 133MB
15+
```
1516

1617
3. Tag the previous version of the app with a new name (e.g. `rollback`):
1718

18-
```console
19-
docker tag 7dbdad453cf3 torrust/tracker:rollback
20-
```
19+
```console
20+
docker tag 7dbdad453cf3 torrust/tracker:rollback
21+
```
2122

22-
This command tags the image with ID `7dbdad453cf3` as `torrust/tracker:rollback`.
23+
This command tags the image with ID `7dbdad453cf3` as `torrust/tracker:rollback`.
2324

24-
```console
25-
docker images torrust/tracker
26-
REPOSITORY TAG IMAGE ID CREATED SIZE
27-
torrust/tracker develop b081a7499542 21 minutes ago 133MB
28-
torrust/tracker rollback 7dbdad453cf3 6 hours ago 133MB
29-
```
25+
```console
26+
docker images torrust/tracker
27+
REPOSITORY TAG IMAGE ID CREATED SIZE
28+
torrust/tracker develop b081a7499542 21 minutes ago 133MB
29+
torrust/tracker rollback 7dbdad453cf3 6 hours ago 133MB
30+
```
3031

31-
The `rollback` tag now points to the previous version of the app.
32+
The `rollback` tag now points to the previous version of the app.
3233

3334
4. Edit the `compose.yaml` file to use the new tag:
3435

35-
Change the line:
36+
Change the line:
3637

37-
```yaml
38-
image: torrust/tracker:develop
39-
```
38+
```yaml
39+
image: torrust/tracker:develop
40+
```
4041
41-
to:
42+
to:
4243
43-
```yaml
44-
image: torrust/tracker:rollback
45-
```
44+
```yaml
45+
image: torrust/tracker:rollback
46+
```
4647
4748
5. Run the following command to start the previous version of the app:
4849
49-
```console
50-
docker compose up --build --detach
51-
```
50+
```console
51+
docker compose up --build --detach
52+
```
5253

5354
6. Check the logs of the tracker container to see if everything is working:
5455

55-
```console
56-
./share/bin/tracker-filtered-logs.sh
57-
```
56+
```console
57+
./share/bin/tracker-filtered-logs.sh
58+
```

application/docs/useful-commands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
- `docker ps`: list containers.
44
- `docker compose logs -f`: print all containers' logs.
55
- `docker compose logs -f tracker`: print tracker container' logs.
6-
- `docker compose logs -f tracker | head -n100`: print the first 100 lines in the tracker container log.
6+
- `docker compose logs -f tracker | head -n100`: print the first 100 lines
7+
in the tracker container log.
78
- `docker compose logs -f | grep "ERROR"`: print logs showing only errors.

docs/guides/integration-testing-guide.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ ls infrastructure/terraform/terraform.tfstate* 2>/dev/null && \
106106

107107
**Expected Output**: All checks should show "✅" (no conflicts).
108108

109-
110109
### 1.4.1 Manual Cleanup (if needed)
111110

112111
If the verification step shows "❌ Volumes still exist!" then manually clean them:
@@ -126,7 +125,8 @@ virsh vol-list user-default 2>/dev/null | grep torrust-tracker-demo && \
126125

127126
**Expected Output**: Should show "✅ No volume conflicts" after manual cleanup.
128127

129-
**What This Fixes**: Removes leftover volumes that `make clean-and-fix` sometimes misses.
128+
**What This Fixes**: Removes leftover volumes that `make clean-and-fix`
129+
sometimes misses.
130130

131131
### 1.5 Set Up SSH Key Configuration
132132

@@ -328,7 +328,7 @@ sudo systemctl status cloud-init-local cloud-init cloud-config cloud-final
328328
# Exit console: Ctrl+]
329329
```
330330

331-
**Method 2: Use virt-viewer for graphical console access**
331+
#### Method 2: Use virt-viewer for graphical console access
332332

333333
```bash
334334
# Connect to VM graphical console (shows login prompt)
@@ -338,7 +338,9 @@ virt-viewer spice://127.0.0.1:5900
338338
virt-viewer torrust-tracker-demo
339339
```
340340

341-
**Note**: The virt-viewer method provides a graphical console where you should see a login prompt. This is particularly useful when the text-based virsh console doesn't work or when you need to see the full boot process.
341+
**Note**: The virt-viewer method provides a graphical console where you should
342+
see a login prompt. This is particularly useful when the text-based virsh
343+
console doesn't work or when you need to see the full boot process.
342344

343345
#### Check from Host System
344346

0 commit comments

Comments
 (0)