Skip to content

Commit ed950ee

Browse files
committed
test 2.1
1 parent da7a0c8 commit ed950ee

3 files changed

Lines changed: 53 additions & 51 deletions

File tree

.github/workflows/daemon_version_check.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,37 @@ jobs:
3030
python -m pip install --upgrade pip
3131
pip install -r requirements.txt
3232
33+
- name: Make deamons.sh executable
34+
run: chmod +x deamons.sh
35+
3336
- name: Extract daemon versions
3437
run: |
35-
python main.py --extract-daemon-versions
38+
# Load the latest export versions
39+
python -c "import json; f=open('data/json/latest_export_versions.json'); print(json.dumps(json.load(f)))" > latest_exports.json
40+
41+
# Iterate over each binary in the latest export versions
42+
cat latest_exports.json | jq -r '.files[].url' | while read -r url; do
43+
# Download the binary
44+
wget "$url" -O binary_file
45+
46+
# Run the binary with deamons.sh to extract the daemon version
47+
DAEMON_VERSION=$(./deamons.sh binary_file)
48+
49+
# Update the JSON with the daemon version
50+
jq --arg url "$url" --arg daemon_version "$DAEMON_VERSION" '.files[] | select(.url == $url) | .daemon_version = $daemon_version' latest_exports.json > tmp.json && mv tmp.json latest_exports.json
51+
done
52+
53+
# Save the updated JSON back to the file
54+
mv latest_exports.json data/json/latest_export_versions.json
3655
3756
- name: Commit and push changes
3857
run: |
39-
git config --local user.email "action@github.com"
40-
git config --local user.name "GitHub Action"
41-
git add .
58+
git add data/json/latest_export_versions.json
4259
if git diff --staged --quiet; then
4360
echo "No changes to commit"
4461
else
62+
git config --local user.email "action@github.com"
63+
git config --local user.name "GitHub Action"
4564
git commit -m "[Auto] Update daemon versions - $(date)"
4665
git push
47-
fi
66+
fi

deamons.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# This script extracts the daemon version from a binary passed as an argument.
4+
# Usage: ./deamons.sh <binary_path>
5+
6+
if [ "$#" -ne 1 ]; then
7+
echo "Usage: $0 <binary_path>"
8+
exit 1
9+
fi
10+
11+
BINARY_PATH=$1
12+
13+
if [ ! -x "$BINARY_PATH" ]; then
14+
echo "Error: $BINARY_PATH is not executable or does not exist."
15+
exit 1
16+
fi
17+
18+
# Run the binary with --version and extract the daemon version using regex
19+
VERSION_OUTPUT=$($BINARY_PATH --version 2>&1)
20+
DAEMON_VERSION=$(echo "$VERSION_OUTPUT" | grep -oP '\d+\.\d+\.\d+')
21+
22+
if [ -z "$DAEMON_VERSION" ]; then
23+
echo "Error: Could not extract daemon version."
24+
exit 1
25+
fi
26+
27+
# Output the daemon version
28+
echo "$DAEMON_VERSION"

main.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import requests
55
import time
6-
import subprocess
76
from typing import List, Dict, Any
87
# Removed custom zfill import as Python strings have a built-in zfill method
98

@@ -263,38 +262,6 @@ def get_latest_version(data: List[Dict[str, Any]]) -> Dict[str, Any]:
263262
sorted_data = sorted(numerical_only, key=lambda x: list(map(int, re.findall(r'\d+', x["version"]))))
264263
return sorted_data[-1] if sorted_data else {"version": None, "files": []}
265264

266-
def extract_daemon_version(binary_path: str) -> str:
267-
"""Run the binary with --version and extract the daemon version using regex."""
268-
try:
269-
result = subprocess.run([binary_path, "--version"], capture_output=True, text=True, check=True)
270-
version_output = result.stdout.strip()
271-
match = re.search(r'version\s+(\d+\.\d+\.\d+)', version_output, re.IGNORECASE)
272-
if match:
273-
return match.group(1)
274-
else:
275-
print(f"No version found in output: {version_output}")
276-
return "unknown"
277-
except subprocess.CalledProcessError as e:
278-
print(f"Error running binary {binary_path}: {e}")
279-
return "error"
280-
281-
def update_latest_export_with_daemon():
282-
"""Update the latest export list with daemon versions."""
283-
try:
284-
with open(LE_VERSIONS, "r") as file:
285-
latest_export = json.load(file)
286-
287-
for entry in latest_export.get("files", []):
288-
binary_path = os.path.join(CACHE_EXPORT_DIR, entry["file_name"])
289-
daemon_version = extract_daemon_version(binary_path)
290-
entry["daemon_version"] = daemon_version
291-
292-
with open(LE_VERSIONS, "w") as file:
293-
json.dump(latest_export, file, indent=4)
294-
295-
print("Updated latest export list with daemon versions.")
296-
except Exception as e:
297-
print(f"Failed to update daemon versions: {e}")
298265

299266
# development time code - create directories and initialize files
300267
try:
@@ -425,16 +392,4 @@ def update_latest_export_with_daemon():
425392

426393
except Exception as e:
427394
print(f"Error building final data: {e}")
428-
exit(1)
429-
430-
if __name__ == "__main__":
431-
import argparse
432-
433-
parser = argparse.ArgumentParser()
434-
parser.add_argument("--extract-daemon-versions", action="store_true", help="Extract daemon versions for the latest export list.")
435-
args = parser.parse_args()
436-
437-
if args.extract_daemon_versions:
438-
update_latest_export_with_daemon()
439-
else:
440-
pass
395+
exit(1)

0 commit comments

Comments
 (0)