-
Notifications
You must be signed in to change notification settings - Fork 3
122 lines (105 loc) · 3.91 KB
/
validate-compose.yml
File metadata and controls
122 lines (105 loc) · 3.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Validate Docker Compose Files
on:
pull_request:
paths:
- '**/docker-compose.yml'
- '**/docker-compose.*.yml'
- '.github/scripts/validate_compose.py'
- '.github/workflows/validate-compose.yml'
push:
branches:
- main
paths:
- '**/docker-compose.yml'
- '**/docker-compose.*.yml'
workflow_dispatch: # Allow manual trigger
jobs:
validate:
name: Validate Compose Files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for file comparison
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install pyyaml
- name: Get changed files (PR only)
id: changed-files
if: github.event_name == 'pull_request'
run: |
# Get list of changed docker-compose files
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E 'docker-compose.*\.yml$' || true)
echo "files=${CHANGED_FILES}" >> $GITHUB_OUTPUT
if [ -n "$CHANGED_FILES" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Validate changed compose files (PR)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_changes == 'true'
run: |
echo "Validating changed files:"
echo "${{ steps.changed-files.outputs.files }}"
python .github/scripts/validate_compose.py --github-actions ${{ steps.changed-files.outputs.files }}
- name: Validate all compose files (push/manual)
if: github.event_name != 'pull_request'
run: |
python .github/scripts/validate_compose.py --github-actions --root .
- name: Skip message (no changes)
if: github.event_name == 'pull_request' && steps.changed-files.outputs.has_changes == 'false'
run: |
echo "No docker-compose files changed in this PR"
lint:
name: YAML Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install yamllint
run: pip install yamllint
- name: Create yamllint config
run: |
cat > .yamllint.yml << 'EOF'
extends: relaxed
rules:
line-length:
max: 200
truthy:
check-keys: false
comments:
min-spaces-from-content: 1
indentation:
spaces: 2
indent-sequences: true
EOF
- name: Lint docker-compose files
run: |
find . -name 'docker-compose*.yml' -not -path './.github/*' | xargs yamllint -c .yamllint.yml || true
continue-on-error: true # Don't fail on lint warnings
docker-compose-config:
name: Docker Compose Syntax Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate compose file syntax
run: |
# Find all docker-compose files and validate syntax
ERRORS=0
for file in $(find . -name 'docker-compose*.yml' -not -path './.github/*'); do
echo "Checking syntax: $file"
# Use docker compose config to validate (dry-run)
# We need to cd to the directory so relative paths work
DIR=$(dirname "$file")
BASENAME=$(basename "$file")
if ! (cd "$DIR" && docker compose -f "$BASENAME" config > /dev/null 2>&1); then
echo "::warning file=$file::Compose file has syntax issues (may be due to missing .env)"
fi
done
continue-on-error: true # .env files won't exist in CI