diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 32210d7..e9bf063 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,19 +1,19 @@ name: Build CI -on: [pull_request, push] +on: [pull_request, push, workflow_dispatch] jobs: test: runs-on: ubuntu-latest steps: - name: Set up Python 3 - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: 3.x - name: Versions run: | python3 --version - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 with: submodules: true - name: Fetch correct submodule shas diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 008f440..bb833aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,20 +10,18 @@ jobs: steps: - name: Translate Repo Name For Build Tools filename_prefix id: repo-name + env: + REPO: ${{ github.repository }} run: | - echo "repo-name=$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - )" >> $GITHUB_OUTPUT + echo "repo-name=$(echo "$REPO" | awk -F '/' '{ print tolower($2) }' | tr '_' '-')" >> "$GITHUB_OUTPUT" - name: Set up Python 3 - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: 3.x - name: Versions run: | python3 --version - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 with: submodules: true - name: Fetch correct submodule shas @@ -32,16 +30,29 @@ jobs: run: | sudo apt-get install -y gettext gawk pip install -r requirements.txt - - name: Package Folder Prefix For circuitpython-build-tools (Community Bundle Specific) - id: pkg-folder + - name: Build assets + env: + # Passed as environment, not spliced into the script by the expression. + FILENAME_PREFIX: ${{ steps.repo-name.outputs.repo-name }} run: | - echo prefix=$( + # Computed in the step that consumes it. Going via $GITHUB_OUTPUT and an + # expression would put a directory name into the next step as script text: + # a newline in it writes extra variables to $GITHUB_OUTPUT, and a quote or + # backtick escapes whatever quoting that step uses. Held in a shell + # variable it stays exactly one argument. + prefix=$( ls -RUx | gawk -F '\n' '{ match($1, /(drivers|helpers)\/(.+)\/(.+)\:/, arr) ; if (length(arr[0]) > 0 && match(arr[3], arr[2]) > 0) printf "%s, ", arr[3] }' | - gawk '{ trimmed = substr($0, 1, length($0) - 2) ; print "\"" trimmed "\"" }' - ) >> $GITHUB_OUTPUT - - name: Build assets - 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 }} + gawk '{ print substr($0, 1, length($0) - 2) }' + ) + # An empty list is never correct: build-tools splits on ", " and matches + # with startswith(), and "".startswith("") is True, so an empty prefix + # would silently make every folder -- docs/, tests/, ci/ -- a package. + if [ -z "$prefix" ]; then + echo "::error::no package folders matched under libraries/; refusing to build an empty bundle" + exit 1 + fi + circuitpython-build-bundles --filename_prefix "$FILENAME_PREFIX" --library_location libraries --library_depth 2 --package_folder_prefix "$prefix" - name: Upload Release Assets uses: shogo82148/actions-upload-release-asset@v1 with: diff --git a/build.sh b/build.sh index 94ed85f..1da0e1c 100755 --- a/build.sh +++ b/build.sh @@ -29,7 +29,12 @@ set -e P=$( ls -RUx | gawk -F '\n' '{ match($1, /(drivers|helpers)\/(.+)\/(.+)\:/, arr) ; if (length(arr[0]) > 0 && match(arr[3], arr[2]) > 0) printf "%s, ", arr[3] }' | -gawk '{ trimmed = substr($0, 1, length($0) - 2) ; print "\"" trimmed "\"" }' +gawk '{ print substr($0, 1, length($0) - 2) }' ) +if [ -z "$P" ]; then + echo "error: no package folders matched under libraries/; refusing to build an empty bundle" >&2 + exit 1 +fi + circuitpython-build-bundles --filename_prefix circuitpython-community-bundle --library_location libraries --library_depth 2 --package_folder_prefix "$P"