Skip to content

Commit 4e019a6

Browse files
committed
Merge branch 'master' of ssh://github.com/lancaster-university/codal-microbit-v2
2 parents 0f5ea52 + 3e42c96 commit 4e019a6

File tree

4 files changed

+303
-9
lines changed

4 files changed

+303
-9
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,26 @@ jobs:
4343
repository: 'lancaster-university/microbit-v2-samples'
4444
# We need to use the checkout action (instead of build.py cloning the
4545
# repository) so that on PRs we can get the commit from the PR merge
46-
- name: Clone the this repository in the libraries folder
46+
- name: Clone this repository in the libraries folder
4747
uses: actions/checkout@v3
4848
with:
4949
path: libraries/codal-microbit-v2
50-
fetch-depth: '0'
5150
# Changing the commit SHA might be unnecessary, as we've already cloned this
5251
# repo, but could be useful to ensure codal.json points to the same commit
5352
- name: Modify codal.json files to use this codal-microbit-v2 commit
5453
shell: bash
5554
run: |
5655
echo "codal.json before:"
5756
cat codal.json
58-
python -c "import pathlib; \
59-
f1 = pathlib.Path('codal.json'); \
60-
f1.write_text(f1.read_text().replace(',\n \"dev\": true', '')); \
61-
f1.write_text(f1.read_text().replace('master', '${GITHUB_SHA}')); \
62-
f2 = pathlib.Path('codal.ble.json'); \
63-
f2.write_text(f2.read_text().replace('master', '${GITHUB_SHA}')); \
64-
f2.write_text(f2.read_text().replace(',\n \"dev\": true', ''))"
57+
python - << EOF
58+
import pathlib
59+
for codal_file in ['codal.json', 'codal.ble.json']:
60+
f = pathlib.Path(codal_file)
61+
f.write_text(f.read_text() \
62+
.replace('lancaster-university/codal-microbit-v2', '${GITHUB_REPOSITORY}') \
63+
.replace('master', '${GITHUB_SHA}') \
64+
.replace(',\n \"dev\": true', ''))
65+
EOF
6566
echo "codal.json after:"
6667
cat codal.json
6768
- name: Build default (non-ble) project using build.py

.github/workflows/makecode.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build MakeCode
2+
3+
# MakeCode has to git clone/checkout this repo commit SHA, so only run this
4+
# workflow on pushes, as PRs generate a "merge commit" that is not clonable.
5+
on:
6+
push:
7+
branches: '*'
8+
9+
jobs:
10+
build-makecode:
11+
strategy:
12+
matrix:
13+
# One job builds with the local toolchain, the other with Docker
14+
pxt-flags: ["PXT_NODOCKER=1", ""]
15+
fail-fast: false
16+
name: Build MakeCode ${{ matrix.pxt-flags && '(nodocker)' }}
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: Setup Python 3.7
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.7'
23+
- name: Setup arm-none-eabi-gcc v10.3
24+
if: ${{ matrix.pxt-flags }}
25+
uses: carlosperate/arm-none-eabi-gcc-action@v1
26+
with:
27+
release: 10.3-2021.10
28+
- name: Install Yotta, Ninja v1.10 & CMake v3.22 via PyPI
29+
if: ${{ matrix.pxt-flags }}
30+
# MarkupSafe < 2.0 needed for Yotta
31+
run: python -m pip install MarkupSafe==1.1.1 ninja==1.10.2.2 cmake==3.22.1 yotta
32+
- name: Install srecord
33+
if: ${{ matrix.pxt-flags }}
34+
run: |
35+
sudo apt update
36+
sudo apt install srecord
37+
- name: Setup Node.js v16
38+
uses: actions/setup-node@v3
39+
with:
40+
node-version: 16.x
41+
- name: Clone the pxt-microbit repo
42+
uses: actions/checkout@v3
43+
with:
44+
repository: 'microsoft/pxt-microbit'
45+
- name: Install MakeCode dependencies
46+
run: |
47+
npm install -g pxt
48+
npm install
49+
# Running from pxt-microbit main branch, so use latest release of these packages
50+
npm install pxt-core@latest pxt-common-packages@latest
51+
- name: Edit pxtarget.json to use this repository and commit
52+
shell: bash
53+
run: |
54+
python - << EOF
55+
import json, collections
56+
57+
def msg_exit(msg):
58+
print('{}\nThe GH Actions workflow Python script needs to be updated.'.format(msg))
59+
exit(1)
60+
61+
with open('pxtarget.json', 'r') as f:
62+
pxt_target = json.loads(f.read(), object_pairs_hook=collections.OrderedDict)
63+
64+
try:
65+
mbcodal = pxt_target['variants']['mbcodal']
66+
mbdal = pxt_target['variants']['mbdal']
67+
if mbdal['compileService'] != {}:
68+
msg_exit("Unexpected variants.mbdal.compileService value.")
69+
if mbcodal['compileService']['codalTarget']['url'] != "https://github.com/lancaster-university/codal-microbit-v2":
70+
msg_exit("Unexpected variants.mbcodal.compileService.codalTarget.url value.")
71+
# Just need to check this exists, we don't care about the value
72+
_ = mbcodal['compileService']['codalTarget']['branch']
73+
except KeyError as e:
74+
msg_exit('The pxt-microbit/pxtarget.json structure has changed and expected keys are not found.')
75+
else:
76+
mbdal['compileService'] = { 'dockerArgs' : ['--env', 'YOTTA_GITHUB_AUTHTOKEN=${{ secrets.YOTTA_GITHUB_AUTHTOKEN }}'] }
77+
mbcodal['compileService']['codalTarget']['url'] = mbcodal['compileService']['codalTarget']['url'].replace(
78+
'lancaster-university/codal-microbit-v2', '${GITHUB_REPOSITORY}'
79+
)
80+
mbcodal['compileService']['codalTarget']['branch'] = '${GITHUB_SHA}'
81+
82+
with open('pxtarget.json', 'w') as f:
83+
f.write(json.dumps(pxt_target, indent=4))
84+
EOF
85+
git diff pxtarget.json
86+
- name: Build MakeCode targets
87+
# Because pxt runs docker with "--user build" it doesn't have write access to some mounted files,
88+
# so we need to force all files created by the pxt cli to have write/execute rights for everyone
89+
run: |
90+
chmod -R a+rwx .
91+
umask 0000
92+
${{ matrix.pxt-flags }} pxt buildtarget --local
93+
env:
94+
YOTTA_GITHUB_AUTHTOKEN: ${{ secrets.YOTTA_GITHUB_AUTHTOKEN }}

.github/workflows/micropython.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build MicroPython
2+
3+
# MicroPython has to git clone/checkout this repo commit SHA, so only run this
4+
# workflow on pushes, as PRs generate a "merge commit" that is not clonable.
5+
on:
6+
push:
7+
branches: '*'
8+
9+
jobs:
10+
build-micropython:
11+
runs-on: ubuntu-22.04
12+
name: Build MicroPython
13+
steps:
14+
- name: Clone MicroPython
15+
uses: actions/checkout@v3
16+
with:
17+
repository: 'microbit-foundation/micropython-microbit-v2'
18+
submodules: true
19+
- name: Setup arm-none-eabi-gcc v10.3
20+
uses: carlosperate/arm-none-eabi-gcc-action@v1
21+
with:
22+
release: 10.3-2021.10
23+
- name: Install CMake v3.22 via PyPI
24+
run: python -m pip install cmake==3.22.1
25+
- name: Check Versions
26+
run: |
27+
arm-none-eabi-gcc --version
28+
cmake --version
29+
- name: Modify codal.json to use this codal-microbit-v2 commit
30+
shell: bash
31+
run: |
32+
python - << EOF
33+
import json, collections
34+
35+
with open('src/codal_app/codal.json', 'r') as f:
36+
codal_json = json.loads(f.read(), object_pairs_hook=collections.OrderedDict)
37+
38+
try:
39+
if codal_json['target']['url'] != "https://github.com/lancaster-university/codal-microbit-v2":
40+
print("Unexpected target URL value.")
41+
exit(1)
42+
# Just need to check this exists, we don't care about the value
43+
_ = codal_json['target']['branch']
44+
except KeyError as e:
45+
print('The src/codal_app/codal.json structure has changed and expected keys are not found.')
46+
exit(1)
47+
else:
48+
codal_json['target']['url'] = codal_json['target']['url'].replace(
49+
'lancaster-university/codal-microbit-v2', '${GITHUB_REPOSITORY}'
50+
)
51+
codal_json['target']['branch'] = '${GITHUB_SHA}'
52+
53+
with open('src/codal_app/codal.json', 'w') as f:
54+
f.write(json.dumps(codal_json, indent=4))
55+
EOF
56+
git diff src/codal_app/codal.json
57+
- name: Build MicroPython
58+
run: |
59+
make -C lib/micropython/mpy-cross -j4
60+
cd src
61+
make -j4
62+
- name: Upload hex file
63+
uses: actions/upload-artifact@v1
64+
with:
65+
name: micropython-${{ github.sha }}.hex
66+
path: src/MICROBIT.hex

.github/workflows/size-diff.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Bloaty size diff
2+
3+
on:
4+
pull_request:
5+
branches: '*'
6+
push:
7+
branches: '*'
8+
9+
jobs:
10+
size-diff:
11+
name: Run Bloaty
12+
runs-on: ubuntu-latest
13+
steps:
14+
#########################
15+
# Install the toolchain #
16+
#########################
17+
- name: Setup Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.8'
21+
- name: Setup arm-none-eabi-gcc 10.3
22+
uses: carlosperate/arm-none-eabi-gcc-action@v1
23+
with:
24+
release: 10.3-2021.10
25+
- name: Install Ninja 1.11 & CMake 3.25 via PyPI
26+
run: python -m pip install ninja==1.11.1 cmake==3.25.0
27+
28+
#########################################
29+
# Set up the CODAL project and build it #
30+
#########################################
31+
- name: Clone the microbit-v2-samples repository
32+
uses: actions/checkout@v3
33+
with:
34+
repository: 'lancaster-university/microbit-v2-samples'
35+
# We need to use the checkout action (instead of build.py cloning the
36+
# repository) so that on PRs we can get the commit from the PR merge
37+
- name: Clone this repository in the libraries folder
38+
uses: actions/checkout@v3
39+
with:
40+
path: libraries/codal-microbit-v2
41+
fetch-depth: '0'
42+
# Changing the commit SHA might be unnecessary, as we've already cloned this
43+
# repo, but could be useful to ensure codal.json points to the same commit
44+
- name: Modify files to use BLE & this codal-microbit-v2 commit
45+
shell: bash
46+
run: |
47+
echo "coda.json before:"
48+
cat codal.json
49+
mv codal.ble.json codal.json
50+
python - << EOF
51+
import pathlib;
52+
f = pathlib.Path('codal.json');
53+
f.write_text(f.read_text() \
54+
.replace('lancaster-university/codal-microbit-v2', '${GITHUB_REPOSITORY}') \
55+
.replace('master', '${GITHUB_SHA}') \
56+
.replace(',\n \"dev\": true', ''))
57+
f = pathlib.Path('source/main.cpp')
58+
f.write_text(f.read_text().replace('out_of_box_experience()', 'ble_test()'))
59+
EOF
60+
echo "coda.json after:"
61+
cat codal.json
62+
- name: Build using build.py
63+
run: python build.py
64+
- name: Save ELF file in a different directory
65+
run: |
66+
mkdir original-build
67+
mv build/MICROBIT original-build/MICROBIT.elf
68+
# Manually clean the project, but keep the codal-microbit-v2 library
69+
# If the codal-microbit-v2 target adds more libs this step will need to include them as well
70+
- name: Clean project
71+
run: rm -rf build/ libraries/codal-core libraries/codal-microbit-nrf5sdk libraries/codal-nrf52
72+
73+
####################################################################
74+
# Set up codal-microbit-v2 to a parent/base commit and build again #
75+
####################################################################
76+
- name: "PR only: Get base commit SHA"
77+
if: ${{ github.event.pull_request.base.sha }}
78+
run: |
79+
echo "${{ github.event.pull_request.base.sha }}"
80+
echo "GIT_BASE_SHA=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
81+
echo "# Bloaty comparison with PR base commit" >> $GITHUB_STEP_SUMMARY
82+
echo "Base commit: ${{ github.event.pull_request.base.sha }}" >> $GITHUB_STEP_SUMMARY
83+
- name: "Commit only: Get parent commit SHA"
84+
if: ${{ ! github.event.pull_request.base.sha }}
85+
run: |
86+
cd libraries/codal-microbit-v2
87+
echo "$(git log --pretty=%P -n 1 HEAD^0)"
88+
echo "GIT_BASE_SHA=$(git log --pretty=%P -n 1 HEAD^0)" >> $GITHUB_ENV
89+
echo "# Bloaty comparison with parent commit" >> $GITHUB_STEP_SUMMARY
90+
echo "Parent commit: $(git log --pretty=%P -n 1 HEAD^0)" >> $GITHUB_STEP_SUMMARY
91+
# We don't need to update codal.json because we've kept the
92+
# codal-microbit-v2 repo and we manually check out the right base commit
93+
- name: Checkout parent/base commit of codal-microbit-v2
94+
run: |
95+
cd libraries/codal-microbit-v2
96+
git checkout ${GIT_BASE_SHA}
97+
- name: Build 'base' project using build.py
98+
run: python build.py --clean
99+
100+
#######################################
101+
# Run the Bloaty McBloatface analysis #
102+
#######################################
103+
# 1st run the bloaty diff so that it's added to the top of the summary page
104+
- name: Run Bloaty to compare before and after ELF files
105+
id: bloaty-comparison
106+
uses: carlosperate/bloaty-action@v1
107+
with:
108+
bloaty-args: -s vm original-build/MICROBIT.elf -- build/MICROBIT
109+
output-to-summary: true
110+
# Then show memory consumption of top 30 components for this build
111+
- name: Run Bloaty to view ELF file full info
112+
uses: carlosperate/bloaty-action@v1
113+
with:
114+
bloaty-args: original-build/MICROBIT.elf -d compileunits -n 30 -s vm
115+
output-to-summary: true
116+
- name: Add comment to PR with the bloaty diff
117+
if: ${{ github.event.pull_request }}
118+
continue-on-error: true
119+
uses: actions/github-script@v6
120+
with:
121+
script: |
122+
let prComment = '## Build diff\n' +
123+
'Base commit: [${{ env.GIT_BASE_SHA }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ env.GIT_BASE_SHA }})\n' +
124+
'Action run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n' +
125+
'```\n' +
126+
'${{ steps.bloaty-comparison.outputs.bloaty-output-encoded }}' +
127+
'```\n'
128+
github.rest.issues.createComment({
129+
issue_number: context.issue.number,
130+
owner: context.repo.owner,
131+
repo: context.repo.repo,
132+
body: prComment
133+
})

0 commit comments

Comments
 (0)