generated from bitcoin-sv/template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
278 lines (244 loc) · 11.8 KB
/
fortress-test-magex.yml
File metadata and controls
278 lines (244 loc) · 11.8 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# ------------------------------------------------------------------------------------
# Test MAGE-X (Reusable Workflow) (GoFortress)
#
# Purpose: Verify that MAGE-X is installed and working correctly with standard
# magex commands. This is a prerequisite for other workflows that use magex commands.
#
# Maintainer: @mrz1836
#
# ------------------------------------------------------------------------------------
name: GoFortress (Test MAGE-X)
on:
workflow_call:
inputs:
env-json:
description: "JSON string of environment variables"
required: true
type: string
primary-runner:
description: "Primary runner OS"
required: true
type: string
# Security: Restrict default permissions (jobs must explicitly request what they need)
permissions: {}
jobs:
# ----------------------------------------------------------------------------------
# Test MAGE-X (Installation and Command Verification)
# ----------------------------------------------------------------------------------
test-magex:
name: 🪄 Verify & Test MAGE-X
runs-on: ${{ inputs.primary-runner }}
permissions:
contents: read
steps:
# --------------------------------------------------------------------
# Parse environment variables
# --------------------------------------------------------------------
- name: 🔧 Parse environment variables
env:
ENV_JSON: ${{ inputs.env-json }}
run: |
echo "📋 Setting environment variables..."
echo "$ENV_JSON" | jq -r 'to_entries | .[] | "\(.key)=\(.value)"' | while IFS='=' read -r key value; do
echo "$key=$value" >> $GITHUB_ENV
done
# --------------------------------------------------------------------
# Checkout code (conditional: full or sparse based on MAGE_X_USE_LOCAL)
# --------------------------------------------------------------------
# Full checkout when using local build (needs cmd/magex directory)
- name: 📥 Checkout (full - local build)
if: env.MAGE_X_USE_LOCAL == 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
# Sparse checkout when using remote build (optimization)
- name: 📥 Checkout (sparse - remote build)
if: env.MAGE_X_USE_LOCAL == 'false'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # Required for sparse checkout
sparse-checkout: |
.github/env
.github/actions/setup-magex
.mage.yaml
go.mod
${{ env.GO_SUM_FILE }}
magefiles/
# --------------------------------------------------------------------
# Setup MAGE-X using the reusable composite action
# --------------------------------------------------------------------
- name: 🔧 Setup MAGE-X
id: setup-magex
uses: ./.github/actions/setup-magex
with:
magex-version: ${{ env.MAGE_X_VERSION }}
runner-os: ${{ inputs.primary-runner }}
use-local: ${{ env.MAGE_X_USE_LOCAL }}
# --------------------------------------------------------------------
# Validate MAGE-X version matches requested version
# --------------------------------------------------------------------
- name: 🔍 Validate MAGE-X Version
id: validate-version
run: |
echo "🔍 Validating MAGE-X version..."
# Get the actual version from the binary
ACTUAL_VERSION=$(magex --version 2>/dev/null | grep -E '^\s+Version:' | awk '{print $2}' || echo "unknown")
REQUESTED_VERSION="${{ env.MAGE_X_VERSION }}"
USE_LOCAL="${{ env.MAGE_X_USE_LOCAL }}"
echo "📋 Build mode: $([ "$USE_LOCAL" == "true" ] && echo "local (development)" || echo "remote (release)")"
echo "📋 Requested version: $REQUESTED_VERSION"
echo "📋 Actual version: $ACTUAL_VERSION"
if [[ "$ACTUAL_VERSION" == "unknown" ]]; then
echo "❌ Failed: Could not determine magex version from binary"
echo "❌ This indicates a problem with version detection or binary corruption"
echo "validation-result=failed" >> $GITHUB_OUTPUT
exit 1
fi
# Local builds should have "dev" version
if [[ "$USE_LOCAL" == "true" ]]; then
if [[ "$ACTUAL_VERSION" == "dev" ]]; then
echo "✅ Version validation passed: local build has expected 'dev' version"
echo "validation-result=success" >> $GITHUB_OUTPUT
else
echo "⚠️ Warning: Local build has version '$ACTUAL_VERSION', expected 'dev'"
echo "⚠️ This might indicate the version file hasn't been updated"
echo "✅ Accepting anyway since this is a local development build"
echo "validation-result=success-with-warning" >> $GITHUB_OUTPUT
fi
else
# Remote builds should match the requested version
REQUESTED_CLEAN=$(echo "$REQUESTED_VERSION" | sed 's/^v//')
ACTUAL_CLEAN=$(echo "$ACTUAL_VERSION" | sed 's/^v//')
if [[ "$ACTUAL_CLEAN" == "$REQUESTED_CLEAN" ]]; then
echo "✅ Version validation passed: $ACTUAL_VERSION matches $REQUESTED_VERSION"
echo "validation-result=success" >> $GITHUB_OUTPUT
else
echo "❌ Version mismatch detected!"
echo "❌ Requested: $REQUESTED_VERSION (clean: $REQUESTED_CLEAN)"
echo "❌ Actual: $ACTUAL_VERSION (clean: $ACTUAL_CLEAN)"
echo "❌ This indicates a cache corruption or installation failure"
echo "validation-result=failed" >> $GITHUB_OUTPUT
exit 1
fi
fi
# --------------------------------------------------------------------
# Verify MAGE-X installation and required commands
# --------------------------------------------------------------------
- name: ✅ Verify magex help and required commands
id: verify-magex
run: |
echo "📋 Testing for required magex commands..."
# Capture help output
HELP_OUTPUT=$(magex help)
echo "$HELP_OUTPUT"
# List of required magex commands
REQUIRED_COMMANDS=(
"bench"
"clean"
"deps:download"
"deps:update"
"format:fix"
"lint"
"metrics:coverage"
"metrics:loc"
"metrics:mage"
"release"
"release:validate"
"test"
"test:cover"
"test:coverrace"
"test:fuzz"
"test:race"
"tidy"
"update:install"
"version:bump"
"vet"
)
MATCHED_COUNT=0
MISSING_COUNT=0
MISSING_COMMANDS=()
echo ""
echo "🔍 Verifying required magex commands..."
for cmd in "${REQUIRED_COMMANDS[@]}"; do
if echo "$HELP_OUTPUT" | grep -qE "^[[:space:]]*$cmd[[:space:]]"; then
echo "✅ Found: $cmd"
MATCHED_COUNT=$((MATCHED_COUNT + 1))
else
echo "❌ Missing required command: $cmd"
MISSING_COMMANDS+=("$cmd")
MISSING_COUNT=$((MISSING_COUNT + 1))
fi
done
echo ""
echo "✅ Matched: $MATCHED_COUNT"
echo "❌ Missing: $MISSING_COUNT"
echo "matched=$MATCHED_COUNT" >> "$GITHUB_OUTPUT"
echo "missing=$MISSING_COUNT" >> "$GITHUB_OUTPUT"
echo "missing_commands=${MISSING_COMMANDS[*]}" >> "$GITHUB_OUTPUT"
# Fail if anything is missing
if [ $MISSING_COUNT -gt 0 ]; then
echo ""
echo "🚨 Missing MAGE-X commands:"
printf ' - %s\n' "${MISSING_COMMANDS[@]}"
exit 1
fi
echo ""
echo "✅ MAGE-X verification completed successfully."
# --------------------------------------------------------------------
# Collect Mage Metrics
# --------------------------------------------------------------------
- name: 📊 Collect Mage Metrics
id: mage-metrics
run: |
set -euo pipefail
echo "📋 Running magex metrics:mage..."
# Run magex metrics:mage and capture output
METRICS_OUTPUT=$(magex metrics:mage 2>&1 || true)
echo "$METRICS_OUTPUT"
# Parse directory found status
if echo "$METRICS_OUTPUT" | grep -q "Magefiles Directory Found: ✅"; then
echo "directory-found=true" >> $GITHUB_OUTPUT
else
echo "directory-found=false" >> $GITHUB_OUTPUT
fi
# Parse total functions count
TOTAL_FUNCTIONS=$(echo "$METRICS_OUTPUT" | grep -oE "Total functions found: [0-9]+" | grep -oE "[0-9]+" || echo "0")
echo "total-functions=$TOTAL_FUNCTIONS" >> $GITHUB_OUTPUT
# Count number of mage files (lines in table excluding header)
FILE_COUNT=$(echo "$METRICS_OUTPUT" | { grep -E "^\| magefiles/" || true; } | wc -l | tr -d ' ')
echo "file-count=$FILE_COUNT" >> $GITHUB_OUTPUT
echo ""
echo "✅ Mage metrics collected successfully."
# --------------------------------------------------------------------
# Summary of MAGE-X verification
# --------------------------------------------------------------------
- name: 📊 Job Summary
run: |
# Get magex version
MAGEX_VERSION=$(magex --version 2>/dev/null | grep -E '^\s+Version:' | awk '{print $2}' || echo "unknown")
echo "## 🪄 MAGE-X Verification Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Verification Details | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Test** | magex help command |" >> $GITHUB_STEP_SUMMARY
echo "| **Version** | $MAGEX_VERSION |" >> $GITHUB_STEP_SUMMARY
echo "| **Version Validation** | ${{ steps.validate-version.outputs.validation-result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Installation** | ${{ steps.setup-magex.outputs.installation-method == 'cached' && '💾 From cache' || '📥 Fresh install' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Purpose** | Verify MAGE-X installation and standard commands |" >> $GITHUB_STEP_SUMMARY
echo "| **Matched Commands** | ${{ steps.verify-magex.outputs.matched }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Missing Commands** | ${{ steps.verify-magex.outputs.missing }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Mage Metrics Section
echo "### 📁 Mage Metrics" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Magefiles Directory** | ${{ steps.mage-metrics.outputs.directory-found == 'true' && '✅ Found' || '❌ Not Found' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Mage Files** | ${{ steps.mage-metrics.outputs.file-count }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Total Functions** | ${{ steps.mage-metrics.outputs.total-functions }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ steps.verify-magex.outputs.missing }}" != "0" ]]; then
echo "🚨 **Missing Commands:** ${{ steps.verify-magex.outputs.missing_commands }}" >> $GITHUB_STEP_SUMMARY
else
echo "🎯 **MAGE-X is properly configured and functional.**" >> $GITHUB_STEP_SUMMARY
fi