Skip to content

Commit 33c7c06

Browse files
tyethclaude
andcommitted
build: refuse an empty package folder list, and validate its characters
Removing the literal quotes changed one failure mode for the worse. If the gawk matches nothing, the prefix is empty; build-tools splits on ", " and matches with startswith(), and "".startswith("") is True, so every folder becomes a package (module_name came out as 'docs'). Previously the empty value reached an unquoted ${{ }} and click failed on the missing argument, which at least stopped the build. Fail loudly instead. The character check covers the part quoting cannot: ${{ }} splices the value into the run: block as text before any shell parses it, so a folder name containing a quote or backtick escapes the quotes added around the expansion. Restricting the list to what a module name can contain closes that, rather than relying on the quotes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 764b924 commit 33c7c06

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,27 @@ jobs:
3535
- name: Package Folder Prefix For circuitpython-build-tools (Community Bundle Specific)
3636
id: pkg-folder
3737
run: |
38-
echo prefix=$(
38+
prefix=$(
3939
ls -RUx |
4040
gawk -F '\n' '{ match($1, /(drivers|helpers)\/(.+)\/(.+)\:/, arr) ; if (length(arr[0]) > 0 && match(arr[3], arr[2]) > 0) printf "%s, ", arr[3] }' |
4141
gawk '{ print substr($0, 1, length($0) - 2) }'
42-
) >> $GITHUB_OUTPUT
42+
)
43+
# An empty list is never correct: build-tools splits on ", " and matches
44+
# with startswith(), and "".startswith("") is True, so an empty prefix
45+
# would silently make every folder -- docs/, tests/, ci/ -- a package.
46+
if [ -z "$prefix" ]; then
47+
echo "::error::no package folders matched under libraries/; refusing to build an empty bundle"
48+
exit 1
49+
fi
50+
# ${{ }} splices this into the later run: block as text, before any shell
51+
# sees it, so the quotes there cannot contain a folder name carrying a
52+
# quote or a backtick. Allow only what a module name can be.
53+
case "$prefix" in
54+
*[!A-Za-z0-9_, -]*)
55+
echo "::error::unexpected character in package folder list: $prefix"
56+
exit 1 ;;
57+
esac
58+
echo "prefix=$prefix" >> "$GITHUB_OUTPUT"
4359
- name: Build assets
4460
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location libraries --library_depth 2 --package_folder_prefix "${{ steps.pkg-folder.outputs.prefix }}"
4561
- name: Upload Release Assets

build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ gawk -F '\n' '{ match($1, /(drivers|helpers)\/(.+)\/(.+)\:/, arr) ; if (length(a
3232
gawk '{ print substr($0, 1, length($0) - 2) }'
3333
)
3434

35+
if [ -z "$P" ]; then
36+
echo "error: no package folders matched under libraries/; refusing to build an empty bundle" >&2
37+
exit 1
38+
fi
39+
3540
circuitpython-build-bundles --filename_prefix circuitpython-community-bundle --library_location libraries --library_depth 2 --package_folder_prefix "$P"

0 commit comments

Comments
 (0)