From 2cd68167fc22d26491197d8c1808604b0891b3d0 Mon Sep 17 00:00:00 2001 From: DrDoof <8052722+DrDoof@users.noreply.github.com> Date: Wed, 28 Oct 2026 13:05:55 +0100 Subject: [PATCH 1/4] ci: show the size of the build next to main in the job summary The bank growth step only exported the sizes to the environment since the comment that used them was removed, so nothing showed them any more. It now writes a table of the code banks, XSEG, the stack left after the internal RAM is allocated and the web assets, main against the branch, to the job summary, which needs no write permission on the pull request. --- .github/workflows/build.yml | 9 +++------ tools/size_summary.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 tools/size_summary.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d85b74b..a8156b91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: - name: Check that every machine definition can be compiled run: cd branch && make machine_check - name: Make project (4x2/RTL8372) - run: cd branch && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map /tmp/branch.map + run: mkdir -p /tmp/branch /tmp/main && cd branch && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem /tmp/branch/ - name: Make project (8x1/RTL8373) run: cd branch && make CI=1 MACHINE="KP_9000_9XHML_X_V3_1" - name: Make project with the health instrumentation @@ -49,10 +49,7 @@ jobs: run: | ln -s ../branch/toolchain main/toolchain PATH="$(echo "$PWD"/branch/toolchain/sdcc-*/bin):$PATH" - cd main && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map /tmp/main.map + cd main && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem /tmp/main/ - name: Calculate bank growth run: | - sed -rn 's/^([XCD]SEG|(BANK[0-9])).*=\s+([0-9]+)\. bytes.*$/MAIN_\1=\3/p' /tmp/main.map | sort -u >> "$GITHUB_ENV" - sed -rn 's/^([XCD]SEG|(BANK[0-9])).*=\s+([0-9]+)\. bytes.*$/BRANCH_\1=\3/p' /tmp/branch.map | sort -u >> "$GITHUB_ENV" - du -sb main/output/KP_9000_6XHML_X2/html_min | awk '{print "MAIN_WEB="$1}' >> "$GITHUB_ENV" - du -sb branch/output/KP_9000_6XHML_X2/html_min | awk '{print "BRANCH_WEB="$1}' >>"$GITHUB_ENV" + sh branch/tools/size_summary.sh /tmp/main /tmp/branch main/output/KP_9000_6XHML_X2/html_min branch/output/KP_9000_6XHML_X2/html_min >> "$GITHUB_STEP_SUMMARY" diff --git a/tools/size_summary.sh b/tools/size_summary.sh new file mode 100644 index 00000000..289a8606 --- /dev/null +++ b/tools/size_summary.sh @@ -0,0 +1,19 @@ +#!/bin/sh +seg() { + sed -rn "s/^$1[^=]*=\\s+([0-9]+)\\. bytes.*$/\\1/p" "$2/rtlplayground.map" | head -n 1 +} +stack() { + sed -rn 's/.* with ([0-9]+) bytes available.*/\1/p' "$1/rtlplayground.mem" +} +row() { + echo "| $1 | $2 | $3 | $((${3:-0} - ${2:-0})) |" +} +echo "### KP_9000_6XHML_X2" +echo +echo "| | main | branch | change |" +echo "| --- | ---: | ---: | ---: |" +for s in HOME CSEG BANK1 BANK2 BANK3 BANK4 XSEG; do + row "$s" "$(seg $s "$1")" "$(seg $s "$2")" +done +row "stack available" "$(stack "$1")" "$(stack "$2")" +row "web" "$(du -sb "$3" | cut -f1)" "$(du -sb "$4" | cut -f1)" From 0cdf029afd772c58e944806f3876309014427bb8 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 29 Oct 2026 19:47:08 +0100 Subject: [PATCH 2/4] tools: one script for the bank sizes bank_occupancy.sh takes the main and branch build directories as optional arguments and prints a markdown table, so CI calls it instead of a second script. It gains the HOME, BANK4 and stack rows, and reads the web assets from the build directory, where html_min is now. --- .github/workflows/build.yml | 6 ++--- tools/bank_occupancy.sh | 47 ++++++++++++++++++++++--------------- tools/size_summary.sh | 19 --------------- 3 files changed, 31 insertions(+), 41 deletions(-) delete mode 100644 tools/size_summary.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8156b91..7a05764e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: - name: Check that every machine definition can be compiled run: cd branch && make machine_check - name: Make project (4x2/RTL8372) - run: mkdir -p /tmp/branch /tmp/main && cd branch && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem /tmp/branch/ + run: mkdir -p /tmp/branch /tmp/main && cd branch && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp -r output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem output/KP_9000_6XHML_X2/html_min /tmp/branch/ - name: Make project (8x1/RTL8373) run: cd branch && make CI=1 MACHINE="KP_9000_9XHML_X_V3_1" - name: Make project with the health instrumentation @@ -49,7 +49,7 @@ jobs: run: | ln -s ../branch/toolchain main/toolchain PATH="$(echo "$PWD"/branch/toolchain/sdcc-*/bin):$PATH" - cd main && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem /tmp/main/ + cd main && make CI=1 MACHINE="KP_9000_6XHML_X2" && cp -r output/KP_9000_6XHML_X2/rtlplayground.map output/KP_9000_6XHML_X2/rtlplayground.mem output/KP_9000_6XHML_X2/html_min /tmp/main/ - name: Calculate bank growth run: | - sh branch/tools/size_summary.sh /tmp/main /tmp/branch main/output/KP_9000_6XHML_X2/html_min branch/output/KP_9000_6XHML_X2/html_min >> "$GITHUB_STEP_SUMMARY" + bash branch/tools/bank_occupancy.sh KP_9000_6XHML_X2 /tmp/main /tmp/branch >> "$GITHUB_STEP_SUMMARY" diff --git a/tools/bank_occupancy.sh b/tools/bank_occupancy.sh index 8638d390..526cb281 100755 --- a/tools/bank_occupancy.sh +++ b/tools/bank_occupancy.sh @@ -1,31 +1,40 @@ #!/bin/bash MACHINE="$1" -if [[ ! -s output-main/rtlplayground.map ]]; then +MAIN="${2:-output-main}" +BRANCH="${3:-output/$MACHINE}" +if [[ ! -s "$MAIN/rtlplayground.map" ]]; then original_branch=$(git branch --show-current) #trap 'git switch "$original_branch"' EXIT - git switch main && make CI=1 MACHINE="$MACHINE" BUILDDIR=output-main + git switch main && make CI=1 MACHINE="$MACHINE" BUILDDIR="$MAIN" git switch "$original_branch" fi -source <(sed -rn 's/^([XCD]SEG|(BANK[0-9])).*=\s+([0-9]+)\. bytes.*$/main_\1=\3/p' output-main/rtlplayground.map | sort -u) - -main_WEB=$(du -sb output-main/html_min | awk '{print $1}') -if [[ ! -s "output/$MACHINE/rtlplayground.map" ]]; then - make CI=1 MACHINE="$MACHINE" +if [[ ! -s "$BRANCH/rtlplayground.map" ]]; then + make CI=1 MACHINE="$MACHINE" BUILDDIR="$BRANCH" fi -source <(sed -rn 's/^([XCD]SEG|(BANK[0-9])).*=\s+([0-9]+)\. bytes.*$/branch_\1=\3/p' output/"$MACHINE"/rtlplayground.map | sort -u) -branch_WEB=$(du -sb output/html_min | awk '{print $1}') + +seg() { + sed -rn "s/^$1[^=]*=\s+([0-9]+)\. bytes.*$/\1/p" "$2/rtlplayground.map" | head -n 1 +} + +stack() { + sed -rn 's/.* with ([0-9]+) bytes available.*/\1/p' "$1/rtlplayground.mem" +} + +web() { + du -sb "$1/html_min" | awk '{print $1}' +} print_line() { local name=$1 main=$2 branch=$3 - printf '%-20s %-20s %-20s %-20s\n' "$name" "$main" "$branch" "$((branch - main))" + echo "| $name | $main | $branch | $((${branch:-0} - ${main:-0})) |" } -printf '%-20s %-20s %-20s %-20s\n' "segment" "main" "branch" "change" - -print_line "BANK1" "$main_BANK1" "$branch_BANK1" -print_line "BANK2" "$main_BANK2" "$branch_BANK2" -print_line "BANK3" "$main_BANK3" "$branch_BANK3" -print_line "CSEG" "$main_CSEG" "$branch_CSEG" -print_line "DSEG" "$main_DSEG" "$branch_DSEG" -print_line "XSEG" "$main_XSEG" "$branch_XSEG" -print_line "WEB" "$main_WEB" "$branch_WEB" +echo "### $MACHINE" +echo +echo "| segment | main | branch | change |" +echo "| --- | ---: | ---: | ---: |" +for s in HOME CSEG BANK1 BANK2 BANK3 BANK4 DSEG XSEG; do + print_line "$s" "$(seg "$s" "$MAIN")" "$(seg "$s" "$BRANCH")" +done +print_line "stack available" "$(stack "$MAIN")" "$(stack "$BRANCH")" +print_line "WEB" "$(web "$MAIN")" "$(web "$BRANCH")" diff --git a/tools/size_summary.sh b/tools/size_summary.sh deleted file mode 100644 index 289a8606..00000000 --- a/tools/size_summary.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -seg() { - sed -rn "s/^$1[^=]*=\\s+([0-9]+)\\. bytes.*$/\\1/p" "$2/rtlplayground.map" | head -n 1 -} -stack() { - sed -rn 's/.* with ([0-9]+) bytes available.*/\1/p' "$1/rtlplayground.mem" -} -row() { - echo "| $1 | $2 | $3 | $((${3:-0} - ${2:-0})) |" -} -echo "### KP_9000_6XHML_X2" -echo -echo "| | main | branch | change |" -echo "| --- | ---: | ---: | ---: |" -for s in HOME CSEG BANK1 BANK2 BANK3 BANK4 XSEG; do - row "$s" "$(seg $s "$1")" "$(seg $s "$2")" -done -row "stack available" "$(stack "$1")" "$(stack "$2")" -row "web" "$(du -sb "$3" | cut -f1)" "$(du -sb "$4" | cut -f1)" From 49f2a156ee4bde4f79466a9a19709837ff1c9697 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:01:02 +0100 Subject: [PATCH 3/4] ci: drop the write permissions They were added for the step that commented on the pull request. The sizes go to the job summary now, which only needs to read the repository. --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a05764e..0198bb1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,8 +7,6 @@ on: permissions: contents: read - pull-requests: write - issues: write jobs: build: From a557e285a2a5737e7dcbf34a331c15ea72b69514 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:47:31 +0100 Subject: [PATCH 4/4] tools: keep the bank table aligned in a terminal printf pads the cells, so the table lines up on the console and is still a markdown table in the job summary. --- tools/bank_occupancy.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/bank_occupancy.sh b/tools/bank_occupancy.sh index 526cb281..4e895c33 100755 --- a/tools/bank_occupancy.sh +++ b/tools/bank_occupancy.sh @@ -26,13 +26,13 @@ web() { print_line() { local name=$1 main=$2 branch=$3 - echo "| $name | $main | $branch | $((${branch:-0} - ${main:-0})) |" + printf '| %-15s | %7s | %7s | %7s |\n' "$name" "$main" "$branch" "$((${branch:-0} - ${main:-0}))" } echo "### $MACHINE" echo -echo "| segment | main | branch | change |" -echo "| --- | ---: | ---: | ---: |" +printf '| %-15s | %7s | %7s | %7s |\n' "segment" "main" "branch" "change" +echo "| --------------- | ------: | ------: | ------: |" for s in HOME CSEG BANK1 BANK2 BANK3 BANK4 DSEG XSEG; do print_line "$s" "$(seg "$s" "$MAIN")" "$(seg "$s" "$BRANCH")" done