-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (164 loc) · 6.66 KB
/
auto-release.yml
File metadata and controls
194 lines (164 loc) · 6.66 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
name: 🤖 Auto Release
run-name: >-
🤖 ${{ github.event_name == 'workflow_dispatch'
&& format('Manual Release - {0}', inputs.exporters != '' && inputs.exporters || 'All exporters')
|| 'Automatic Release - New release' }}
on:
push:
branches: [main]
paths:
- 'exporters/**'
workflow_dispatch:
inputs:
exporters:
description: 'Comma-separated list of exporters to build (leave empty to build ALL exporters)'
required: false
type: string
default: ''
permissions:
contents: write
actions: write
concurrency:
group: auto-release
cancel-in-progress: false
jobs:
detect-changes:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
exporters: ${{ steps.detect.outputs.exporters }}
matrix: ${{ steps.detect.outputs.matrix }}
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: 🔍 Detect Changed Exporters
id: detect
env:
INPUT_EXPORTERS: ${{ inputs.exporters }}
CATALOG_URL: https://sckyzo.github.io/monitoring-hub/catalog/index.json
PYTHONPATH: ${{ github.workspace }}
run: |
echo "::group::🔍 Detecting exporters to build"
# Check if workflow was manually triggered
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "Manual trigger detected"
# Check if specific exporters were provided
if [ -n "$INPUT_EXPORTERS" ]; then
echo "Building specific exporters: $INPUT_EXPORTERS"
# Convert comma-separated list to JSON array
EXPORTERS_JSON=$(echo "$INPUT_EXPORTERS" | jq -R -c \
'split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0))')
echo "exporters=$EXPORTERS_JSON" >> $GITHUB_OUTPUT
echo "matrix={\"exporter\":$EXPORTERS_JSON}" >> $GITHUB_OUTPUT
COUNT=$(echo "$EXPORTERS_JSON" | jq '. | length')
echo "✓ Building $COUNT specific exporter(s): $(echo "$EXPORTERS_JSON" | jq -r 'join(", ")')"
echo "::endgroup::"
exit 0
else
# No specific exporters - force rebuild ALL
echo "Force rebuild ALL exporters"
export FORCE_REBUILD=true
fi
fi
# Use state_manager for smart detection
echo "Using state_manager for change detection..."
python3 core/engine/state_manager.py
# Read outputs from state_manager
EXPORTERS_JSON=$(grep "^exporters=" $GITHUB_OUTPUT | cut -d= -f2)
BUILD_NEEDED=$(grep "^build_needed=" $GITHUB_OUTPUT | cut -d= -f2)
if [ "$BUILD_NEEDED" = "false" ]; then
echo "ℹ️ No exporters need building (all up to date)"
echo "matrix={\"exporter\":[]}" >> $GITHUB_OUTPUT
echo "::endgroup::"
exit 0
fi
# Generate matrix
echo "matrix={\"exporter\":$EXPORTERS_JSON}" >> $GITHUB_OUTPUT
COUNT=$(echo "$EXPORTERS_JSON" | jq '. | length')
echo "✓ Detected $COUNT exporter(s) to build: $(echo "$EXPORTERS_JSON" | jq -r 'join(", ")')"
echo "::endgroup::"
- name: 📊 Generate Summary
if: steps.detect.outputs.exporters != '[]'
env:
EXPORTERS_LIST: ${{ steps.detect.outputs.exporters }}
TRIGGER_MODE: ${{ github.event_name }}
run: |
echo "## 🚀 Auto Release Triggered" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$TRIGGER_MODE" = "workflow_dispatch" ]; then
echo "**Mode:** Manual trigger" >> $GITHUB_STEP_SUMMARY
else
echo "**Mode:** Automatic (push to main)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Exporters to build:**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "$EXPORTERS_LIST" | jq -r '.[] | "- **" + . + "**"' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Release workflows will be triggered for each exporter." >> $GITHUB_STEP_SUMMARY
trigger-releases:
name: 🚀 Trigger Build
needs: detect-changes
if: needs.detect-changes.outputs.exporters != '[]'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- name: 📊 Count Exporters
id: count
env:
EXPORTERS: ${{ needs.detect-changes.outputs.exporters }}
run: |
count=$(echo "$EXPORTERS" | jq '. | length')
echo "count=$count" >> $GITHUB_OUTPUT
echo "Found $count exporter(s) to build"
# Log exporters list
echo "$EXPORTERS" | jq -r '.[]' | while read exp; do
echo " → $exp"
done
- name: 🚀 Trigger Build Workflow
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXPORTERS: ${{ needs.detect-changes.outputs.exporters }}
COUNT: ${{ steps.count.outputs.count }}
run: |
echo "::group::🚀 Triggering build workflow for $COUNT exporter(s)"
# Format exporters list for display
echo "Exporters to build:"
echo "$EXPORTERS" | jq -r '.[]' | while read exp; do
echo " → $exp"
done
# Trigger unified build.yml workflow
# Now handles both single and batch builds
max_retries=3
for i in $(seq 1 $max_retries); do
if gh workflow run build.yml \
--repo ${{ github.repository }} \
--ref main \
--raw-field exporters="$EXPORTERS"; then
echo "✓ Build workflow triggered successfully"
echo "## ✅ Build Triggered" >> $GITHUB_STEP_SUMMARY
echo "**Exporters:** $COUNT" >> $GITHUB_STEP_SUMMARY
echo "**Workflow:** build.yml (unified)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**List:**" >> $GITHUB_STEP_SUMMARY
echo "$EXPORTERS" | jq -r '.[] | "- " + .' >> $GITHUB_STEP_SUMMARY
break
else
if [ $i -lt $max_retries ]; then
echo "⚠️ Attempt $i failed, retrying in 10s..."
sleep 10
else
echo "❌ Failed to trigger workflow after $max_retries attempts"
exit 1
fi
fi
done
echo "::endgroup::"