Skip to content

Commit a58c5a3

Browse files
committed
Allow getting board serial number
1 parent baa0ec2 commit a58c5a3

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.yml
2+
**/__pycache__

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ RUN cd /actions-runner && \
3939
# Fix for Fedora not finding libstlink.so.1
4040

4141
RUN pip install PyYAML
42-
COPY register-runner.py /actions-runner
43-
RUN chmod +x /actions-runner/register-runner.py
42+
COPY register_runner.py /actions-runner
43+
RUN chmod +x /actions-runner/register_runner.py
4444

4545
ENV PATH="/actions-runner:${PATH}"
4646

@@ -49,4 +49,4 @@ ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
4949

5050
WORKDIR /actions-runner
5151

52-
ENTRYPOINT [ "/actions-runner/register-runner.py" ]
52+
ENTRYPOINT [ "/actions-runner/register_runner.py" ]

board_serial

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/python3
2+
import os
3+
import sys
4+
5+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
6+
import register_runner
7+
8+
if __name__ == "__main__":
9+
chips = register_runner.get_chips()
10+
if len(sys.argv) != 3:
11+
print("Usage: %s <device>" % sys.argv[0])
12+
print("Available devices:")
13+
for chip in chips:
14+
print(" %s" % chip)
15+
sys.exit(1)
16+
17+
devices = list(filter(lambda x: x["dev_type"] == sys.argv[1], chips))
18+
19+
if len(devices) == 0:
20+
print("Device not found")
21+
sys.exit(1)
22+
23+
device = devices[0]
24+
25+
print(device['serial'])
26+
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/python
1+
#!/bin/python3
22
import os
33
import re
44
import subprocess
@@ -115,7 +115,14 @@ class Config(TypedDict):
115115
serial_map: Dict[str, str]
116116
runner_name: str
117117

118-
def parse_config_file(config_file: str) -> dict:
118+
def parse_config_file(config_file: str = None) -> dict:
119+
if config_file is None:
120+
env_value = os.getenv("CHIPS_FILE_PATH")
121+
if env_value:
122+
config_file = env_value
123+
else:
124+
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "chips.yml")
125+
119126
with open(config_file) as f:
120127
return yaml.safe_load(f)
121128

@@ -138,10 +145,8 @@ def parse_config_file(config_file: str) -> dict:
138145

139146
return config
140147

141-
def main():
142-
config_file_path = os.getenv("CHIPS_FILE_PATH") or "chips.yml"
143-
144-
config = parse_config_file(config_file_path)
148+
def get_chips():
149+
config = parse_config_file()
145150
probe_info = run_command("st-info --probe")
146151
if not probe_info:
147152
print("No output from st-info --probe")
@@ -156,6 +161,11 @@ def main():
156161
if probe["serial"] in config["serial_map"]:
157162
chips[i]["dev_type"] = config["serial_map"][probe["serial"]]
158163

164+
return chips
165+
166+
def main():
167+
chips = get_chips()
168+
159169
print(yaml.dump(chips))
160170

161171
labels = set()

0 commit comments

Comments
 (0)