1
+ name : netsim-runner
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ branch :
7
+ required : true
8
+ type : string
9
+ max_workers :
10
+ required : true
11
+ type : number
12
+ default : 4
13
+ netsim_branch :
14
+ required : true
15
+ type : string
16
+ default : " main"
17
+ debug_logs :
18
+ required : false
19
+ type : boolean
20
+ default : false
21
+ build_profile :
22
+ required : false
23
+ type : string
24
+ default : " release"
25
+ sim_paths :
26
+ required : false
27
+ type : string
28
+ default : " sims/iroh,sims/integration"
29
+ publish_metrics :
30
+ required : false
31
+ type : boolean
32
+ default : false
33
+ visualizations :
34
+ required : false
35
+ type : boolean
36
+ default : false
37
+ pr_number :
38
+ required : false
39
+ type : string
40
+ default : " "
41
+ report_table :
42
+ required : false
43
+ type : boolean
44
+ default : false
45
+ workflow_call :
46
+ inputs :
47
+ branch :
48
+ required : true
49
+ type : string
50
+ max_workers :
51
+ required : true
52
+ type : number
53
+ default : 4
54
+ netsim_branch :
55
+ required : true
56
+ type : string
57
+ default : " main"
58
+ debug_logs :
59
+ required : false
60
+ type : boolean
61
+ default : false
62
+ build_profile :
63
+ required : false
64
+ type : string
65
+ default : " release"
66
+ sim_paths :
67
+ required : false
68
+ type : string
69
+ default : " sims/iroh,sims/integration"
70
+ publish_metrics :
71
+ required : false
72
+ type : boolean
73
+ default : false
74
+ visualizations :
75
+ required : false
76
+ type : boolean
77
+ default : false
78
+ pr_number :
79
+ required : false
80
+ type : string
81
+ default : " "
82
+ report_table :
83
+ required : false
84
+ type : boolean
85
+ default : false
86
+
87
+ env :
88
+ RUST_BACKTRACE : 1
89
+ RUSTFLAGS : -Dwarnings
90
+ MSRV : " 1.66"
91
+ SCCACHE_GHA_ENABLED : " true"
92
+ RUSTC_WRAPPER : " sccache"
93
+ IROH_FORCE_STAGING_RELAYS : " 1"
94
+
95
+ jobs :
96
+ netsim :
97
+ permissions : write-all
98
+ name : Netsim
99
+ timeout-minutes : 45
100
+ runs-on : [self-hosted, linux, X64]
101
+ steps :
102
+ - name : Checkout
103
+ uses : actions/checkout@v4
104
+ with :
105
+ submodules : recursive
106
+ ref : ${{ inputs.branch }}
107
+
108
+ - name : Install rust stable
109
+ uses : dtolnay/rust-toolchain@stable
110
+
111
+ - name : Install sccache
112
+ uses : mozilla-actions/sccache-action@v0.0.6
113
+
114
+ - name : Build iroh
115
+ run : |
116
+ cargo build --profile ${{ inputs.build_profile }} --workspace --all-features --examples --bins
117
+
118
+ - name : Fetch and build chuck
119
+ run : |
120
+ cd ..
121
+ rm -rf chuck
122
+ git clone --single-branch --branch ${{ inputs.netsim_branch }} https://github.com/n0-computer/chuck.git
123
+ cd chuck
124
+ cargo build --release
125
+
126
+ - name : Install netsim deps
127
+ run : |
128
+ cd ../chuck/netsim
129
+ sudo apt update
130
+ ./setup.sh
131
+ ./cleanup.sh || true
132
+
133
+ - name : Copy binaries to right location
134
+ run : |
135
+ cp target/${{inputs.build_profile}}/examples/* ../chuck/netsim/bins/
136
+ cp target/${{inputs.build_profile}}/iroh ../chuck/netsim/bins/iroh
137
+ cp target/${{inputs.build_profile}}/iroh-relay ../chuck/netsim/bins/iroh-relay
138
+ cp ../chuck/target/release/chuck ../chuck/netsim/bins/chuck
139
+
140
+ - name : Get commit sha
141
+ shell : bash
142
+ run : |
143
+ echo "LAST_COMMIT_SHA=$(git rev-parse --short ${GITHUB_SHA})" >> ${GITHUB_ENV}
144
+
145
+ - name : Run tests
146
+ id : run_tests
147
+ continue-on-error : true
148
+ run : |
149
+ cd ../chuck/netsim
150
+ # split sim_paths by comma
151
+ IFS=',' read -ra sim_paths <<< "${{ inputs.sim_paths }}"
152
+ for sim_path in "${sim_paths[@]}"; do
153
+ sudo python3 main.py ${{ inputs.debug_logs && '--debug' || ''}} ${{ inputs.visualizations && '--visualize' || ''}} --max-workers=${{ inputs.max_workers }} --integration $sim_path
154
+ done
155
+
156
+ - name : Generate report
157
+ id : generate_report
158
+ if : always()
159
+ run : |
160
+ cd ../chuck/netsim
161
+ python3 reports_csv.py --table > report_table.txt
162
+ python3 reports_csv.py --prom --commit ${{ env.LAST_COMMIT_SHA }} > report_prom.txt
163
+ python3 reports_csv.py --metro --commit ${{ env.LAST_COMMIT_SHA }} > report_metro.txt
164
+ python3 reports_csv.py --metro --integration --commit ${{ env.LAST_COMMIT_SHA }} > report_metro_integration.txt
165
+
166
+ - name : Upload report
167
+ if : always()
168
+ run : |
169
+ export AWS_ACCESS_KEY_ID=${{secrets.S3_ACCESS_KEY_ID}}
170
+ export AWS_SECRET_ACCESS_KEY=${{secrets.S3_ACCESS_KEY}}
171
+ export AWS_DEFAULT_REGION=us-west-2
172
+
173
+ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
174
+ unzip -q awscliv2.zip
175
+ sudo ./aws/install --update
176
+
177
+ cd ../chuck/netsim
178
+
179
+ aws_fname=${{ env.LAST_COMMIT_SHA }}.tar.gz
180
+ tar -cvzf report.tar.gz report_prom.txt report_table.txt report_metro.txt report_metro_integration.txt logs/ report/ viz/
181
+ if [[ -n "${{ secrets.S3_BUCKET }}" ]]; then
182
+ aws s3 cp ./report.tar.gz s3://${{secrets.S3_REPORT_BUCKET}}/$aws_fname --no-progress
183
+ fi
184
+
185
+ - name : Move report
186
+ if : always()
187
+ run : |
188
+ cp ../chuck/netsim/report.tar.gz ./report.tar.gz
189
+
190
+ - name : Upload report
191
+ if : always()
192
+ uses : actions/upload-artifact@v4
193
+ id : upload-report
194
+ with :
195
+ name : netsim-report-${{ env.LAST_COMMIT_SHA }}
196
+ path : report.tar.gz
197
+ retention-days : 3
198
+ overwrite : true
199
+
200
+ - name : Fail Job if Tests Failed
201
+ if : ${{ failure() && steps.run_tests.outcome == 'failure' }}
202
+ run : exit 1
203
+
204
+ - name : Find Docs Comment
205
+ if : ${{ inputs.pr_number != '' }}
206
+ uses : peter-evans/find-comment@v3
207
+ id : fc
208
+ with :
209
+ issue-number : ${{ inputs.pr_number }}
210
+ comment-author : ' github-actions[bot]'
211
+ body-includes : Netsim report & logs for this PR have been generated
212
+
213
+ - name : Create or Update Docs Comment
214
+ if : ${{ inputs.pr_number != '' && !github.event.pull_request.head.repo.fork }}
215
+ uses : peter-evans/create-or-update-comment@v4
216
+ with :
217
+ issue-number : ${{ inputs.pr_number }}
218
+ comment-id : ${{ steps.fc.outputs.comment-id }}
219
+ body : |
220
+ Netsim report & logs for this PR have been generated and is available at: [LOGS](${{steps.upload-report.outputs.artifact-url}})
221
+ This report will remain available for 3 days.
222
+
223
+ Last updated for commit: ${{ env.LAST_COMMIT_SHA }}
224
+ edit-mode : replace
225
+
226
+ - name : Generate report table
227
+ if : ${{ inputs.pr_number != '' && inputs.report_table}}
228
+ id : generate_report_table
229
+ run : |
230
+ cd ../chuck/netsim
231
+ export NETSIM_REPORT=$(cat report_table.txt)
232
+ echo "NETSIM_REPORT<<EOFMARKER" >> ${GITHUB_OUTPUT}
233
+ echo "${NETSIM_REPORT}" >> ${GITHUB_OUTPUT}
234
+ echo "EOFMARKER" >> ${GITHUB_OUTPUT}
235
+
236
+ - name : Echo Report Table on PR
237
+ uses : peter-evans/create-or-update-comment@v4
238
+ if : ${{ inputs.pr_number != '' && inputs.report_table && !github.event.pull_request.head.repo.fork }}
239
+ with :
240
+ issue-number : ${{ inputs.pr_number }}
241
+ body : |
242
+ `${{ inputs.branch }}.${{ env.LAST_COMMIT_SHA }}`
243
+ Perf report:
244
+ ${{ steps.generate_report_table.outputs.NETSIM_REPORT }}
245
+
246
+ - name : Publish metrics
247
+ if : ${{ inputs.publish_metrics && !github.event.pull_request.head.repo.fork }}
248
+ run : |
249
+ cd ../chuck/netsim
250
+ d=$(cat report_metro.txt)
251
+ metro_data=$(printf "%s\n " "$d")
252
+ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{secrets.METRO_TOKEN}}" --data "$metro_data" ${{secrets.METRO_ENDPOINT}}
253
+ d=$(cat report_metro_integration.txt)
254
+ metro_data=$(printf "%s\n " "$d")
255
+ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{secrets.METRO_TOKEN}}" --data "$metro_data" ${{secrets.METRO_ENDPOINT}}
256
+
257
+ - name : Echo metrics (debug)
258
+ run : |
259
+ cd ../chuck/netsim
260
+ d=$(cat report_metro.txt)
261
+ metro_data=$(printf "%s\n " "$d")
262
+ echo "$metro_data"
263
+ d=$(cat report_metro_integration.txt)
264
+ metro_data=$(printf "%s\n " "$d")
265
+ echo "$metro_data"
266
+
267
+ - name : Cleanup
268
+ run : |
269
+ ./cleanup.sh || true
0 commit comments