Skip to content

Update to use pre compiled mpy-cross binaries #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
23 changes: 11 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ Inputs
Argument Name Description Default Notes
======================= ===================================================================== ==================== =====================================================================
github-token Your GitHub token N/A N/A
circuitpy-tag The version of CircuitPython to compile for N/A You can use any valid tag (or branch) from ``adafruit/circuitpython``
mpy-cross-version The version of mpy-cross to download and use 9.2.4 You can specify any version from ``https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/mpy-cross/linux-amd64``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a little overwhelming and translates to the same effect as the CircuitPython version. I think this name and description should remain as is, so it's easier for people to understand exactly which version they should be selecting. In that case, changing it to circuitpy-version would also be appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this makes it more user friendly.

zip-filename The name of the ZIP file that will be attached "mpy-release.zip" N/A
circuitpython-repo-name The name of the clone CircuitPython repo "circuitpython-repo" Change if it conflicts with another file
mpy-directory The directory to search for files to compile "." (top folder) Becomes the basis for filepaths in ``mpy-manifest-file``
mpy-manifest-file A file with a list of files to compile or exclude "" If none is given, all files in ``mpy-directory`` are used
mpy-manifest-type Whether the files in the manifest file should be included or excluded "include" N/A
Expand All @@ -35,7 +34,7 @@ Examples
========

If you have just a repository with files intended for a CircuitPython board, your release
file could be very simple! This release CI creates .mpy files for CircuitPython 8.2.0:
file could be very simple!

.. code-block:: yaml

Expand All @@ -48,19 +47,19 @@ file could be very simple! This release CI creates .mpy files for CircuitPython
runs-on: ubuntu-latest
steps:
- name: Checkout the current repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Run MPY Action
uses: adafruit/build-mpy@v1
uses: adafruit/build-mpy@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
circuitpy-tag: "8.2.0"

You also have granular control of which directories to compile and zip and the ability to specify which
files should or should not be compiled and/or zipped. For example, if you wanted to compile and zip
files in a folder named ``microcontroller`` and you wanted to use a manifest file named ``mpy_manifest.txt``
to specify certain files NOT to compile, you could modify the script above to be:
files should or should not be compiled and/or zipped as well as the ability to specify a different mpy-cross
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just missing a period at the end of the sentence. I would also make this refer to the version of CircuitPython instead of specifically to the mpy-cross version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as well as fixed some other typo's.

For example, if you wanted to compile and zip files in a folder named ``microcontroller`` and you wanted to
use a manifest file named ``mpy_manifest.txt`` to specify certain files NOT to compile, using mpy-cross
version ``7.3.1``, you could modify the script above to be:

.. code-block:: yaml

Expand All @@ -73,14 +72,14 @@ to specify certain files NOT to compile, you could modify the script above to be
runs-on: ubuntu-latest
steps:
- name: Checkout the current repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Run MPY Action
uses: adafruit/build-mpy@v1
uses: adafruit/build-mpy@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
circuitpy-tag: "8.2.0"
mpy-cross-version: "7.3.1"
mpy-directory: "microcontroller"
mpy-manifest-file: "mpy_manifest.txt"
mpy-manifest-type: "exclude"
Expand Down
54 changes: 11 additions & 43 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ inputs:
github-token:
description: 'Your GitHub token, needed to upload the ZIP file'
required: true
circuitpy-tag:
description: 'The CircuitPython version of mpy-cross to build'
mpy-cross-version:
description: 'The version of mpy-cross to use'
required: true
default: "9.2.4"
zip-filename:
description: 'The name of the ZIP file to attach'
required: true
default: "mpy-release.zip"
circuitpython-repo-name:
description: >
The name for the CircuitPython repo. The default is 'circuitpython-repo',
and there typically isn't any reason to change this unless it conflicts
with an existing folder name in your repository.
required: true
default: 'circuitpython-repo'
mpy-directory:
description: >
The directory to look for files to compile with mpy-cross. If none
Expand Down Expand Up @@ -76,39 +70,17 @@ runs:
sudo apt install build-essential
sudo add-apt-repository ppa:pybricks/ppa
sudo apt install git gettext uncrustify
- name: Clone adafruit/circuitpython
uses: actions/checkout@v3
with:
repository: adafruit/circuitpython
path: ${{ inputs.circuitpython-repo-name }}
- name: Enter CircuitPython repo, checkout tag, and update
shell: bash
run: |
function version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}

cd ${{ inputs.circuitpython-repo-name }}
git fetch
git checkout ${{ inputs.circuitpy-tag }}

if [ $(version "${{ inputs.circuitpy-tag }}") -ge $(version "8.2.0") ]; then
make fetch-all-submodules
else
make fetch-submodules
fi
- name: Build mpy-cross
- name: Download mpy-cross
shell: bash
run: |
cd ${{ inputs.circuitpython-repo-name }}/mpy-cross
make clean
make
mkdir mpy-cross
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the escape hatch of the folder name being customizable is nice in the VERY rare event it conflicts with something in the user's repository. I'd keep this functionality included, though I'd rename it to something more appropriate if we're downloading the pre-compiled binary. Altertnatively, you could just place it in the root folder, in which case I agree the escape hatch isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this option.

cd mpy-cross
wget -O mpy-cross https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/linux-amd64/mpy-cross-linux-amd64-${{ inputs.mpy-cross-version }}.static
chmod +x mpy-cross
- name: Compile MPY files
shell: bash
run: |
# Store repo name
reponame="${{ inputs.circuitpython-repo-name }}"

echo "Compiling using mpy-cross version ${{ inputs.mpy-cross-version }}"
# Read MPY manifest file contents, if needed
if [[ "${{ inputs.mpy-manifest-file }}" != "" ]]
then
Expand All @@ -125,7 +97,7 @@ runs:
# Compile MPY files
mpyresults=()
prempyfiles=()
pyfiles=$(find ${{ inputs.mpy-directory }} -name "*.py" ! -path "./${{ inputs.circuitpython-repo-name }}/*" ! -name "code.py" -printf '%P\n')
pyfiles=$(find ${{ inputs.mpy-directory }} -name "*.py" ! -name "code.py" -printf '%P\n')
for file in ${pyfiles[@]}
do
if [[ "${{ inputs.mpy-manifest-file }}" == "" ]] || \
Expand All @@ -137,14 +109,10 @@ runs:
mpyresults+=("$outputmpy")
prempyfile="${{ inputs.mpy-directory }}/$file"
prempyfiles+=("$prempyfile")
${reponame}/mpy-cross/mpy-cross $prempyfile -o $outputmpy
mpy-cross/mpy-cross $prempyfile -o $outputmpy
fi
done

# Delete the CircuitPython repo
echo "Deleting CircuitPython repository folder"
rm -r ${{ inputs.circuitpython-repo-name }}

# Read ZIP manifest file contents, if needed
if [[ "${{ inputs.zip-manifest-file }}" != "" ]]
then
Expand Down