Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/scripts/xdos_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Composes the UST format verification report of one firmware as markdown.

python3 xdos_report.py <fw_type> <project_dir> <build_dir> <findings.txt> <tests.txt>

Written for xdos_check.yml: the report is shown in the run summary and, for a release, is
appended to the release description, below what the release workflow writes there itself.
"""

import re
import subprocess
import sys
from importlib.metadata import version
from pathlib import Path

from ust_format_checker.platformio import SCENARIO
from ust_format_checker.requirements import load_requirements

ANSI = re.compile(r"\x1b\[[0-9;]*m")


def read(path: Path) -> str:
return ANSI.sub("", path.read_text(encoding="utf-8", errors="replace")).strip() if path.exists() else ""


def identity(capture: str) -> tuple[str, str, str, str]:
"""(device, version, commit, build type) as the firmware printed them in $DOS."""
for line in capture.splitlines():
fields = line.split(",")
if fields[0] == "$DOS" and len(fields) >= 6:
return fields[1], fields[2], fields[4], fields[5]
return ("unknown",) * 4


def last_line(text: str) -> str:
return text.splitlines()[-1].strip("= ") if text else ""


def main() -> int:
fw_type = sys.argv[1]
project, build_dir, findings_path, tests_path = (Path(value) for value in sys.argv[2:6])

findings = read(findings_path)
device, fw_version, commit, build_type = identity(read(build_dir / "xdos" / "capture.txt"))
requirements = load_requirements()
scenario = re.search(r"^name:\s*(\S+)", read(project / SCENARIO), re.M)

counts = re.search(r"(\d+) error, (\d+) warning, (\d+) info", last_line(findings))
if counts:
errors, warnings, infos = (int(number) for number in counts.groups())
passed = errors == 0 and warnings == 0
result = (f"**Result: {'PASS' if passed else 'FAIL'}** ({errors} errors, {warnings} warnings, "
f"{infos} informational notes)")
detail = "\n".join(findings.splitlines()[:-1]).strip()
blocking = errors + warnings
heading = (f"{blocking} blocking, {infos} informational" if blocking
else f"{infos} informational notes, none of them blocks")
else:
# the checker did not get as far as a verdict (no simulator, broken board model, ...)
passed = False
result = "**Result: NOT VERIFIED** (the check did not run to the end)"
detail, heading = findings, "output of the check"

matrix = subprocess.run(
[sys.executable, "-m", "ust_format_checker.matrix", "--standalone"],
check=True, capture_output=True, text=True,
).stdout.strip()

lines = [
f"# UST format verification: {fw_type} {fw_version}",
"",
result,
"",
"| Item | Value |",
"|---|---|",
f"| Firmware | `{fw_type}`, device `{device}` |",
f"| Version | `{fw_version}` ({build_type} build) |",
f"| Commit | `{commit}` |",
f"| Format | [version {requirements.format_version}]({requirements.version_url}) |",
f"| Checker | `ust-format-checker` {version('ust-format-checker')}, strict mode (warnings block the release) |",
"| Method | The released binary is run in the simavr simulator against the board model "
f"`xdos/board.yaml`, scenario `{scenario.group(1) if scenario else 'default'}` |",
f"| Device tests | {last_line(read(tests_path)) or 'none'} |",
"",
"The run is a simulation. Device identifiers in it are placeholders of the board model, "
"not those of a real detector.",
"",
"## Findings",
"",
]
if detail:
# open when something blocks, folded away when there are only notes
lines += [f"<details{'' if passed else ' open'}><summary>{heading}</summary>", "",
"```text", detail, "```", "", "</details>", ""]
else:
lines += ["None.", ""]
lines += [matrix, ""]
sys.stdout.write("\n".join(lines))
return 0


if __name__ == "__main__":
sys.exit(main())
24 changes: 23 additions & 1 deletion .github/workflows/build_fw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Build firmware

on:
push:
branches:
- AIRDOS03B
paths:
- 'fw/**'
- '.github/workflows/*.yml'
Expand All @@ -20,6 +22,12 @@ on:
build_type:
required: false
type: string

# One run per branch or pull request at a time
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
load-matrix:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -143,10 +151,23 @@ jobs:
root
retention-days: 1

# reused in other workflows
- name: Store ELF
uses: actions/upload-artifact@v4
with:
name: elf_${{ matrix.type }}_${{ matrix.name }}
path: fw/${{ matrix.type }}/.pio/build/${{ matrix.env }}/firmware.elf
retention-days: 1
if-no-files-found: error

format-check:
needs: [build]
uses: ./.github/workflows/xdos_check.yml

commit:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
needs: [build]
needs: [build, format-check]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -161,6 +182,7 @@ jobs:
- name: Download a Build Artifact
uses: actions/download-artifact@v4
with:
pattern: fw_*
path: 'fw/artifacts/'

- name: Update git hash
Expand Down
39 changes: 32 additions & 7 deletions .github/workflows/create_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
name: fw_${{ matrix.type }}_${{ matrix.name }}
path: artifact

# only firmware with a format check has one (see xdos_check.yml)
- name: Download format verification report
uses: actions/download-artifact@v4
with:
pattern: xdos-report-${{ matrix.type }}
merge-multiple: true
path: report

- name: Gen release name
id: gen_release_name
env:
Expand Down Expand Up @@ -72,18 +80,35 @@ jobs:
echo "tagname=${FW_TYPE}-${VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT

- name: Release notes
env:
TAGNAME: ${{ steps.gen_release_name.outputs.tagname }}
VERSION: ${{ steps.gen_release_name.outputs.version }}
run: |
{
echo "Pre-release (BETA) of firmware \`${{ matrix.type }}\` (\`${{ matrix.name }}\`)"
echo
echo "* version: \`${VERSION}\`"
echo "* PlatformIO env: \`${{ matrix.env }}\`"
echo "* commit: ${{ github.sha }}"
if [ -f report/report.md ]; then
echo
cat report/report.md
fi
} > release-notes.md
if [ -f report/report.md ]; then
cp report/report.md "${TAGNAME}-ust-format-report.md"
fi

- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.gen_release_name.outputs.tagname }}
target_commitish: ${{ github.sha }}
name: BETA ${{ steps.gen_release_name.outputs.tagname }}
body: |
Pre-release (BETA) of firmware `${{ matrix.type }}` (`${{ matrix.name }}`)

* version: `${{ steps.gen_release_name.outputs.version }}`
* PlatformIO env: `${{ matrix.env }}`
* commit: ${{ github.sha }}
body_path: release-notes.md
draft: false
prerelease: true
files: artifact/fw/build/fw_${{ matrix.type }}_${{ matrix.name }}.hex
files: |
artifact/fw/build/fw_${{ matrix.type }}_${{ matrix.name }}.hex
${{ steps.gen_release_name.outputs.tagname }}-ust-format-report.md
39 changes: 32 additions & 7 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
name: fw_${{ matrix.type }}_${{ matrix.name }}
path: artifact

# only firmware with a format check has one (see xdos_check.yml)
- name: Download format verification report
uses: actions/download-artifact@v4
with:
pattern: xdos-report-${{ matrix.type }}
merge-multiple: true
path: report

- name: Gen release name
id: gen_release_name
env:
Expand Down Expand Up @@ -72,18 +80,35 @@ jobs:
echo "tagname=${FW_TYPE}-${VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT

- name: Release notes
env:
TAGNAME: ${{ steps.gen_release_name.outputs.tagname }}
VERSION: ${{ steps.gen_release_name.outputs.version }}
run: |
{
echo "Release of firmware \`${{ matrix.type }}\` (\`${{ matrix.name }}\`)"
echo
echo "* version: \`${VERSION}\`"
echo "* PlatformIO env: \`${{ matrix.env }}\`"
echo "* commit: ${{ github.sha }}"
if [ -f report/report.md ]; then
echo
cat report/report.md
fi
} > release-notes.md
if [ -f report/report.md ]; then
cp report/report.md "${TAGNAME}-ust-format-report.md"
fi

- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.gen_release_name.outputs.tagname }}
target_commitish: ${{ github.sha }}
name: Release ${{ steps.gen_release_name.outputs.tagname }}
body: |
Release of firmware `${{ matrix.type }}` (`${{ matrix.name }}`)

* version: `${{ steps.gen_release_name.outputs.version }}`
* PlatformIO env: `${{ matrix.env }}`
* commit: ${{ github.sha }}
body_path: release-notes.md
draft: false
prerelease: false
files: artifact/fw/build/fw_${{ matrix.type }}_${{ matrix.name }}.hex
files: |
artifact/fw/build/fw_${{ matrix.type }}_${{ matrix.name }}.hex
${{ steps.gen_release_name.outputs.tagname }}-ust-format-report.md
Loading