Skip to content

Commit 6e7e8d1

Browse files
masciper1234
andauthored
Use goreleaser to build the full binary matrix (#311)
* use crossbuild as base image * add drone step * add how to contribute * Update CONTRIBUTING.md Co-Authored-By: per1234 <[email protected]>
1 parent f3efd0c commit 6e7e8d1

File tree

6 files changed

+384
-101
lines changed

6 files changed

+384
-101
lines changed

Diff for: .drone.yml

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
---
12
kind: pipeline
2-
name: default
3+
name: test
34

45
steps:
56
- name: lint
67
image: arduino/arduino-cli:drone-1.0
78
commands:
89
# Check if the Go code is properly formatted and run the linter
910
- task check
10-
# Ensure protobufs compile
11+
# Ensure protobufs compile without errors
1112
- task protoc
1213

1314
- name: build
@@ -27,10 +28,10 @@ steps:
2728
- pip install -r test/requirements.txt
2829
- task test-integration
2930

30-
# Contrary to other CI platforms, uploading reports to Codecov requires Drone to provide a token.
31-
# To avoid exposing the Codecov token to external PRs, we only upload coverage when we merge on
32-
# `master`.
3331
- name: coverage
32+
# Contrary to other CI platforms, uploading reports to Codecov requires Drone to provide a token.
33+
# To avoid exposing the Codecov token to external PRs, we only upload coverage when we merge on
34+
# `master`.
3435
image: arduino/arduino-cli:drone-1.0
3536
environment:
3637
CODECOV_TOKEN:
@@ -43,3 +44,38 @@ steps:
4344
- master
4445
event:
4546
- push
47+
48+
---
49+
kind: pipeline
50+
name: release
51+
52+
steps:
53+
- name: fetch
54+
# extra step needed to fetch tags after cloning
55+
image: docker:git
56+
commands:
57+
- git fetch --tags
58+
59+
- name: release
60+
image: arduino/arduino-cli:builder-0.1
61+
environment:
62+
GITHUB_TOKEN:
63+
from_secret: github_token
64+
commands:
65+
- goreleaser
66+
67+
trigger:
68+
event:
69+
# releases are triggered by tags only
70+
- tag
71+
status:
72+
# skip the release if the previous build failed
73+
- success
74+
ref:
75+
exclude:
76+
# exclude the tags used to build Docker images for drone
77+
- refs/tags/builder-*
78+
- refs/tags/drone-*
79+
80+
depends_on:
81+
- test

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ coverage_*.txt
1010
__pycache__
1111
venv
1212
.pytest_cache
13+
/dist

Diff for: .goreleaser.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Global section
2+
checksum:
3+
name_template: 'checksums.txt'
4+
5+
snapshot:
6+
name_template: "{{ .Tag }}-next"
7+
8+
changelog:
9+
sort: asc
10+
filters:
11+
exclude:
12+
- '^[skip changelog]'
13+
14+
# We have multiple builds in order to fine tune
15+
# cross compilations.
16+
builds:
17+
-
18+
# OSX
19+
id: arduino_cli_osx
20+
binary: arduino-cli
21+
env:
22+
- CGO_ENABLED=1
23+
- CXXFLAGS="-mmacosx-version-min=10.10"
24+
- CC=/usr/x86_64-apple-darwin14/bin/cc
25+
goos:
26+
- darwin
27+
goarch:
28+
- amd64
29+
ldflags:
30+
- -s -w -X github.com/arduino/arduino-cli/version.versionString={{.Tag}} -X github.com/arduino/arduino-cli/version.commit=={{ .ShortCommit }}
31+
-
32+
# ARM
33+
id: arduino_cli_arm
34+
binary: arduino-cli
35+
env:
36+
- CGO_ENABLED=1
37+
- CC=/usr/arm-linux-gnueabihf/bin/cc
38+
goos:
39+
- linux
40+
goarch:
41+
- arm
42+
goarm:
43+
- 7
44+
ldflags:
45+
- -s -w -X github.com/arduino/arduino-cli/version.versionString={{.Tag}} -X github.com/arduino/arduino-cli/version.commit=={{ .ShortCommit }}
46+
- "-extldflags '-static'"
47+
-
48+
# ARM64
49+
id: arduino_cli_arm64
50+
binary: arduino-cli
51+
env:
52+
- CGO_ENABLED=1
53+
- CC=/usr/aarch64-linux-gnu/bin/cc
54+
goos:
55+
- linux
56+
goarch:
57+
- arm64
58+
ldflags:
59+
- -s -w -X github.com/arduino/arduino-cli/version.versionString={{.Tag}} -X github.com/arduino/arduino-cli/version.commit=={{ .ShortCommit }}
60+
- "-extldflags '-static'"
61+
-
62+
# All the other platforms
63+
id: arduino_cli
64+
binary: arduino-cli
65+
env:
66+
- CGO_ENABLED=0
67+
goos:
68+
- linux
69+
- windows
70+
goarch:
71+
- amd64
72+
- 386
73+
ldflags:
74+
- -s -w -X github.com/arduino/arduino-cli/version.versionString={{.Tag}} -X github.com/arduino/arduino-cli/version.commit=={{ .ShortCommit }}
75+
- "-extldflags '-static'"
76+
77+
archives:
78+
-
79+
id: "arduino_cli"
80+
format: tar.gz
81+
format_overrides:
82+
- goos: windows
83+
format: zip
84+
replacements:
85+
amd64: 64bit
86+
darwin: macOS
87+
386: 32bit
88+
arm: ARM
89+
arm64: ARM64
90+
linux: Linux
91+
windows: Windows
92+
files:
93+
- README.md
94+
- LICENSE.txt

Diff for: CONTRIBUTING.md

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# How to contribute
2+
3+
First of all, thanks for contributing!
4+
5+
This document provides some basic guidelines for contributing to this repository. To propose
6+
improvements or fix a bug, feel free to submit a PR.
7+
8+
## Legal requirements
9+
10+
Before we can accept your contributions you have to sign the [Contributor License Agreement][0]
11+
12+
## Prerequisites
13+
14+
To build the Arduino CLI from sources you need the following tools to be available in your local
15+
enviroment:
16+
17+
* [Go][1] version 1.12 or later
18+
* [Taskfile][2] to help you run the most common tasks from the command line
19+
20+
If you want to run integration tests you will also need:
21+
22+
* A serial port with an Arduino device attached
23+
* A working [Python][3] environment, version 3.5 or later
24+
25+
## Building the source code
26+
27+
From the project folder root, just run:
28+
29+
```shell
30+
task build
31+
```
32+
33+
The project uses Go modules so dependencies will be downloaded automatically, you should end with
34+
an `arduino-cli` executable in the same folder.
35+
36+
## Running the tests
37+
38+
There are several checks and test suites in place to ensure the code works as expected but also it
39+
is written in a way that's consistent across the whole codebase. Such tests can be run one after
40+
another by running the command:
41+
42+
```shell
43+
task test
44+
```
45+
46+
If you want to only run unit tests and skip other checks, you can run:
47+
48+
```shell
49+
task test-unit
50+
```
51+
52+
Similarly, if you're only interested in running integration tests, you can do (be sure to read the
53+
part dedicated to integration tests if something doesn't work):
54+
55+
```shell
56+
task test-integration
57+
```
58+
59+
### Integration tests
60+
61+
Being a command line interface, Arduino CLI is heavily interactive and it has to stay consistent
62+
in accepting the user input and providing the expected output and proper exit codes. On top of this,
63+
many Arduino CLI features involve communicating with external devices, most likely through a serial
64+
port, so unit tests can only put our confidence that the code is working so far.
65+
66+
For these reasons, in addition to regular unit tests the project has a suite of integration tests
67+
that actually run Arduino CLI in a different process and assess the options are correctly
68+
understood and the output is what we expect.
69+
70+
To run the full suite of integration tests you need an Arduino device attached to a serial port and
71+
a working Python environment. Chances are that you already have Python installed in your system, if
72+
this is not the case you can [download][3] the official distribution or use the package manager
73+
provided by your Operating System.
74+
75+
Some dependencies need to be installed before running the tests and to avoid polluting your global
76+
Python enviroment with dependencies that might be only used by the Arduino CLI, you can use a
77+
[virtual environment][4]. There are many ways to manage virtual environments, for example you can
78+
use a productivity tool called [hatch][5]. First you need to install it (you might need to `sudo`
79+
the following command):
80+
81+
```shell
82+
pip3 install --user hatch
83+
```
84+
85+
Then you can create a virtual environment to be used while working on Arduino CLI:
86+
87+
```shell
88+
hatch env arduino-cli
89+
```
90+
91+
At this point the virtual environment was created and you need to make it active every time you
92+
open a new terminal session with the following command:
93+
94+
```shell
95+
hatch shell arduino-cli
96+
```
97+
98+
From now on, every package installed by Python will be confined to the `arduino-cli` virtual
99+
environment, so you can proceed installing the dependencies required with:
100+
101+
```shell
102+
pip install -r test/requirements.txt
103+
```
104+
105+
If the last step was successful, you should be able to run the tests with:
106+
107+
```shell
108+
task test-integration
109+
```
110+
111+
## Pull Requests
112+
113+
In order to ease code reviews and have your contributions merged faster, here is a list of items
114+
you can check before submitting a PR:
115+
116+
* Create small PRs that are narrowly focused on addressing a single concern.
117+
* PR titles indirectly become part of the CHANGELOG so it's crucial to provide a good
118+
record of **what** change is being made in the title; **why** it was made will go in the
119+
PR description, along with a link to a GitHub issue if it exists.
120+
* Write tests for the code you wrote.
121+
* Open your PR against the `master` branch.
122+
* Maintain **clean commit history** and use **meaningful commit messages**.
123+
PRs with messy commit history are difficult to review and require a lot of work to be merged.
124+
* Your PR must pass all CI tests before we will merge it. If you're seeing an error and don't think
125+
it's your fault, it may not be! The reviewer will help you if there are test failures that seem
126+
not related to the change you are making.
127+
128+
## Additional settings
129+
130+
If you need to push a commit that's only shipping documentation changes or example files, thus a
131+
complete no-op for the test suite, please start the commit message with the string **[skip ci]**
132+
to skip the build and give that slot to someone else who does need it.
133+
134+
If your PR doesn't need to be included in the changelog, please start the PR title with the string
135+
**[skip changelog]**
136+
137+
[0]: https://cla-assistant.io/arduino/arduino-cli
138+
[1]: https://golang.org/doc/install
139+
[2]: https://taskfile.dev/#/installation
140+
[3]: https://www.python.org/downloads/
141+
[4]: https://docs.python.org/3/tutorial/venv.html
142+
[5]: https://github.com/ofek/hatch

Diff for: Dockerfiles/builder/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM multiarch/crossbuild
2+
3+
ENV PATH $PATH:/usr/local/go/bin
4+
5+
# Install tooling
6+
ENV GORELEASER_VER 0.113.0
7+
ENV GORELEASER_SHA 2379beebb6369b75ccead7f7a43269de700b51821feae3857701d106ed72bd63
8+
ENV GOVER 1.12.7
9+
RUN set -ex \
10+
&& curl -o goreleaser.tar.gz -LO https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VER}/goreleaser_Linux_x86_64.tar.gz \
11+
&& echo "$GORELEASER_SHA goreleaser.tar.gz" | sha256sum -c - || exit 1 \
12+
&& tar -xzf goreleaser.tar.gz -C /usr/bin/ goreleaser \
13+
&& rm goreleaser.tar.gz \
14+
&& curl -LO https://dl.google.com/go/go${GOVER}.linux-amd64.tar.gz \
15+
&& tar -C /usr/local -xzf go${GOVER}.linux-amd64.tar.gz \
16+
&& rm go${GOVER}.linux-amd64.tar.gz

0 commit comments

Comments
 (0)