-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (72 loc) · 2.91 KB
/
ci.yml
File metadata and controls
79 lines (72 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# ===========================================================================
# CI — Validate Docker Compose files on every PR
#
# Runs `docker compose config --quiet` on every service whose compose file
# was added or modified in the PR. Catches YAML errors, bad env variable
# references, and schema violations before they reach main.
# ===========================================================================
name: Validate compose files
on:
pull_request:
paths:
- "services/**/docker-compose.yml"
- ".github/workflows/ci.yml"
push:
branches: [main]
paths:
- "services/**/docker-compose.yml"
- ".github/workflows/ci.yml"
workflow_dispatch: # Allow manual trigger from Actions tab
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Find changed or all compose files
id: find
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# On PRs: only validate changed compose files
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD \
| grep "docker-compose.yml" || true)
else
# On push to main: validate everything
FILES=$(find services -name "docker-compose.yml" | sort)
fi
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$FILES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "Found $(echo "$FILES" | grep -c . || echo 0) file(s) to validate"
- name: Seed .env files from .env.example for validation
run: |
# Services that use env_file: .env or have volume vars without defaults
# need a .env present. Copy .env.example → .env for every service so
# validation uses the documented placeholder values.
find services -name ".env.example" | while IFS= read -r f; do
cp "$f" "$(dirname "$f")/.env"
done
echo "Seeded $(find services -name ".env.example" | wc -l) .env files"
- name: Validate compose files
if: steps.find.outputs.files != ''
run: |
FAILED=0
while IFS= read -r file; do
[[ -z "$file" ]] && continue
dir="$(dirname "$file")"
echo -n " Validating $file ... "
# Use an empty env so missing vars default to blank (expected for templates)
if docker compose -f "$file" config --quiet 2>/dev/null; then
echo "OK"
else
echo "FAILED"
docker compose -f "$file" config 2>&1 | grep -v "variable is not set" || true
FAILED=$((FAILED + 1))
fi
done <<< "${{ steps.find.outputs.files }}"
if [[ $FAILED -gt 0 ]]; then
echo ""
echo "ERROR: $FAILED compose file(s) failed validation."
exit 1
fi
echo ""
echo "All compose files are valid."