Skip to content

Commit 3a3fc46

Browse files
authoredFeb 20, 2023
feat: netsim CI (#135)
1 parent 2991cbb commit 3a3fc46

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
 

‎.github/workflows/netsim.yml

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: netsim-CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
issue_comment:
8+
types: [created, edited, deleted]
9+
10+
env:
11+
RUST_BACKTRACE: 1
12+
RUSTFLAGS: -Dwarnings
13+
MSRV: "1.63"
14+
15+
jobs:
16+
netsim:
17+
name: Run network simulations/benchmarks
18+
if: >-
19+
(github.event_name == 'issue_comment' &&
20+
github.event.issue.pull_request &&
21+
github.event.comment.body == '/netsim') || github.event_name != 'issue_comment'
22+
runs-on: [self-hosted, linux, X64]
23+
permissions:
24+
issues: write
25+
pull-requests: write
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@master
29+
with:
30+
submodules: recursive
31+
32+
- name: Install rust stable
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
override: true
37+
38+
- name: Build sendme
39+
run: |
40+
cargo build --release
41+
42+
- name: Fetch and build chuck
43+
run: |
44+
git clone https://github.com/n0-computer/chuck.git
45+
cd chuck
46+
cargo build --release
47+
48+
- name: Install netsim deps
49+
run: |
50+
cd chuck/netsim
51+
sudo apt update
52+
./setup.sh
53+
54+
- name: Copy binaries to right location
55+
run: |
56+
cp target/release/sendme chuck/netsim/bins/sendme
57+
cp chuck/target/release/chuck chuck/netsim/bins/chuck
58+
59+
- name: Run tests
60+
run: |
61+
cd chuck/netsim
62+
sudo kill -9 $(pgrep ovs)
63+
sudo mn --clean
64+
sudo python3 main.py sims/standard
65+
66+
- name: Generate report
67+
id: generate_report
68+
run: |
69+
cd chuck/netsim
70+
python3 reports_csv.py > report.txt
71+
export NETSIM_REPORT=$(cat report.txt)
72+
echo "NETSIM_REPORT<<EOFMARKER" >> ${GITHUB_OUTPUT}
73+
echo "${NETSIM_REPORT}" >> ${GITHUB_OUTPUT}
74+
echo "EOFMARKER" >> ${GITHUB_OUTPUT}
75+
76+
- name: Setup Environment (PR)
77+
if: ${{ github.event_name == 'pull_request' }}
78+
shell: bash
79+
run: |
80+
echo "LAST_COMMIT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})" >> ${GITHUB_ENV}
81+
- name: Setup Environment (Push)
82+
if: ${{ github.event_name == 'push' }}
83+
shell: bash
84+
run: |
85+
echo "LAST_COMMIT_SHA=$(git rev-parse --short ${GITHUB_SHA})" >> ${GITHUB_ENV}
86+
87+
- name: Respond Issue
88+
uses: peter-evans/create-or-update-comment@v2
89+
if: github.event_name == 'issue_comment'
90+
with:
91+
issue-number: ${{ github.event.issue.number }}
92+
body: |
93+
body: |
94+
`${{ github.head_ref }}.${{ env.LAST_COMMIT_SHA }}`
95+
<details>
96+
<summary>Perf report</summary>
97+
98+
```json
99+
100+
${{ steps.generate_report.outputs.NETSIM_REPORT }}
101+
102+
```
103+
</details>
104+
105+
- name: Respond PR
106+
uses: peter-evans/create-or-update-comment@v2
107+
if: github.event.pull_request
108+
with:
109+
issue-number: ${{ github.event.pull_request.number }}
110+
body: |
111+
`${{ github.head_ref }}.${{ env.LAST_COMMIT_SHA }}`
112+
<details>
113+
<summary>Perf report</summary>
114+
115+
```json
116+
117+
${{ steps.generate_report.outputs.NETSIM_REPORT }}
118+
119+
```
120+
</details>
121+
122+
- name: Dump report
123+
run: |
124+
export AWS_ACCESS_KEY_ID=${{secrets.S3_ACCESS_KEY_ID}}
125+
export AWS_SECRET_ACCESS_KEY=${{secrets.S3_ACCESS_KEY}}
126+
export AWS_DEFAULT_REGION=us-west-2
127+
128+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
129+
unzip -q awscliv2.zip
130+
sudo ./aws/install --update
131+
132+
cd chuck/netsim
133+
python3 reports_csv.py --prom --commit ${{ env.LAST_COMMIT_SHA }} > report_prom.txt
134+
135+
tar cvzf report.tar.gz report_prom.txt report.txt logs/ report/
136+
aws s3 cp ./report.tar.gz s3://${{secrets.S3_REPORT_BUCKET}}/${{ env.LAST_COMMIT_SHA }}.tar.gz --no-progress
137+
138+
instance=$(echo "${{ github.head_ref }}" | tr -c '[:alnum:]' '_')
139+
d=$(cat report_prom.txt)
140+
prom_data=$(printf "%s\n " "$d")
141+
curl -X POST -H "Content-Type: text/plain" --data "$prom_data" ${{secrets.PROM_ENDPOINT}}/metrics/job/netsim/instance/${instance}
142+

0 commit comments

Comments
 (0)
Please sign in to comment.