-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (172 loc) · 6.45 KB
/
build-pr.yml
File metadata and controls
208 lines (172 loc) · 6.45 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: 🔨 Build & Test PR
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: read
concurrency:
group: pr-build-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
detect-changes:
name: 🔍 Detect Modified Exporters
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
exporters: ${{ steps.detect.outputs.exporters }}
has_changes: ${{ steps.detect.outputs.has_changes }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 🔍 Detect Changed Exporters
id: detect
run: |
echo "::group::🔍 Detecting modified exporters in PR"
# Get changed files in this PR
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^exporters/' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "ℹ️ No changes in exporters/"
echo "exporters=[]" >> $GITHUB_OUTPUT
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "::endgroup::"
exit 0
fi
# Extract unique exporter names
EXPORTERS=$(echo "$CHANGED_FILES" | cut -d'/' -f2 | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "exporters=$EXPORTERS" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
COUNT=$(echo "$EXPORTERS" | jq '. | length')
echo "✓ Found $COUNT modified exporter(s): $(echo "$EXPORTERS" | jq -r 'join(", ")')"
echo "::endgroup::"
validate-manifests:
name: ✅ Validate Manifests
runs-on: ubuntu-latest
timeout-minutes: 10
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: 'requirements/base.txt'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Validate Modified Exporters
env:
EXPORTERS: ${{ needs.detect-changes.outputs.exporters }}
run: |
echo "::group::✅ Validating manifests"
export PYTHONPATH=$GITHUB_WORKSPACE
echo "$EXPORTERS" | jq -r '.[]' | while read exporter; do
manifest="exporters/$exporter/manifest.yaml"
if [ ! -f "$manifest" ]; then
echo "⚠️ Skipping $exporter (no manifest)"
continue
fi
python3 core/scripts/validate_manifest.py "$manifest"
done
echo "::endgroup::"
- name: Validate URLs
env:
EXPORTERS: ${{ needs.detect-changes.outputs.exporters }}
run: |
echo "::group::🔗 Validating download URLs"
echo "$EXPORTERS" | jq -r '.[]' | while read exporter; do
echo "Checking $exporter..."
python3 core/scripts/validate_urls.py "$exporter" || echo "⚠️ URL validation failed for $exporter (non-blocking)"
done
echo "::endgroup::"
canary-build:
name: 🧪 Canary Build (node_exporter)
runs-on: ubuntu-latest
timeout-minutes: 20
needs: detect-changes
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: 'requirements/base.txt'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Test Full Pipeline
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
chmod +x core/scripts/*.sh
echo "Testing full pipeline with node_exporter as canary..."
./core/scripts/local_test.sh node_exporter --validate
deb-canary:
name: 🧪 DEB Build Test (${{ matrix.dist }})
runs-on: ubuntu-latest
timeout-minutes: 20
needs: detect-changes
strategy:
fail-fast: false
matrix:
dist: [ubuntu-22.04, debian-12]
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: 'pip'
cache-dependency-path: 'requirements/base.txt'
- name: Install dependencies
run: pip install -r requirements/base.txt
- name: Test DEB Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DIST: ${{ matrix.dist }}
run: |
chmod +x core/scripts/*.sh
echo "Testing DEB build for node_exporter on $DIST..."
./core/scripts/test_deb_build.sh node_exporter "$DIST" amd64
- name: Validate Package
run: |
deb_file=$(find build -name "*.deb" | head -1)
if [ -z "$deb_file" ]; then
echo "❌ No DEB file found"
exit 1
fi
echo "Validating: $deb_file"
dpkg-deb --info "$deb_file"
dpkg-deb --contents "$deb_file" | grep -E "(usr/bin|systemd)"
echo "✓ DEB validation passed"
summary:
name: 📊 Summary
runs-on: ubuntu-latest
needs: [detect-changes, validate-manifests, canary-build, deb-canary]
if: always()
steps:
- name: Generate Summary
env:
EXPORTERS: ${{ needs.detect-changes.outputs.exporters }}
HAS_CHANGES: ${{ needs.detect-changes.outputs.has_changes }}
VALIDATE_STATUS: ${{ needs.validate-manifests.result }}
CANARY_STATUS: ${{ needs.canary-build.result }}
DEB_STATUS: ${{ needs.deb-canary.result }}
run: |
echo "## 🔨 PR Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$HAS_CHANGES" = "true" ]; then
echo "**Modified exporters:**" >> $GITHUB_STEP_SUMMARY
echo "$EXPORTERS" | jq -r '.[] | "- " + .' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ No exporters modified in this PR" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
echo "**Validation Results:**" >> $GITHUB_STEP_SUMMARY
echo "- Manifest validation: $VALIDATE_STATUS" >> $GITHUB_STEP_SUMMARY
echo "- Canary build (RPM+Docker): $CANARY_STATUS" >> $GITHUB_STEP_SUMMARY
echo "- DEB build test: $DEB_STATUS" >> $GITHUB_STEP_SUMMARY