Skip to content

Commit 00b1d72

Browse files
authored
Generate automatically module_firmware_index.json (#82)
* add shell script to easily copy dir structure to s3 * add generated content to .gitignore * remove code duplication * add python3 shebang and chmod +x * add first prototype of the generate-index workflow (still to test) * various fixes, should work now * apply formatting * trigger workflow only on master
1 parent d660c25 commit 00b1d72

File tree

5 files changed

+101
-3
lines changed

5 files changed

+101
-3
lines changed

.github/workflows/generate-index.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Generate Index
2+
3+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
branches:
7+
- master
8+
paths:
9+
- "generator/**"
10+
- "firmwares/**"
11+
- "poetry.lock"
12+
- "pyproject.toml"
13+
- ".github/workflows/generate-index.yml"
14+
workflow_dispatch:
15+
repository_dispatch:
16+
17+
jobs:
18+
generate-index:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: generator
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v2
27+
28+
- name: Install Taskfile
29+
uses: arduino/setup-task@v1
30+
31+
- name: Install Python
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: "3.9"
35+
36+
- name: Install Poetry
37+
run: pip install poetry
38+
39+
- name: Install Arduino CLI
40+
uses: arduino/setup-arduino-cli@v1
41+
42+
- name: Install platforms
43+
run: |
44+
arduino-cli core update-index -v
45+
arduino-cli version
46+
arduino-cli core install arduino:samd@${{ env.SAMD_V }} -v
47+
arduino-cli core install arduino:megaavr@${{ env.MEGAAVR_V }} -v
48+
arduino-cli core install arduino:mbed_nano@${{ env.MBED_NANO_V }} -v
49+
env:
50+
SAMD_V: 1.8.11
51+
MEGAAVR_V: 1.8.7
52+
MBED_NANO_V: 2.2.0
53+
54+
- name: Install dependencies
55+
run: |
56+
cd $GITHUB_WORKSPACE
57+
task poetry:install-deps
58+
59+
- name: Generate index
60+
run: poetry run ./generator.py -a $(which arduino-cli)
61+
62+
# fix `gpg: signing failed: Inappropriate ioctl for device`
63+
# https://github.com/keybase/keybase-issues/issues/2798
64+
- name: Import GPG key
65+
run: |
66+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 -di > private.key
67+
gpg --batch --import --passphrase "${{ secrets.PASSPHRASE }}" private.key
68+
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
69+
70+
# disable gpg pass prompt
71+
# https://stackoverflow.com/questions/49072403/suppress-the-passphrase-prompt-in-gpg-command
72+
- name: sign the json
73+
run: gpg --pinentry-mode=loopback --passphrase "${{ secrets.PASSPHRASE }}" --output boards/module_firmware_index.json.sig --detach-sign boards/module_firmware_index.json
74+
75+
- name: create the gzip
76+
run: gzip --keep boards/module_firmware_index.json
77+
78+
- name: s3 sync
79+
run: ./s3Copy.sh . s3://arduino-downloads-prod-beagle/arduino-fwuploader
80+
env:
81+
AWS_REGION: "us-east-1" # or https://github.com/aws/aws-cli/issues/5623
82+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
83+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
coverage_*.txt
66
/dist
77
__pycache__/
8+
/generator/boards/
9+
/generator/firmwares/
810

911
# Misc.
1012
.DS_Store

Taskfile.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ tasks:
9393
desc: Run integration tests
9494
cmds:
9595
- task: build
96-
- poetry install --no-root
96+
- task: poetry:install-deps
9797
- poetry run pytest test
9898

9999
check:
@@ -123,13 +123,13 @@ tasks:
123123
python:lint:
124124
desc: Lint Python code
125125
cmds:
126-
- poetry install --no-root
126+
- task: poetry:install-deps
127127
- poetry run flake8
128128

129129
python:format:
130130
desc: Automatically formats Python files
131131
cmds:
132-
- poetry install --no-root
132+
- task: poetry:install-deps
133133
- poetry run black .
134134

135135
vars:

generator/generator.py

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
import argparse
24
import subprocess
35
import sys

generator/s3Copy.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
path=$1 # the path of the directory where the files and directories that need to be copied are located
2+
s3Dir=$2 # the s3 bucket path
3+
4+
for entry in "$path"/*; do
5+
name=`echo $entry | sed 's/.*\///'` # getting the name of the file or directory
6+
if [[ -d $entry ]]; then # if it is a directory
7+
aws s3 cp --recursive "$name" "$s3Dir/$name/"
8+
else # if it is a file
9+
aws s3 cp "$name" "$s3Dir/" --exclude "generator.py" --exclude "raw_boards.json" --exclude "s3Copy.sh"
10+
fi
11+
done

0 commit comments

Comments
 (0)