Skip to content

Commit 42a8729

Browse files
committed
Save output text and post it as comment
1 parent d853f5c commit 42a8729

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

.github/workflows/tests.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252

5353
xray-tests:
5454
runs-on: ubuntu-24.04
55+
permissions:
56+
pull-requests: write
5557
steps:
5658
- name: Checkout
5759
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
@@ -67,9 +69,16 @@ jobs:
6769
pipenv install
6870
- name: Execute xray
6971
working-directory: xray
70-
run: pipenv run python run.py --wg native --ascii --save-chart
72+
run: pipenv run python run.py --wg native --ascii --save-output
7173
- name: Upload results
7274
uses: actions/upload-artifact@v4
7375
with:
7476
name: xray-results
7577
path: xray/results/*.png
78+
- name: Post results
79+
uses: mshick/add-pr-comment@v2
80+
with:
81+
message: |
82+
**Hello**
83+
🌏
84+
!

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
**/*.csv
66
**/*.pcap
7-
**/*.png
87
**/*.sk
98
**/*.pk
109
**/__pycache__

xray/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
!xray_setup.png
1+
results/

xray/analyze.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import mpl_ascii
99

1010

11-
def analyze(csv_path, pcap_path, count, test_type, png_path, ascii):
12-
Analyzer(csv_path, pcap_path, count, test_type, png_path, ascii)
11+
def analyze(csv_path, test_path, count, test_type, ascii, save_output):
12+
Analyzer(csv_path, test_path, count, test_type, ascii, save_output)
1313

1414

1515
class CsvData:
@@ -63,10 +63,10 @@ def __init__(self, pcap_path, test_type):
6363

6464

6565
class Analyzer:
66-
def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
66+
def __init__(self, csv_name, test_path, count, test_type, ascii, save_output):
6767
self.count = count
6868
self.csv_data = CsvData(csv_name)
69-
self.pcap_data = PcapData(pcap_name, test_type)
69+
self.pcap_data = PcapData(test_path + ".pcap", test_type)
7070

7171
graphs = [
7272
self.ordering_pie_chart,
@@ -86,12 +86,12 @@ def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
8686
fn(ax[i, 1])
8787

8888
plt.show()
89-
if png_path:
90-
plt.savefig(png_path)
89+
if save_output:
90+
plt.savefig(test_path + ".png")
9191

9292
if ascii:
93-
mpl_ascii.AXES_WIDTH=100
94-
mpl_ascii.AXES_HEIGHT=40
93+
mpl_ascii.AXES_WIDTH = 80
94+
mpl_ascii.AXES_HEIGHT = 25
9595
mpl.use("module://mpl_ascii")
9696
graphs = [
9797
self.packet_ordering,
@@ -102,12 +102,14 @@ def __init__(self, csv_name, pcap_name, count, test_type, png_path, ascii):
102102
rows = len(graphs)
103103

104104
fig, ax = plt.subplots(nrows=rows)
105-
# fig.tight_layout(pad=)
105+
fig.tight_layout(pad=2)
106106

107107
for i, fn in enumerate(graphs):
108108
fn(ax[i])
109109

110110
plt.show()
111+
if save_output:
112+
plt.savefig(test_path + ".txt")
111113

112114
def ordering_pie_chart(self, ax):
113115
in_order = count_ordered(self.csv_data.indices, self.count)

xray/run.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ def get_csv_name(wg, test_type, count):
2121
return f"results/xray_metrics_{wg.lower()}_{test_type}_{count}.csv"
2222

2323

24-
def get_pcap_name(wg, test_type, count):
25-
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}.pcap"
26-
27-
28-
def get_png_name(wg, test_type, count):
29-
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}.png"
24+
def get_test_path(wg, test_type, count):
25+
return f"results/{WG_IFC_NAME}_{wg.lower()}_{test_type}_{count}"
3026

3127

3228
class Wireguard(Enum):
@@ -108,7 +104,7 @@ def main():
108104
parser.add_argument("--count")
109105
parser.add_argument("--nobuild-neptun", action="store_true")
110106
parser.add_argument("--nobuild-xray", action="store_true")
111-
parser.add_argument("--save-chart", action="store_true")
107+
parser.add_argument("--save-output", action="store_true")
112108
parser.add_argument("--ascii", action="store_true")
113109
args = parser.parse_args()
114110

@@ -122,18 +118,18 @@ def main():
122118
assert count > 0, f"Count must be at least one, but got {count}"
123119
build_neptun = args.nobuild_neptun is False
124120
build_xray = args.nobuild_xray is False
125-
png_path = get_png_name(wg.name, test_type, count) if args.save_chart else None
126121

127122
Path("results/").mkdir(parents=True, exist_ok=True)
128123
try:
129124
os.remove(get_csv_name(wg.name, test_type, count))
130-
os.remove(get_pcap_name(wg.name, test_type, count))
131-
os.remove(get_png_name(wg.name, test_type, count))
125+
os.remove(get_test_path(wg.name, test_type, count) + ".pcap")
126+
os.remove(get_test_path(wg.name, test_type, count) + ".png")
127+
os.remove(get_test_path(wg.name, test_type, count) + ".txt")
132128
except: # noqa: E722
133129
pass
134130

135131
setup_wireguard(wg, build_neptun)
136-
tcpdump = start_tcpdump(get_pcap_name(wg.name, test_type, count))
132+
tcpdump = start_tcpdump(get_test_path(wg.name, test_type, count) + ".pcap")
137133

138134
succeeded = True
139135
try:
@@ -148,11 +144,11 @@ def main():
148144
if succeeded:
149145
analyze(
150146
get_csv_name(wg.name, test_type, count),
151-
get_pcap_name(wg.name, test_type, count),
147+
get_test_path(wg.name, test_type, count),
152148
count,
153149
test_type,
154-
png_path,
155-
args.ascii
150+
args.ascii,
151+
args.save_output
156152
)
157153

158154

0 commit comments

Comments
 (0)