Skip to content

Commit bb0d7d3

Browse files
authored
Merge pull request #749 from Josverl/wf/createstubs
Update createstubs.yml and firmware flashing process
2 parents 6c07e5b + 0593ffd commit bb0d7d3

File tree

2,708 files changed

+206492
-2335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,708 files changed

+206492
-2335
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "get-mpversions"
2+
description: "get the most recent 4 published versions of MicroPython"
3+
inputs:
4+
max:
5+
description: "Maximum number of versions to return"
6+
required: false
7+
default: "4"
8+
9+
10+
outputs:
11+
versions:
12+
description: "Return recent versions of MicroPython"
13+
value: ${{ steps.dynamic.outputs.versions }}
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.11
21+
cache: pip
22+
23+
- run: pip install pygithub packaging
24+
shell: bash
25+
26+
- run: python .github/actions/get-mpversions/list_versions.py --latest --preview --max ${{ inputs.max }}
27+
shell: bash
28+
id: dynamic
29+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
This module retrieves the versions of Micropython from the Micropython repository on GitHub.
3+
It is used to generate a matrix of versions to create stubs for using Github Actions.
4+
5+
It provides a function `micropython_versions` that returns a list of versions starting from a specified version.
6+
The module also includes a main block that generates a matrix of versions based on command-line arguments and environment variables.
7+
The matrix is printed as JSON and can be optionally written to a file if running in a GitHub Actions workflow.
8+
"""
9+
import argparse
10+
import json
11+
import os
12+
13+
from github import Auth, Github
14+
from packaging.version import parse
15+
16+
# Token with no permissions to avoid throttling
17+
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#getting-a-higher-rate-limit
18+
PAT_NO_ACCESS = (
19+
"github_pat" + "_11AAHPVFQ0qAkDnSUaMKSp" + "_ZkDl5NRRwBsUN6EYg9ahp1Dvj4FDDONnXVgimxC2EtpY7Q7BUKBoQ0Jq72X"
20+
)
21+
PAT = os.environ.get("GITHUB_TOKEN") or PAT_NO_ACCESS
22+
23+
def micropython_versions(start="v1.10"):
24+
g = Github(auth=Auth.Token(PAT))
25+
try:
26+
repo = g.get_repo("micropython/micropython")
27+
# Suppress `v1.22.0-preview` tags
28+
tags = sorted([tag.name for tag in repo.get_tags() if "-preview" not in tag.name and parse(tag.name) >= parse(start)], reverse=True)
29+
except Exception as e:
30+
print(f"Error: {e}")
31+
tags = ["stable"]
32+
return tags
33+
34+
35+
def main():
36+
matrix = {}
37+
38+
parser = argparse.ArgumentParser()
39+
parser.add_argument("--stable", "--latest","-s", action=argparse.BooleanOptionalAction,default=True, help="Add latest version")
40+
parser.add_argument("--preview", "-p", action=argparse.BooleanOptionalAction, default=False, help="Add preview version")
41+
parser.add_argument("--max", "-m", type=int, default=3, help="Maximum number of versions")
42+
43+
args = parser.parse_args()
44+
45+
# only run latests when running in ACT locally for testing
46+
if os.environ.get("ACT"):
47+
matrix["version"] = micropython_versions(start="v1.20")[:1] # only latest
48+
else:
49+
matrix["version"] = micropython_versions(start="v1.20")[1:args.max] # last three
50+
51+
52+
print(args)
53+
if args.stable:
54+
matrix["version"].insert(0, "stable")
55+
if args.preview:
56+
matrix["version"].insert(0, "preview")
57+
matrix["version"]=matrix["version"][:args.max]
58+
# GITHUB_OUTPUT is set by github actions
59+
if os.getenv('GITHUB_OUTPUT'):
60+
with open(os.getenv('GITHUB_OUTPUT'), 'a') as file: # type: ignore
61+
file.write(f"versions={json.dumps(matrix)}")
62+
else:
63+
print(json.dumps(matrix, indent=4))
64+
65+
# sourcery skip: assign-if-exp, merge-dict-assign
66+
if __name__ == "__main__":
67+
main()
68+

.github/not-active/action-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
# make Python work
3030
- name: Set up Python
31-
uses: actions/setup-python@v4
31+
uses: actions/setup-python@v5
3232
with:
3333
python-version: 3.11
3434

.github/not-active/get-all-frozen.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
fetch-depth: 1
3030
- name: Set up Python
31-
uses: actions/setup-python@v4
31+
uses: actions/setup-python@v5
3232
with:
3333
python-version: 3.11
3434

@@ -61,7 +61,7 @@ jobs:
6161

6262
# make Python work
6363
- name: Set up Python
64-
uses: actions/setup-python@v4
64+
uses: actions/setup-python@v5
6565
with:
6666
python-version: 3.11
6767

@@ -108,7 +108,7 @@ jobs:
108108

109109
# # make Python work
110110
# - name: Set up Python
111-
# uses: actions/setup-python@v4
111+
# uses: actions/setup-python@v5
112112
# with:
113113
# python-version: 3.9
114114
# cache: "pip"

.github/not-active/get-doc-stubs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252

5353
# make Python work
5454
- name: Set up Python
55-
uses: actions/setup-python@v4
55+
uses: actions/setup-python@v5
5656
with:
5757
python-version: 3.9
5858
cache: "pip"

.github/not-active/get-loboris-frozen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
# make Python work
3333
- name: Set up Python
34-
uses: actions/setup-python@v4
34+
uses: actions/setup-python@v5
3535
with:
3636
python-version: 3.9
3737

.github/not-active/testspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/checkout@v4
2424

2525
- name: Set up Python 3.x
26-
uses: actions/setup-python@v4
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: 3.9
2929
cache: "pip"

.github/runner/selfhosted.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/createstubs.yml

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,84 @@ name: Createstubs
33
on: [push, workflow_dispatch]
44

55
jobs:
6-
build:
7-
runs-on: self-hosted
6+
########################################################################################################################################
7+
list-versions-cs:
8+
# 'Get a matrix for the latest versions of micropython'
9+
runs-on: ubuntu-latest
810
steps:
9-
- uses: actions/checkout@v4
10-
- name: Set up Python
11-
uses: actions/setup-python@v5
12-
with:
13-
python-version: 3.12
14-
# cache: pip
15-
16-
- name: Install dependencies
17-
run: |
18-
pip install mpremote
19-
20-
- name: list connected devices
21-
run: |
22-
mpremote devs
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 1
14+
- uses: ./.github/actions/get-mpversions
15+
id: dynamic
16+
outputs:
17+
versions: ${{ steps.dynamic.outputs.versions }}
18+
########################################################################################################################################
19+
createstubs:
20+
needs: list-versions-cs
21+
runs-on: [self-hosted, mpremote, ARM64]
22+
strategy:
23+
matrix: ${{ fromJSON(needs.list-versions-cs.outputs.versions) }}
24+
max-parallel: 1
25+
# matrix:
26+
# version: [preview, v1.22.2]
27+
steps:
28+
- name: Checkout stubs repo
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Python
32+
# if: ${{ matrix.os == 'ubuntu-arm' }}
33+
uses: deadsnakes/[email protected]
34+
with:
35+
python-version: "3.11"
36+
37+
- name: Install dependencies
38+
run: |
39+
pipx install poetry
40+
pip install -U mpremote micropython-stubber
41+
42+
- name: Install mp_downloader
43+
run: |
44+
# dev versie
45+
pip install -I git+https://github.com/josverl/micropython-stubber.git@action_board_stubber#subdirectory=src/mptool
46+
47+
- uses: actions/cache@v4
48+
with:
49+
path: firmware
50+
key: ${{ runner.os }}-firmware-${{ matrix.version }}-${{ hashFiles('firmware/firmware.json') }}
51+
restore-keys: |
52+
${{ runner.os }}-firmware-${{ matrix.version }}
53+
${{ runner.os }}-firmware-
54+
55+
56+
- name: Get ${{ matrix.version }} firmwares for flashing
57+
run: |
58+
mptool download --version ${{ matrix.version }}
59+
60+
- name: Update firmware to ${{ matrix.version }} on all connected boards
61+
# cant update stm32 as that requires sudo :-(
62+
run: |
63+
mptool flash --version ${{ matrix.version }}
64+
65+
- name: clone Repos
66+
run: |
67+
stubber clone
68+
69+
- name: run board stubber
70+
run: |
71+
stubber get-mcu-stubs
72+
73+
- name: check in changes
74+
run: |
75+
git config user.name github-actions
76+
git config user.email [email protected]
77+
git pull
78+
git add .
79+
git commit -m "create boardstubs"
80+
git push
81+
82+
- name: Build App
83+
if: always()
84+
run: echo "Done."
85+
86+

.github/workflows/list_versions.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
from github import Github
1414
from packaging.version import parse
1515

16-
...
17-
import json
18-
import os
19-
import sys
20-
21-
from github import Github
22-
from packaging.version import parse
23-
2416

2517
def micropython_versions(start="v1.10"):
2618
g = Github()
@@ -33,22 +25,28 @@ def micropython_versions(start="v1.10"):
3325
tags = ["v1.19.1"]
3426
return tags
3527

36-
# sourcery skip: assign-if-exp, merge-dict-assign
37-
if __name__ == "__main__":
28+
29+
def main():
3830
matrix = {}
3931
# only run latests when running in ACT locally for testing
4032
if os.environ.get("ACT"):
41-
matrix["version"] = micropython_versions(start="v1.20")[-1:]
33+
matrix["version"] = micropython_versions(start="v1.20")[:1] # only latest
4234
else:
43-
matrix["version"] = micropython_versions(start="v1.20")
35+
matrix["version"] = micropython_versions(start="v1.20")[:3] # last three
4436

4537
add_latest = False
4638
if len(sys.argv) > 1 and (sys.argv[1].lower() in ["--latest", "-l"]):
47-
print("Adding latest")
39+
# print("Adding latest")
4840
matrix["version"].insert(0, "latest")
4941

50-
print(json.dumps(matrix))
5142
# GITHUB_OUTPUT is set by github actions
5243
if os.getenv('GITHUB_OUTPUT'):
5344
with open(os.getenv('GITHUB_OUTPUT'), 'a') as file: # type: ignore
5445
file.write(f"versions={json.dumps(matrix)}")
46+
else:
47+
print(json.dumps(matrix))
48+
49+
# sourcery skip: assign-if-exp, merge-dict-assign
50+
if __name__ == "__main__":
51+
main()
52+

0 commit comments

Comments
 (0)