Skip to content

Generate automatically module_firmware_index.json #82

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

Merged
merged 8 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
82 changes: 82 additions & 0 deletions .github/workflows/generate-index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Generate Index

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
branches:
paths:
- "generator/**"
- "firmwares/**"
- "poetry.lock"
- "pyproject.toml"
- ".github/workflows/generate-index.yml"
workflow_dispatch:
repository_dispatch:

jobs:
generate-index:
runs-on: ubuntu-latest
defaults:
run:
working-directory: generator

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Taskfile
uses: arduino/setup-task@v1

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Install Poetry
run: pip install poetry

- name: Install Arduino CLI
uses: arduino/setup-arduino-cli@v1

- name: Install platforms
run: |
arduino-cli core update-index -v
arduino-cli version
arduino-cli core install arduino:samd@${{ env.SAMD_V }} -v
arduino-cli core install arduino:megaavr@${{ env.MEGAAVR_V }} -v
arduino-cli core install arduino:mbed_nano@${{ env.MBED_NANO_V }} -v
env:
SAMD_V: 1.8.11
MEGAAVR_V: 1.8.7
MBED_NANO_V: 2.2.0

- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE
task poetry:install-deps

- name: Generate index
run: poetry run ./generator.py -a $(which arduino-cli)

# fix `gpg: signing failed: Inappropriate ioctl for device`
# https://github.com/keybase/keybase-issues/issues/2798
- name: Import GPG key
run: |
echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 -di > private.key
gpg --batch --import --passphrase "${{ secrets.PASSPHRASE }}" private.key
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV

# disable gpg pass prompt
# https://stackoverflow.com/questions/49072403/suppress-the-passphrase-prompt-in-gpg-command
- name: sign the json
run: gpg --pinentry-mode=loopback --passphrase "${{ secrets.PASSPHRASE }}" --output boards/module_firmware_index.json.sig --detach-sign boards/module_firmware_index.json

- name: create the gzip
run: gzip --keep boards/module_firmware_index.json

- name: s3 sync
run: ./s3Copy.sh . s3://arduino-downloads-prod-beagle/arduino-fwuploader
env:
AWS_REGION: "us-east-1" # or https://github.com/aws/aws-cli/issues/5623
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
coverage_*.txt
/dist
__pycache__/
/generator/boards/
/generator/firmwares/

# Misc.
.DS_Store
Expand Down
6 changes: 3 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ tasks:
desc: Run integration tests
cmds:
- task: build
- poetry install --no-root
- task: poetry:install-deps
- poetry run pytest test

check:
Expand Down Expand Up @@ -123,13 +123,13 @@ tasks:
python:lint:
desc: Lint Python code
cmds:
- poetry install --no-root
- task: poetry:install-deps
- poetry run flake8

python:format:
desc: Automatically formats Python files
cmds:
- poetry install --no-root
- task: poetry:install-deps
- poetry run black .

vars:
Expand Down
2 changes: 2 additions & 0 deletions generator/generator.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import argparse
import subprocess
import sys
Expand Down
11 changes: 11 additions & 0 deletions generator/s3Copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
path=$1 # the path of the directory where the files and directories that need to be copied are located
s3Dir=$2 # the s3 bucket path

for entry in "$path"/*; do
name=`echo $entry | sed 's/.*\///'` # getting the name of the file or directory
if [[ -d $entry ]]; then # if it is a directory
aws s3 cp --recursive "$name" "$s3Dir/$name/"
else # if it is a file
aws s3 cp "$name" "$s3Dir/" --exclude "generator.py" --exclude "raw_boards.json" --exclude "s3Copy.sh"
fi
done