This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 9dab957d7 ci: automate HW CI status updates
9dab957d7 is described below

commit 9dab957d73bbabd5c7d594fbc01983dcae42a33b
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Mon May 4 15:55:12 2026 +0200

    ci: automate HW CI status updates
    
    This adds script and workflow to keep hardware test statuses
    up to date. It relies on HTML comment tags within the README to
    identify and replace the badge section during each run
---
 .github/scripts/update_badges.py          | 103 ++++++++++++++++++++++++++++++
 .github/workflows/update_hw_ci_badges.yml |  54 ++++++++++++++++
 README.md                                 |   2 +
 3 files changed, 159 insertions(+)

diff --git a/.github/scripts/update_badges.py b/.github/scripts/update_badges.py
new file mode 100644
index 000000000..0df1aa65e
--- /dev/null
+++ b/.github/scripts/update_badges.py
@@ -0,0 +1,103 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+import urllib.request
+import urllib.error
+import json
+import re
+
+URL = "https://static.codecoup.pl/mynewt/run/latest/status.json";
+BASE_URL = "https://static.codecoup.pl/mynewt/run/latest";
+README_PATH = "README.md"
+START_MARKER = "<!--HW_CI_START-->"
+END_MARKER = "<!--HW_CI_END-->"
+
+
+def _get_results_from_url(url):
+    try:
+        with urllib.request.urlopen(url) as response:
+            return json.loads(response.read().decode("utf-8"))
+    except urllib.error.HTTPError as e:
+        print(f"Connection error: {e}")
+
+
+def _generate_markdown(results):
+    md = [f"## HW CI status"]
+
+    for test_name in sorted(results.keys()):
+        md.append(f"![]({BASE_URL}/{test_name}.svg)")
+
+    md.append("\n<details>")
+    md.append("<summary>Toggle for more informations</summary>\n")
+
+    for test_name in sorted(results.keys()):
+        boards = results[test_name]
+        valid_boards = sorted([b for b, status in boards.items() if status in 
("passing", "failing")])
+
+        if valid_boards:
+            md.append(f"## {test_name}")
+            for board in valid_boards:
+                md.append(f"![]({BASE_URL}/{test_name}/{board}.svg)")
+            md.append("")
+
+    md.append("</details>")
+
+    return "\n".join(md)
+
+
+def _update_readme(new_md_block):
+    try:
+        with open(README_PATH, "r", encoding="utf-8") as f:
+            content = f.read()
+
+        pattern = re.compile(rf"{START_MARKER}(?P<HW_CI>.*?){END_MARKER}", 
re.DOTALL)
+
+        m = pattern.search(content)
+
+        if not m:
+            print(f"Markers {START_MARKER} and {END_MARKER} not found in 
README.md")
+            return
+
+        old_md_block = m.group("HW_CI").strip()
+
+        if old_md_block == new_md_block:
+            print(f"No differences in HW CI status, skipping update.")
+        else:
+            new_content = 
pattern.sub(rf"{START_MARKER}\n{new_md_block}\n{END_MARKER}", content)
+            with open(README_PATH, "w", encoding="utf-8") as f:
+                f.write(new_content)
+            print("README.md content updated successfully")
+
+    except Exception as e:
+        print(f"Error occured while updating README: {e}")
+
+
+def main():
+    results = _get_results_from_url(URL)
+
+    if not results:
+        print("Data could not be requested or JSON is empty")
+        return
+
+    new_md_block = _generate_markdown(results)
+    _update_readme(new_md_block)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/.github/workflows/update_hw_ci_badges.yml 
b/.github/workflows/update_hw_ci_badges.yml
new file mode 100644
index 000000000..c4a5a2ef3
--- /dev/null
+++ b/.github/workflows/update_hw_ci_badges.yml
@@ -0,0 +1,54 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+name: Update HW CI Badges
+
+on:
+  schedule:
+    - cron: '0 5 * * *'
+
+jobs:
+  update-badges:
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v4
+
+      - uses: actions/setup-python@v6
+        with:
+          python-version: '3.x'
+
+      - name: Fetch and Update Badges
+        run: python .github/scripts/update_badges.py
+
+      - name: Create Pull Request
+        uses: peter-evans/create-pull-request@v6
+        with:
+          author: Mynewt Bot <[email protected]>
+          token: ${{ secrets.GITHUB_TOKEN }}
+          commit-message: |
+            Update HW CI badges in README
+          branch: update-hw-ci-badges
+          title: "Update HW CI status badges"
+          body: |
+            Update of the HW CI status badges in README.md
+            - Fetched the latest test results from the Codecoup hardware lab
+            - Auto-generated by [create-pull-request][1]
+
+            [1]: https://github.com/peter-evans/create-pull-request
diff --git a/README.md b/README.md
index 7a62afa6a..0368bf5a8 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,7 @@
   <img 
src="https://github.com/apache/mynewt-core/actions/workflows/newt_test_all.yml/badge.svg";>
 <a/>
 
+<!--HW_CI_START-->
 ## HW CI status
 ![](https://static.codecoup.pl/mynewt/run/latest/clockdrift.svg)
 ![](https://static.codecoup.pl/mynewt/run/latest/coremark.svg)
@@ -187,6 +188,7 @@
 ![](https://static.codecoup.pl/mynewt/run/latest/watchdog/reel_board.svg)
 
 </details>
+<!--HW_CI_END-->
 
 ## Overview
 

Reply via email to