Skip to content

Commit

Permalink
coucou
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Oct 11, 2023
1 parent 95a4323 commit 52795c0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/_build_nanos_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ jobs:
python3 scripts/output_scripts/convert.py --input_file build_nanos.json --output_file out.md --key build
cat out.md >> $GITHUB_STEP_SUMMARY
- name: Convert to markdown
run: |
python3 scripts/output_scripts/slack.py --input_file build_nanos.json --output_file slack.json --key build --devices nanos
- name: Send custom JSON data to Slack workflow
if: always()
id: slack
uses: slackapi/[email protected]
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload-file-path: build_nanos.json
payload-file-path: slack.json
#payload: |
# {
# "key": "value",
Expand Down
74 changes: 74 additions & 0 deletions scripts/output_scripts/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import json
from argparse import ArgumentParser
from pathlib import Path

def count_status(json_list, key):
success_count = 0
fail_count = 0
total_count = 0
fail_list = {}

# Iterate over each dictionary in the list
for json_data in json_list:
app_data = json_data.get(key, {})
app_name = json_data.get("name", {})

for build_data in app_data.values():
if isinstance(build_data, dict): # nested structure
variant, status = build_data.popitem()
total_count += 1
if status == "Success":
success_count += 1
elif status == "Fail":
fail_count += 1
fail_list[app_name] = variant
else: # direct structure
total_count += 1
if build_data == "Success":
success_count += 1
elif build_data == "Fail":
fail_count += 1

return success_count, fail_count, total_count, fail_list


if __name__ == "__main__":
parser = ArgumentParser()

parser.add_argument("--input_file", required=True, type=Path)
parser.add_argument("--output_file", required=False, type=Path)
parser.add_argument("--key", required=False, type=str, default="build")
parser.add_argument("--devices", required=False, type=str)

args = parser.parse_args()


with open(args.input_file) as json_file:
json_list = json.load(json_file)

success_count, fail_count, total_count, fail_list = count_status(json_list, args.key)

title = f"{args.key}"

if args.devices:
title += f" on {args.devices}"


if fail_count == 0:
status = f":large_green_circle: Success for {total_count} apps"
else:
status = f":red-cross: Success for {success_count} / {total_count} apps"
fail_status = "Failed for:\n"
for app_name, variants in fail_list.items():
fail_status += f"\t{app_name} : {variants}\n"
status_detail = f"{fail_status}"

slack_json = {}
slack_json["title"] = title
slack_json["status"] = status
slack_json["status_detail"] = status_detail

if args.output_file:
with open(args.output_file, 'w') as f:
json.dump(slack_json, f, indent=1)

0 comments on commit 52795c0

Please sign in to comment.