rewrote the python script

the script now checks for project name on every line read from the log
file and appends it to a list named by the project, if the branch is
master then it appends all lines into one list, then it checks if there
is any data in the list and uploads them to the correct tab that matches
the project name or master
This commit is contained in:
2025-11-12 18:42:17 +01:00
parent cdd8b45da8
commit 352b4e57d7

View File

@@ -20,33 +20,71 @@ jobs:
echo "$GOOGLE_SERVICE_ACCOUNT_JSON" > service_account.json
python <<'PYCODE'
import gspread, json, time, subprocess
import gspread, json, subprocess
# credentials
creds = json.load(open("service_account.json"))
gc = gspread.service_account_from_dict(creds)
sh = gc.open_by_key("${{ secrets.SPREADSHEET_ID }}")
v = subprocess.run(['git','rev-parse','--show-toplevel'], capture_output=True).stdout.decode().strip()
print(f"{v}/test_data.log")
with open(f"{v}/test_data.log", "r") as f:
lines = [line.strip() for line in f if line.strip()]
project = lines[0].lower()
worksheet = sh.worksheet(project)
# project name
data = lines[1:]
#blank rows
def writeRowsToSpreadsheet(data_list, worksheet):
existing_rows = len(worksheet.get_all_values())
start_row = existing_rows + 3
# Split data into columns (by spaces)
rows_to_append = [row.split() for row in data]
rows_to_append = [row.split() for row in data_list]
print(f"{rows_to_append}")
for i, row in enumerate(rows_to_append):
worksheet.insert_row(row, start_row + i)
print(f"Uploaded {len(rows_to_append)} rows to '{project}' tab.")
with open(f"{v}/test_data.log", "r") as f:
lines = [line.strip() for line in f if line.strip()]
isMaster = False
project = lines[0].lower()
if project == "master":
isMaster = True
engine_data = []
server_data = []
ui_data = []
master_data = []
for entry in lines:
if not isMaster and entry == "engine":
project = "engine"
elif not isMaster and entry == "server":
project = "server"
elif not isMaster and entry == "ui":
project = "ui"
if project == "engine" and entry != "engine":
engine_data.append(entry)
elif project == "server" and entry != "server":
server_data.append(entry)
elif project == "ui" and entry != "ui":
ui_data.append(entry)
elif project == "master" and entry != "master":
master_data.append(entry)
print("PRINTING FILTERED DATA\n\n")
print(f"engine\n{engine_data}")
print(f"server\n{server_data}")
print(f"ui\n{ui_data}")
print("\n\n\n")
if isMaster and len(master_data) != 0:
worksheet = sh.worksheet("master")
writeRowsToSpreadsheet(master_data, worksheet)
exit(0)
if len(engine_data) != 0:
writeRowsToSpreadsheet(engine_data, sh.worksheet("engine"))
if len(server_data) != 0:
writeRowsToSpreadsheet(server_data, sh.worksheet("server"))
if len(ui_data) != 0:
writeRowsToSpreadsheet(ui_data, sh.worksheet("ui"))
PYCODE