Skip to content

Use Travis CI for automated testing #1

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

Closed
wants to merge 5 commits into from
Closed

Use Travis CI for automated testing #1

wants to merge 5 commits into from

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented May 17, 2019

Travis CI is used to run the following tests on the repository after every commit or pull request:

  • Compile all example sketches for MKR Zero using the latest version of arduino-cli.
  • Use TravisBuddy to automatically comment on pull requests that result in a failed Travis CI build.
  • Check all code files for compliance with the Arduino code formatting style.
  • Check for commonly misspelled words.

The file extras/codespell-ignore-words-list.txt is used in case of false positives during the check for commonly misspelled words (all words in the file are ignored by codespell).

@sandeepmistry
Copy link
Contributor

Hi @per1234,

Thanks for opening this pull request!

I have a few things I think we should discuss as a team before we propagate to more libraries:

  1. Has the code style been formally agreed to? My understanding is it's used for sketches, but do we want to force it on libraries as well? @cmaglie @facchinm

If the plan is to enforce it, we could also consider a git precheck hook.

  1. extras/codespell-ignore-words-list.txt does it make sense to host this in a central Github repo and download it instead of one new file per repo?

@per1234
Copy link
Contributor Author

per1234 commented May 17, 2019

Has the code style been formally agreed to?

@lxrobotics and I set up the code style check in the ArduinoIoTCloud and ArduinoCloudThing repositories a month ago as somewhat of a trial and demonstration, then @lxrobotics made a proposal in the #core Slack channel that this be expanded to the rest of the library repositories. A week later, there were no objections and some nice "thumbs up", so I took that as an implicit approval to proceed. I know none of that counts as a formal agreement.

I think this is something that's really important to put in place. I also understand that it's a pretty significant change.

do we want to force it on libraries as well?

My opinion is that the same code style should be used consistently on all code that runs on microcontrollers (and perhaps even beyond that scope). I don't care what that style looks like; I just want there to be a standard. https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf is the closest thing Arduino has to an existing standard, though I understand it was not necessarily created with my usage in mind.

extras/codespell-ignore-words-list.txt does it make sense to host this in a central Github repo and download it instead of one new file per repo?

The advantage of that is avoiding cluttering up all the repositories with an extra file (and usually folder).

The disadvantage is that when you add a word to the ignore list to fix a false positive, you also increase the changes of a false negative. That word was on the list of commonly misspelled words for a reason. Sharing a common ignore list causes each ignored word to have a much larger scope than necessary.

A shared ignore list also means that someone whose PR introduces a false positive will need to submit a separate PR to the shared list repo and those two PRs will need to be coordinated (no need to merge the PR to the ignore words list if the PR that requires it is going to be rejected).

@aentinger
Copy link
Contributor

Hi @sandeepmistry,

As @per1234 mentioned there was my proposal within the core channel on Slack on 7th of May. As of today no one has objected to the proposal (and quite a few people have thumbed it up). I'd consider this an implicit agreement. However, if you feel that further discussion is necessary than by all means let's have one - on Slack which would be im my opinion the better medium for this discussion.

per1234 added 5 commits May 22, 2019 06:12
Travis CI will compile each of the example sketches MKR Zero using the latest release of arduino-cli every time someone commits to the repository or submits a pull request.
TravisBuddy automatically comments on any pull request that results in a failed Travis CI build. This will cause the author of the pull request to get a notification of the failure and asking them to check the build results to see if they can fix the problem. The hope is that this will result in more pull requests that are valid before a maintainer needs to get involved. It also makes it easier on the pull request author because they don't need to remember to come back to the repository to check the CI build result.
The Artistic Style formatter tool was used with the https://raw.githubusercontent.com/arduino/Arduino/master/build/shared/examples_formatter.conf configuration to format all code in the repository.

I did not touch the files in src/minmea because this appears to be an external resource.
Use the Artistic Style formatting tool (also used for the Arduino IDE's auto format feature) to check all code files in the repository for compliance with the Arduino code formatting style.

I excluded src/minmea from the check because this appears to be an external resource.
Use codespell to check for commonly misspelled words during the Travis CI build. In the event of false positives, the words can be added to extras/codespell-ignore-words-list.txt, after which codespell will ignore those words.

I excluded src/minmea from the check because this appears to be an external resource.
@sandeepmistry
Copy link
Contributor

Some more thoughts on this:

  • We definitely need to agree on a code style, the examples_formatter.conf used currently in this pull request definitely looks like it wasn't intended for libraries based on file name. I think the newly agreed to config file should live in a new repo. We could also possibly extract the code style from existing libraries and cores in order to minimize changes.
  • We should also identify ways to make a contributors/developers/maintainers life easier to adhere to the newly enforced rules (things like a .editorconfig file). Also, also carefully evaluate the pros/cons of enforcing these rules.
  • I'd also like to see a proposal on who/how the new infrastructure will be maintained and if there's any way to stream line it. For example, if the Travis CI config needs to be updated across every repo inside the arduino-libraries org, what's the process and impact like.

So overall, it's a good direction to go in, but we should take it slow, and also I think we have higher priority things to work on at the moment.

cc/ @pnndra

@pnndra
Copy link

pnndra commented May 22, 2019

  • We definitely need to agree on a code style, the examples_formatter.conf used currently in this pull request definitely looks like it wasn't intended for libraries based on file name. I think the newly agreed to config file should live in a new repo. We could also possibly extract the code style from existing libraries and cores in order to minimize changes.

my understanding is that a code style was already in place based on what i heard from simone/cristian. if it isn't then we need to have it anyway.

  • We should also identify ways to make a contributors/developers/maintainers life easier to adhere to the newly enforced rules (things like a .editorconfig file). Also, also carefully evaluate the pros/cons of enforcing these rules.

i was proposing to have an initial period in which we just issue warnings, if possible, and enforce rules only after this grace period. of course we should have a document that explains how to run the code through a checker before committing, in order to prevent wasting time on files with formatting issues.

  • I'd also like to see a proposal on who/how the new infrastructure will be maintained and if there's any way to stream line it. For example, if the Travis CI config needs to be updated across every repo inside the arduino-libraries org, what's the process and impact like.

i think that, if possible, we should not include the file but rather reference it from a central git repo through a submodule. this would allow the file to propagate automatically everywhere.
if that is not possible for some reason we should have a script that automatically updates on all interested repos and we should have a way to list repos that need to be updated.

in terms of who is going to be responsible for this i think that at the moment alex and per are perfect candidates for this for the time being. as they will become busier and we'll have more people on board things may change.

So overall, it's a good direction to go in, but we should take it slow, and also I think we have higher priority things to work on at the moment.

cc/ @pnndra

having consistent code and documentation is really a priority as it is a metric for the quality of our products. also, this is sort of a starting test for introducing continuous integration more in general which also will be a crucial point to avoid regression

@SimonePDA
Copy link

Hi Dario, this is what I was referring to:

https://www.arduino.cc/en/Reference/APIStyleGuide

It was written by the Founder Tom Igoe and it is one of the pillars of Arduino.

It goes together with this other guide: https://www.arduino.cc/en/Reference/StyleGuide

These two documents and many others that give a clear picture on how things should be done can be found here:

https://www.arduino.cc/en/Hacking/HomePage

The specific link https://www.arduino.cc/en/Hacking/LibraryTutorial will let you to the above mentioned links and provides some information on how we ask our contributors to write the libraries.

I hope this gives some more clues on how things should be done to keep the essence of Arduino consistent throughout the new libraries and documentation.

Simone

@per1234
Copy link
Contributor Author

per1234 commented May 22, 2019

i was proposing to have an initial period in which we just issue warnings

I can easily use Travis CI's allow_failures feature to make it so a failure of the formatting check job will not cause the CI build to fail. However, the formatting issues will need to be fixed after the initial period passes anyway so it might make more sense to leave it as is. The CI build's failure would be part of the warning to the contributor. A maintainer may fix the formatting for the contributor to get a passing build if necessary. To me, it makes the most sense to ensure all incoming commits have compliant formatting so the only bulk format that ever happens is the initial one when the formatting check is added to the repository.

we should have a document that explains how to run the code through a checker before committing, in order to prevent wasting time on files with formatting issues.

I'm happy to help with that. The Arduino IDE's Auto Format can easily be customized. I know how to integrate Artistic Style into Notepad++. I can provide an example of an astyle command to run from the command line or script to do the formatting on a project. I don't have any experience with setting up other editors/IDEs for auto formatting with Artistic Style, but I can investigate that if necessary.

I'm also working on a pre-commit Git hook for checking formatting compliance right now.

i think that, if possible, we should not include the file but rather reference it from a central git repo through a submodule. this would allow the file to propagate automatically everywhere.

By "the file", do you mean a script that contains a code formatting check function (and perhaps other generally useful functions)? That file could be downloaded or cloned from its dedicated repository during the CI build so a submodule wouldn't necessarily be needed.

i think that at the moment alex and per are perfect candidates for this for the time being

I'm happy to help out in any way I am able. I really enjoy working on this sort of thing and I have a good amount of experience using Travis CI.

https://www.arduino.cc/en/Reference/APIStyleGuide

Unfortunately, not much of that can be checked for automatically so it doesn't provide any guidance for this project. The only thing in that guide I could see possibly being checked automatically is camel case names, but Artistic Style doesn't do that. As I mentioned in arduino/ArduinoCore-avr#71 (comment), in addition to the Artistic Style configuration which defines the code formatting style, I'd like to see Arduino write a more detailed code style guide that contains additional guidelines.


I think the ArduinoIoTCloud and ArduinoCloudThing repositories can be used as a case study on this proposal. I'm not involved with the development work in those repositories, but from what I've seen from watching those repos it seems like it has been of benefit. I do think providing some documentation on how the developers can easily make their code comply with the standard would have been helpful.

@pnndra
Copy link

pnndra commented May 22, 2019

Thanks for the detailed response Simone. i will link these in the FT home page for future reference.

@pnndra
Copy link

pnndra commented May 22, 2019

@per1234 by the file i mean for example the travis files you committed in this repo. as @sandeepmistry mentioned it doesn't make sense to have the same things everywhere as if we need to change it we'll need to traverse many different repos.

@per1234
Copy link
Contributor Author

per1234 commented May 22, 2019

The files I added in this PR are extras/codespell-ignore-words-list.txt and .travis.yml.

Regarding extras/codespell-ignore-words-list.txt, I think it's reasonable to share a single file, but there are some disadvantages, which I listed above. I think there is much benefit to sharing the codespell ignore list from a maintenance standpoint. I don't foresee it being common for the same false positives to occur across many repositories. The benefit of sharing the file is to avoid adding an additional file to the repository, and that is persuasive to me.

Regarding .travis.yml, each repository will need to have a somewhat different configuration (e.g., which boards are used, which examples are compiled for which boards, which folders are excluded from the code formatting check). It should be possible to define those differences in a separate file which is unique to each repository. Adafruit does something like this in their libraries by using flag files in the example sketch folders to control which boards they are compiled for during the CI build:
https://github.com/adafruit/travis-ci-arduino#skipping-platforms
but that seems a bit messy to me.

I think it would be quite difficult to use a submodule for .travis.yml. A submodule will be a subfolder of the repository, but .travis.yml must be in the root of the repository. Perhaps this could be gotten around using a symlink but the Library Manager indexer doesn't accept any library that contains a symlink. I suppose an exception could be added to the indexer to allow symlinks in the libraries from the arduino-libraries repos, but then we would be setting a bad example for the 3rd party library authors who use Arduino's libraries as a model but would be subject to different Library Manager requirements. Your suggestion of automatically updating the .travis.yml file in all repositories using a script would be the better option.

@aentinger
Copy link
Contributor

Well, I'm glad we've got the discussion going 😃 I agree with @per1234 that it does not make sense to have a global .travis.yml contained within a submodule. .travis.yml is and will always be specific for each repository, additionally there is no good way of getting the .travis.yml out of the submodule and into the top level directory where it is required by the Travis CI service (As I have learned the hard way, symbolic links are not looked kindly upon by our Jenkins.). That being said it would make a lot of sense to provide a certain "CI" functionality via scripts shared between all repositories via submodule and utilized by the .travis.yml build script. This way we reduce code duplication as well as maintenance effort.

The astyle configuration file examples_formatter.conf we are using within this PR (and also within ArduinoIoTCloud and ArduinoCloudThing) is retrieved from its location within the Arduino IDE github repository via wget during each CI build. This means that a change to this file will automatically affect all repositories using it. The wget approach outperforms git submodule in terms of necessary maintainance effort since there isn't even a submodule update necessary to automatically propagate changes in the configuration file to all CI builds. Needless to say, changes to this file should be few and done with great care.

Furthermore I'd like to point out that the Arduino IDE itself uses formatter.conf for its auto-format functionality which is a slightly less restrictive version of examples_formatter.conf. With the Arduino libraries/examples setting the example for users looking to extend and contribute I consider it a good idea to subject ourselves to a higher standard. As a last point I want to add that formatter.conf and examples_formatter.conf have been in usage unchanged for quite some time already, are known to developers, users and contributors which is why I consider them as the perfect starting point for a unified code appearance across all Arduino code.

@pnndra
Copy link

pnndra commented May 23, 2019

thanks for the clarifications. once we have this nailed up i would suggest to add some of this detail to confluence so that everyone knows how to set up properly repositories.
thanks,

Dario

@per1234
Copy link
Contributor Author

per1234 commented Jun 4, 2019

Here's an example of why it's important for Arduino to use an official code style standard and have an automated check for compliance:
https://github.com/arduino-libraries/WiFiNINA/blob/master/src/WiFi.cpp
Use an editor or browser extension that shows tabs and spaces and take a look at that file. It looks like there was a war between tabs and spaces and everyone lost. We have 4 space indents, 3 space indents, 2 space indents, tab indents, random mixtures of tab and space indents. I see this sort of thing often in Arduino's code.

Any conscientious contributor will want to follow the existing code style of the file they're working in. They would waste a lot of time trying to determine what the prevailing style is in that file and eventually give up and pick something at random.

We currently have a PR where the contributor added some functions to the file and decided on two space indents:
https://github.com/arduino-libraries/WiFiNINA/pull/63/files#diff-e9f196d8fa89bd51343151d8af2220bf
That matches very little of the existing style used in the file, but I suppose it's as good a choice as any.

@per1234
Copy link
Contributor Author

per1234 commented Jun 16, 2019

I wrote a script for the code formatting check that can be shared between all of Arduino's CI configurations:
https://github.com/per1234/ci-resources/blob/master/check-code-formatting.sh

I prepared a demonstration of it in use in a Travis CI configuration here:
https://github.com/per1234/Arduino_MKRGPS/blob/add-travis-CI-demo/.travis.yml#L31-L40

Regarding the codespell ignore words list, I have changed to specifying this directly in the codespell command as a comma-separated list using the --ignore-words-list= option. That way, each repository can have a custom ignore words list without having to add a new file.
https://github.com/per1234/Arduino_MKRGPS/blob/add-travis-CI-demo/.travis.yml#L54

I wrote Git hooks for both the code formatting check and codespell here:
https://github.com/per1234/git-hooks/

I welcome any feedback on these proposed solutions to the concerns regarding this PR.

@per1234
Copy link
Contributor Author

per1234 commented Jul 23, 2019

There have been no objections to the solution I proposed in my last reply after over a month so I'd like to try to move forward with this. To do that, I'll need someone to create a repository for the CI helper script. For my demonstration, I named this repository "ci-resources" with the idea that it might later be used to contain other resources for CI builds to share, but you're welcome to pick any name you like. I think the arduino organization would be the best place for the repository, since the contents of the repository might well be used for more than only testing of Arduino libraries in time. Once that repository is created, I can submit a pull request to add my script.

@sandeepmistry
Copy link
Contributor

Please note my feedback above (#1 (comment), #1 (comment)) has not fully been addressed yet.

@per1234
Copy link
Contributor Author

per1234 commented Jul 24, 2019

I guess you mean this:

Has the code style been formally agreed to? My understanding is it's used for sketches, but do we want to force it on libraries as well?

and this:

We definitely need to agree on a code style, the examples_formatter.conf used currently in this pull request definitely looks like it wasn't intended for libraries based on file name. I think the newly agreed to config file should live in a new repo. We could also possibly extract the code style from existing libraries and cores in order to minimize changes.

I haven't seen any disagreement to it in the 3.5 months since I implemented it in the ArduinoIoTCloud and ArduinoCloudThing repositories, the 2.5 months since Alexander proposed it on Slack, or the >2 months since I opened this PR. Earnest efforts have been made to bring it to the attention of interested parties and they have been given plenty of time to comment. I feel that in the real world this is as close as it gets to the formal agreement you want.

We have an existing well defined code style that has been in use for Arduino sketches for years and works perfectly fine. Why not use the one we already have and move on to more important things than talking about how many spaces are in an indent?

It makes no sense to me for Arduino to have one code style for sketches and another for libraries. Changing the code style in the sketches would be disruptive to the users and require a lot of work to update documentation. It would cause a style mismatch with the many existing tutorials that use Arduino examples but are not in Arduino's control to update. Using the established sketch code style in library code just seems like the logical way to proceed.

@facchinm
Copy link

My 2 cents:
reformatting the style of every cpp file makes git blame useless, so I would avoid it as much as possible for existing libraries.
If we had an editor configuration file all new libraries will start in a good shape so we could enforce the automatic formatting on them.
About spellcheck I'm totally fine, and also removing whitespaces looks more than reasonable.

@per1234
Copy link
Contributor Author

per1234 commented Jul 24, 2019

So there are a few things that are unresolved:

Should existing code be formatted?

The only statement specifically against doing this so far is from @facchinm, though @sandeepmistry's comment "We could also possibly extract the code style from existing libraries and cores in order to minimize changes." is related.

I disagree with the argument that it "makes git blame useless". It doesn't make it useless, it only makes it slightly less convenient due to introducing a commit that doesn't have any functional effect on the code. You can still go back one commit in the history to get the blame previous to the formatting commit.

In a previous discussion about formatting the Arduino AVR Boards code, the concern was raised that it will cause merge conflicts in pull requests. (arduino/ArduinoCore-avr#71 (comment))

Even if the decision is made to not format or enforce a code style on existing code, it is still worthwhile to establish an official Arduino code style to use on all future code.

What should the official Arduino code style be?

There has been no specific disagreement to using the code style defined in examples_formatter.conf so far.

@sandeepmistry's statement "We could also possibly extract the code style from existing libraries and cores in order to minimize changes." could be considered a counter proposal.

How can a formal agreement be reached on the official Arduino code style?

Would we need to make a list of interested parties and wait for all of them to make a statement in favor of the chosen code style before it's considered a formal agreement?

I appreciate the democratic approach, but I also think there's a time for executive decisions when running a company. The organizational chart indicates that @pnndra is the person who has final say in this.

@pnndra
Copy link

pnndra commented Jul 25, 2019

here i am with some guidance. after some discussion with @mbanzi @facchinm and @sandeepmistry there seems to be consensus on a number of things:

  1. we don't necessarily need to enforce the same code style on sketches and libraries
  2. running automated code formatter on the libraries would create a breaking point for PRs and for blames that would cross such boundary as even ignoring whitespace changes there would be a number of other changes which would make it difficult to make comparisons
  3. more or less no one of us really cares about which style to use as for sure the one we chose will upset someone. Sandeep suggested we try to use the most common style across the libraries so that any future enforcement will cause minimal impact and i totally agree with him. not only this will basically end up being a consensus based choice, it will also minimize the impact of the "breaking point" when we apply it.
  4. we all agree that it makes sense to enforce rules at some point but for sure we need to act gradually in order not to break too much at once.

having said this i would request @per1234 to summarize in a spreadsheet the state for all our libraries listing the number of commits, branches, forks and open PRs. while doing this it would make sense to summarize the conding style for each repo, possibly categorizing it so that we can later look at the spreadsheet and weight our choice based on the most used style weighted by library popularity (commits, PRs, etc).
note that in terms of coding style i would not insist too much on finer details... likely we can just settle for tabs vs spaces and braces location other than of course API conventions. long term it would be nice to enforce variable and function naming conventions but i don't think we should even try to refactor existing code for this.
it would also make sense to have a report on the open PRs to understand which of these can be merged, which need discussion and which need to be rejected and we could use this also as a tool to re-engage with community and spark new activity around the libraries.

once we have this job done (please @per1234 let me have a time estimate for this), we can set up the style rules and start enforcing them on all "new" libraries, with small number of commits and PRs. regarding more popular libraries we can create a new master branch and set it as default while keeping the old master branch which will keep the PRs attached. this will allow transitioning to the clean files without losing the history and without upsetting everyone. of course we'll be encouraging community to migrate PRs to the new master so that they can be merged.

i apologize with @cmaglie for not consulting him but hope he agrees with this approach and would like to see this topic closed asap as hopefully we'll be engaging more and more with community and the earliest we fix this, the less work we'll have to do to amend work done.

@per1234
Copy link
Contributor Author

per1234 commented Jul 26, 2019

I'm approximately half finished with the libraries spreadsheet. I estimate I will finish it tomorrow.

@per1234
Copy link
Contributor Author

per1234 commented Jul 28, 2019

Here's the libraries spreadsheet:
https://gist.github.com/per1234/b425a2ef7f9ed7d2db4ddb9ae68c2212

I tried to skip over the files of any external libraries bundled with the Arduino libraries, as it probably is best to only modify those files upstream. In some cases it was difficult to determine what was and wasn't to be considered an external library.

In many cases, the coding style was not consistent throughout each library's code. I indicated this by adding "(mixed)" to the cell. In these cases, I estimated what was the predominant style of the library.


Unweighted results for the predominant styles:

Indent

  • 2 spaces: 59%
  • tab: 24%

Braces attached to function definition

  • no: 61%
  • yes: 35%

Braces attached to statement

  • yes: 81%
  • no: 13%

else attached to closing brace

  • yes: 60%
  • no: 18%

weighted (by commits, stars, forks, and PRs) results for the predominant styles:

Indent

  • 2 spaces: 45%
  • tab: 32%

Braces attached to function definition

  • no: 59%
  • yes: 40%

Braces attached to statement

  • yes: 81%
  • no: 15%

else attached to closing brace

  • yes: 61%
  • no: 19%

Percentages don't sum to 100% due to the existence of other indentation styles, libraries where I couldn't decipher a predominant style, or lack of data.

I didn't include the bundled libraries in the weighted results because I didn't know how to do the weighting for them. They are included in the unweighted results.

Note that with the exception of "Braces attached to function definition", these match the examples_formatter.conf code style.

@pnndra
Copy link

pnndra commented Jul 28, 2019

Great job @per1234. Thank you for accomplishing it in such short time. At first look it seems like there's a clear prevalence of style even if there are some borderline situations on indent and braces. I'll review closely the data with @facchinm and decide how to move forward.

@per1234
Copy link
Contributor Author

per1234 commented Sep 2, 2019

I created a script with functions for the common actions used for compilation testing and added it to the same repository that contains the code formatting script. The idea is to reduce code duplication by sharing these functions between all CI configurations:
https://github.com/per1234/ci-resources/blob/master/compilation-test.sh

I've updated my demonstration .travis.yml file to use them as well as the shared code formatting check script:
https://github.com/per1234/Arduino_MKRGPS/blob/add-travis-CI-demo/.travis.yml

Any contributions to improve those functions or suggestions for additional functions to add are welcome.

@aentinger
Copy link
Contributor

Thank you very much for preparing a collection of scripts to be reused across all repositories. In my opinion there is all the functionality present which we use within the regular CI build but either rewrite it manually or copy from project to project. Good work 👍

@aentinger
Copy link
Contributor

Closing, shall be replaced by GitHub Action based CI (#10).

@aentinger aentinger closed this Feb 11, 2021
@per1234 per1234 added type: enhancement Proposed improvement conclusion: declined Will not be worked on topic: infrastructure Related to project infrastructure labels Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: declined Will not be worked on topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants