Skip to content

Commit 927af98

Browse files
Paolo Calaopolldo
Paolo Calao
authored andcommitted
Download provisioning binaries from aws (#74)
This completes the task of decoupling provisioning binaries from the repo. - Now users can use the 'device create' commands from any directory, since binaries are no more tied to a certain folder - Binaries can be updated without requiring a new release of the cli Changes: - provisioning binaries are now downloaded instead of being searched in the binaries folder - binaries folder has been removed - binaries are removed from the release process
1 parent 08ad6fc commit 927af98

24 files changed

+475
-184
lines changed

Diff for: .github/workflows/release-go-task.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ env:
99
# The project's folder on Arduino's download server for uploading builds
1010
AWS_PLUGIN_TARGET: TODO
1111
ARTIFACT_NAME: dist
12-
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project
13-
PROVISIONING_BINARIES_FOLDER: binaries
1412

1513
on:
1614
push:
@@ -104,15 +102,14 @@ jobs:
104102
# This step performs the following:
105103
# 1. Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
106104
# 2. Recalculate package checksum and replace it in the nnnnnn-checksums.txt file
107-
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project ({{.PROVISIONING_BINARIES_FOLDER}})
108105
run: |
109106
# GitHub's upload/download-artifact@v2 actions don't preserve file permissions,
110107
# so we need to add execution permission back until the action is made to do this.
111108
chmod +x ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/${{ env.PROJECT_NAME }}
112109
TAG="${GITHUB_REF/refs\/tags\//}"
113110
tar -czvf "${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz" \
114111
-C ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_darwin_amd64/ ${{ env.PROJECT_NAME }} \
115-
-C ../../ ${{ env.PROVISIONING_BINARIES_FOLDER }} LICENSE.txt
112+
-C ../../ LICENSE.txt
116113
CHECKSUM="$(shasum -a 256 ${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_${TAG}_macOS_64bit.tar.gz | cut -d " " -f 1)"
117114
perl \
118115
-pi \

Diff for: DistTasks.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ tasks:
3939
Windows_32bit:
4040
desc: Builds Windows 32 bit binaries
4141
dir: "{{.DIST_DIR}}"
42-
# TODO: Remember to REMOVE binaries folder as soon as it is removed from the project
4342
cmds:
4443
- |
4544
docker run -v `pwd`/..:/home/build -w /home/build \
@@ -50,7 +49,7 @@ tasks:
5049
5150
cp {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../
5251
cd ..
53-
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt
52+
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe LICENSE.txt
5453
cd {{.DIST_DIR}}
5554
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
5655
@@ -75,7 +74,7 @@ tasks:
7574
7675
cp {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe ../
7776
cd ..
78-
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt
77+
zip -r {{.DIST_DIR}}/{{.PACKAGE_NAME}} {{.PROJECT_NAME}}.exe LICENSE.txt
7978
cd {{.DIST_DIR}}
8079
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
8180
@@ -98,7 +97,7 @@ tasks:
9897
--build-cmd "{{.BUILD_COMMAND}}" \
9998
-p "{{.BUILD_PLATFORM}}"
10099
101-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
100+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
102101
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
103102
104103
vars:
@@ -120,7 +119,7 @@ tasks:
120119
--build-cmd "{{.BUILD_COMMAND}}" \
121120
-p "{{.BUILD_PLATFORM}}"
122121
123-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
122+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
124123
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
125124
126125
vars:
@@ -142,7 +141,7 @@ tasks:
142141
--build-cmd "{{.BUILD_COMMAND}}" \
143142
-p "{{.BUILD_PLATFORM}}"
144143
145-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
144+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
146145
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
147146
148147
vars:
@@ -164,7 +163,7 @@ tasks:
164163
--build-cmd "{{.BUILD_COMMAND}}" \
165164
-p "{{.BUILD_PLATFORM}}"
166165
167-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
166+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
168167
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
169168
170169
vars:
@@ -214,7 +213,7 @@ tasks:
214213
--build-cmd "{{.BUILD_COMMAND}}" \
215214
-p "{{.BUILD_PLATFORM}}"
216215
217-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
216+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
218217
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
219218
220219
vars:
@@ -236,7 +235,7 @@ tasks:
236235
--build-cmd "{{.BUILD_COMMAND}}" \
237236
-p "{{.BUILD_PLATFORM}}"
238237
239-
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. {{.PROVISIONING_BINARIES_FOLDER}} LICENSE.txt -f {{.PACKAGE_NAME}}
238+
tar cz -C {{.PLATFORM_DIR}} {{.PROJECT_NAME}} -C ../.. LICENSE.txt -f {{.PACKAGE_NAME}}
240239
sha256sum {{.PACKAGE_NAME}} >> {{.CHECKSUM_FILE}}
241240
242241
vars:

Diff for: README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ This code is licensed under the terms of the GNU Affero General Public License v
77

88
### Requirements
99

10-
This is all you need to use arduino-cloud-cli for device **provisioning**:
10+
This is all you need to use arduino-cloud-cli:
1111
* A client ID and a secret ID, retrievable from the [cloud](https://create.arduino.cc/iot/integrations) by creating a new API key
12-
* The folder containing the precompiled provisioning firmwares (`binaries`) needs to be in the same location you run the command from
1312

1413
### Additional info
1514

Diff for: binaries/arduino.mbed_nano.nanorp2040connect.elf

-3.91 MB
Binary file not shown.

Diff for: binaries/arduino.mbed_portenta.envie_m7.bin

-533 KB
Binary file not shown.

Diff for: binaries/arduino.samd.mkr1000.bin

-111 KB
Binary file not shown.

Diff for: binaries/arduino.samd.mkrgsm1400.bin

-143 KB
Binary file not shown.

Diff for: binaries/arduino.samd.mkrnb1500.bin

-111 KB
Binary file not shown.

Diff for: binaries/arduino.samd.mkrwifi1010.bin

-80.1 KB
Binary file not shown.

Diff for: binaries/arduino.samd.nano_33_iot.bin

-79.9 KB
Binary file not shown.

Diff for: binaries/getdeveui.arduino.samd.mkrwan1300.bin

-16.4 KB
Binary file not shown.

Diff for: binaries/getdeveui.arduino.samd.mkrwan1310.bin

-17 KB
Binary file not shown.

Diff for: command/device/board.go

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// This file is part of arduino-cloud-cli.
2+
//
3+
// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
package device
19+
20+
import (
21+
"strings"
22+
23+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
24+
)
25+
26+
var (
27+
cryptoFQBN = []string{
28+
"arduino:samd:nano_33_iot",
29+
"arduino:samd:mkrwifi1010",
30+
"arduino:mbed_nano:nanorp2040connect",
31+
"arduino:mbed_portenta:envie_m7",
32+
"arduino:samd:mkr1000",
33+
"arduino:samd:mkrgsm1400",
34+
"arduino:samd:mkrnb1500",
35+
}
36+
loraFQBN = []string{
37+
"arduino:samd:mkrwan1310",
38+
"arduino:samd:mkrwan1300",
39+
}
40+
)
41+
42+
// board contains details of a physical arduino board
43+
type board struct {
44+
fqbn string
45+
serial string
46+
dType string
47+
port string
48+
}
49+
50+
// isCrypto checks if the board is a valid arduino board with a
51+
// supported crypto-chip
52+
func (b *board) isCrypto() bool {
53+
for _, f := range cryptoFQBN {
54+
if b.fqbn == f {
55+
return true
56+
}
57+
}
58+
return false
59+
}
60+
61+
// isCrypto checks if the board is a valid LoRa arduino board
62+
func (b *board) isLora() bool {
63+
for _, f := range loraFQBN {
64+
if b.fqbn == f {
65+
return true
66+
}
67+
}
68+
return false
69+
}
70+
71+
// boardFromPorts returns a board that matches all the criteria
72+
// passed in. If no criteria are passed, it returns the first board found.
73+
func boardFromPorts(ports []*rpc.DetectedPort, params *CreateParams) *board {
74+
for _, port := range ports {
75+
if portFilter(port, params) {
76+
continue
77+
}
78+
boardFound := boardFilter(port.Boards, params)
79+
if boardFound != nil {
80+
b := &board{
81+
fqbn: boardFound.Fqbn,
82+
serial: port.SerialNumber,
83+
dType: strings.Split(boardFound.Fqbn, ":")[2],
84+
port: port.Address,
85+
}
86+
return b
87+
}
88+
}
89+
90+
return nil
91+
}
92+
93+
// portFilter filters out the given port in the following cases:
94+
// - if the port parameter does not match the actual port address.
95+
// - if the the detected port does not contain any board.
96+
// It returns:
97+
// true -> to skip the port
98+
// false -> to keep the port
99+
func portFilter(port *rpc.DetectedPort, params *CreateParams) bool {
100+
if len(port.Boards) == 0 {
101+
return true
102+
}
103+
if params.Port != nil && *params.Port != port.Address {
104+
return true
105+
}
106+
return false
107+
}
108+
109+
// boardFilter looks for a board which has the same fqbn passed as parameter.
110+
// If fqbn parameter is nil, then the first board found is returned.
111+
// It returns:
112+
// - a board if it is found.
113+
// - nil if no board matching the fqbn parameter is found.
114+
func boardFilter(boards []*rpc.BoardListItem, params *CreateParams) (board *rpc.BoardListItem) {
115+
if params.Fqbn == nil {
116+
return boards[0]
117+
}
118+
for _, b := range boards {
119+
if b.Fqbn == *params.Fqbn {
120+
return b
121+
}
122+
}
123+
return
124+
}
File renamed without changes.

Diff for: command/device/create.go

+10-60
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ package device
2020
import (
2121
"errors"
2222
"fmt"
23-
"strings"
2423

25-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2624
"github.com/arduino/arduino-cloud-cli/arduino/cli"
2725
"github.com/arduino/arduino-cloud-cli/internal/config"
2826
"github.com/arduino/arduino-cloud-cli/internal/iot"
@@ -37,13 +35,6 @@ type CreateParams struct {
3735
Fqbn *string // Board FQBN - Optional - If omitted then the first device found gets selected
3836
}
3937

40-
type board struct {
41-
fqbn string
42-
serial string
43-
dType string
44-
port string
45-
}
46-
4738
// Create command is used to provision a new arduino device
4839
// and to add it to Arduino IoT Cloud.
4940
func Create(params *CreateParams) (*DeviceInfo, error) {
@@ -62,6 +53,16 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
6253
return nil, err
6354
}
6455

56+
if !board.isCrypto() {
57+
return nil, fmt.Errorf(
58+
"board with fqbn %s found at port %s is not a device with a supported crypto-chip.\n"+
59+
"Try the 'create-lora' command instead if it's a LoRa device"+
60+
" or 'create-generic' otherwise",
61+
board.fqbn,
62+
board.port,
63+
)
64+
}
65+
6566
conf, err := config.Retrieve()
6667
if err != nil {
6768
return nil, err
@@ -104,54 +105,3 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
104105
}
105106
return devInfo, nil
106107
}
107-
108-
// boardFromPorts returns a board that matches all the criteria
109-
// passed in. If no criteria are passed, it returns the first board found.
110-
func boardFromPorts(ports []*rpc.DetectedPort, params *CreateParams) *board {
111-
for _, port := range ports {
112-
if portFilter(port, params) {
113-
continue
114-
}
115-
boardFound := boardFilter(port.Boards, params)
116-
if boardFound != nil {
117-
t := strings.Split(boardFound.Fqbn, ":")[2]
118-
b := &board{boardFound.Fqbn, port.SerialNumber, t, port.Address}
119-
return b
120-
}
121-
}
122-
123-
return nil
124-
}
125-
126-
// portFilter filters out the given port in the following cases:
127-
// - if the port parameter does not match the actual port address.
128-
// - if the the detected port does not contain any board.
129-
// It returns:
130-
// true -> to skip the port
131-
// false -> to keep the port
132-
func portFilter(port *rpc.DetectedPort, params *CreateParams) bool {
133-
if len(port.Boards) == 0 {
134-
return true
135-
}
136-
if params.Port != nil && *params.Port != port.Address {
137-
return true
138-
}
139-
return false
140-
}
141-
142-
// boardFilter looks for a board which has the same fqbn passed as parameter.
143-
// If fqbn parameter is nil, then the first board found is returned.
144-
// It returns:
145-
// - a board if it is found.
146-
// - nil if no board matching the fqbn parameter is found.
147-
func boardFilter(boards []*rpc.BoardListItem, params *CreateParams) (board *rpc.BoardListItem) {
148-
if params.Fqbn == nil {
149-
return boards[0]
150-
}
151-
for _, b := range boards {
152-
if b.Fqbn == *params.Fqbn {
153-
return b
154-
}
155-
}
156-
return
157-
}

0 commit comments

Comments
 (0)