1
+ name : ' Cleanup Autonomi Network'
2
+ description : ' Stops local Autonomi testnet and EVM processes, cleans up resources'
3
+ author : ' MaidSafe'
4
+
5
+ inputs :
6
+ upload-logs :
7
+ description : ' Whether to upload logs as artifacts'
8
+ required : false
9
+ default : ' false'
10
+
11
+ keep-directories :
12
+ description : ' Whether to keep network directories after cleanup'
13
+ required : false
14
+ default : ' true'
15
+
16
+ timeout-minutes :
17
+ description : ' Maximum time to wait for cleanup operations'
18
+ required : false
19
+ default : ' 5'
20
+
21
+ outputs :
22
+ cleanup-status :
23
+ description : ' Status of the cleanup operation'
24
+ value : ${{ steps.cleanup-network.outputs.status }}
25
+
26
+ runs :
27
+ using : ' composite'
28
+ steps :
29
+ - name : Install cleanup prerequisites
30
+ shell : bash
31
+ run : |
32
+ echo "Installing cleanup prerequisites..."
33
+
34
+ # Ensure basic tools are available
35
+ if ! command -v ps &> /dev/null; then
36
+ echo "Warning: ps command not found - process verification may fail"
37
+ fi
38
+
39
+ if ! command -v pkill &> /dev/null; then
40
+ echo "⚠️ WARNING: pkill command not found - trying to install procps"
41
+ sudo apt-get update && sudo apt-get install -y procps || {
42
+ echo "❌ ERROR: Could not install procps. Process cleanup may be incomplete."
43
+ echo " Manual cleanup may be required after this action completes."
44
+ }
45
+ fi
46
+
47
+ if ! command -v netstat &> /dev/null; then
48
+ echo "Installing net-tools for network diagnostics..."
49
+ sudo apt-get update && sudo apt-get install -y net-tools || {
50
+ echo "⚠️ WARNING: Could not install net-tools. Network diagnostics will be limited."
51
+ }
52
+ fi
53
+
54
+ echo "Prerequisites check completed"
55
+
56
+ - name : Stop Autonomi network processes
57
+ id : cleanup-network
58
+ shell : bash
59
+ run : |
60
+ echo "=========================================="
61
+ echo "Starting Autonomi Network Cleanup"
62
+ echo "=========================================="
63
+
64
+ cleanup_status="success"
65
+
66
+ # Stop antctl local network
67
+ echo "Stopping local Autonomi network..."
68
+ echo "Checking for antctl binary..."
69
+ which antctl || echo "antctl not found in PATH"
70
+
71
+ if command -v antctl &> /dev/null; then
72
+ if [[ "${{ inputs.keep-directories }}" == "true" ]]; then
73
+ echo "Running: antctl local kill --keep-directories"
74
+ antctl local kill --keep-directories || {
75
+ echo "⚠️ WARNING: antctl kill with keep-directories failed"
76
+ echo " This may indicate the network was already stopped or crashed"
77
+ echo " Continuing with manual process cleanup..."
78
+ cleanup_status="partial"
79
+ }
80
+ else
81
+ echo "Running: antctl local kill"
82
+ antctl local kill || {
83
+ echo "⚠️ WARNING: antctl kill failed"
84
+ echo " This may indicate the network was already stopped or crashed"
85
+ echo " Continuing with manual process cleanup..."
86
+ cleanup_status="partial"
87
+ }
88
+ fi
89
+ else
90
+ echo "⚠️ WARNING: antctl not found in PATH"
91
+ echo " The network may not have been properly started, or binaries were not installed"
92
+ echo " Continuing with manual process cleanup..."
93
+ cleanup_status="partial"
94
+ fi
95
+
96
+ # Stop EVM testnet process
97
+ echo "Stopping EVM testnet processes..."
98
+ if pkill -f "evm-testnet"; then
99
+ echo "✅ Stopped EVM testnet processes"
100
+ else
101
+ echo "ℹ️ No evm-testnet processes found (may not have been running)"
102
+ fi
103
+
104
+ # Stop anvil processes (if any)
105
+ echo "Stopping anvil processes..."
106
+ if pkill -f "anvil"; then
107
+ echo "✅ Stopped anvil processes"
108
+ else
109
+ echo "ℹ️ No anvil processes found (may not have been running)"
110
+ fi
111
+
112
+ # Kill any remaining antnode processes
113
+ echo "Stopping antnode processes..."
114
+ if pkill -f "antnode"; then
115
+ echo "✅ Stopped antnode processes"
116
+ else
117
+ echo "✅ No antnode processes found (antctl did its work)"
118
+ fi
119
+
120
+ # Wait a moment for processes to terminate
121
+ sleep 2
122
+
123
+ echo "status=$cleanup_status" >> $GITHUB_OUTPUT
124
+ echo "Cleanup status: $cleanup_status"
125
+
126
+ - name : Collect network logs
127
+ if : inputs.upload-logs == 'true'
128
+ shell : bash
129
+ run : |
130
+ echo "Collecting network logs for upload..."
131
+
132
+ # Create logs directory
133
+ mkdir -p network-logs
134
+
135
+ # Collect Autonomi logs if they exist
136
+ autonomi_log_dir="$HOME/.local/share/autonomi"
137
+ if [ -d "$autonomi_log_dir" ]; then
138
+ echo "Copying Autonomi logs from $autonomi_log_dir..."
139
+ cp -r "$autonomi_log_dir" network-logs/autonomi-logs/ || {
140
+ echo "⚠️ WARNING: Could not copy Autonomi logs"
141
+ echo " Log directory exists but copy failed - check permissions"
142
+ echo " Directory contents:"
143
+ ls -la "$autonomi_log_dir" || echo " Could not list directory contents"
144
+ }
145
+ else
146
+ echo "ℹ️ No Autonomi log directory found at $autonomi_log_dir"
147
+ fi
148
+
149
+ # Collect system logs related to our processes
150
+ echo "Collecting process information..."
151
+ ps aux | grep -E "(antnode|antctl|evm-testnet|anvil)" > network-logs/final-processes.txt || echo "No processes found"
152
+
153
+ # Collect network interface information
154
+ echo "Collecting network information..."
155
+ netstat -tlnp 2>/dev/null | grep -E ":(8545|3000|4000)" > network-logs/network-ports.txt || echo "No relevant ports found"
156
+
157
+ # Create a detailed summary
158
+ cat > network-logs/cleanup-summary.txt << 'CLEANUP_SUMMARY_EOF'
159
+ Autonomi Network Cleanup Summary
160
+ ===============================
161
+ Timestamp: $(date)
162
+ Cleanup Status: ${{ steps.cleanup-network.outputs.status }}
163
+ Keep Directories: ${{ inputs.keep-directories }}
164
+ Upload Logs: ${{ inputs.upload-logs }}
165
+ GitHub Run ID: ${{ github.run_id }}
166
+ Workflow: ${{ github.workflow }}
167
+
168
+ Process Cleanup Results:
169
+ - antctl network shutdown: $(if command -v antctl &> /dev/null; then echo "attempted"; else echo "skipped (not found)"; fi)
170
+ - antnode processes: $(if pkill -0 -f "antnode" 2>/dev/null; then echo "still running"; else echo "stopped"; fi)
171
+ - evm-testnet processes: $(if pkill -0 -f "evm-testnet" 2>/dev/null; then echo "still running"; else echo "stopped"; fi)
172
+ - anvil processes: $(if pkill -0 -f "anvil" 2>/dev/null; then echo "still running"; else echo "stopped"; fi)
173
+
174
+ Final Process Count: $(ps aux | grep -E "(antnode|antctl|evm-testnet|anvil)" | grep -v grep | wc -l) remaining
175
+
176
+ If cleanup status is 'partial', manual intervention may be required.
177
+ CLEANUP_SUMMARY_EOF
178
+
179
+ echo "Logs collected in network-logs directory"
180
+ ls -la network-logs/
181
+
182
+ - name : Upload network logs
183
+ if : inputs.upload-logs == 'true'
184
+ uses : actions/upload-artifact@v4
185
+ with :
186
+ name : autonomi-network-logs-${{ github.run_id }}
187
+ path : network-logs/
188
+ retention-days : 7
189
+
190
+ - name : Clean up temporary files
191
+ shell : bash
192
+ run : |
193
+ echo "Cleaning up temporary files..."
194
+
195
+ # Remove any temporary upload directories
196
+ rm -rf temp_uploads/ || echo "No temp_uploads directory"
197
+ rm -rf test_temp_* || echo "No test_temp files"
198
+
199
+ # Remove downloaded binaries if they exist in current directory
200
+ rm -f autonomi-binaries.zip autonomi-source.zip || echo "No binary archives to clean"
201
+
202
+ # Clean up any extracted source directories
203
+ rm -rf autonomi-stable-* autonomi-rc-* || echo "No source directories to clean"
204
+
205
+ echo "✅ Temporary files cleaned up"
206
+
207
+ - name : Cleanup summary
208
+ shell : bash
209
+ run : |
210
+ echo "=========================================="
211
+ echo "Autonomi Network Cleanup Complete"
212
+ echo "=========================================="
213
+ echo "Status: ${{ steps.cleanup-network.outputs.status }}"
214
+ echo "Keep Directories: ${{ inputs.keep-directories }}"
215
+ echo "Logs Uploaded: ${{ inputs.upload-logs }}"
216
+ echo "=========================================="
217
+
218
+ if [[ "${{ steps.cleanup-network.outputs.status }}" == "success" ]]; then
219
+ echo "🧹 Network cleanup completed successfully!"
220
+ else
221
+ echo "⚠️ Network cleanup completed with warnings - check logs above"
222
+ fi
0 commit comments