PeterWone / vscode-arduino-cli

Integration of the Arduino CLI into VS Code
Other
9 stars 2 forks source link

Continuous integration #3

Open PeterWone opened 4 years ago

PeterWone commented 4 years ago

Commits should trigger a build and run tests.

When we're properly set up each PR will branch, merge the PR into the branch then build and run tests as a first assessment of the contributed code.

Some guidance here https://code.visualstudio.com/api/working-with-extensions/continuous-integration#github-actions

PeterWone commented 4 years ago

@trullock @HEMISixty

I've built a clean Win10 VM and checkpointed it. As of half an hour ago I have powershell scripts that download and install Node, netcore31sdk, vscode and git and another checkpoint there.

My next step will be a script to clone the two repos (arduino-cli and serial-monitor) then write and test a script to build and package them.

While this is all directed at setting up continuous integration, it also forms a sound basis for instructions for the manual setup of one's build environment and configuration.

PeterWone commented 4 years ago

On a clean Win 10 box this will download and install Node, dotnet31sdk, vscode and git. I have another script that clones the two repos into

and builds self-contained serial-monitor images for win-x64, linux-x64, osx-x64. I'm still working on it though.

@ECHO OFF
CD \Users\User

IF NOT EXIST \build\NUL MKDIR \build
IF NOT EXIST SetupKits\NUL MKDIR SetupKits
cd SETUPKITS

ECHO.
ECHO Downloading GIT Client
curl -L https://github.com/git-for-windows/git/releases/download/v2.29.1.windows.1/Git-2.29.1-64-bit.exe -o Git-2.29.1-64-bit.exe
IF ERRORLEVEL 1 ECHO "GIT client download has failed."

ECHO.
ECHO Downloading DotNet Core Install Script
curl https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 -o dotnet-install.ps1
IF ERRORLEVEL 1 ECHO "DotNet Core Script download has failed."

ECHO.
ECHO Downloading Visual Studio Code
curl https://az764295.vo.msecnd.net/stable/d2e414d9e4239a252d1ab117bd7067f125afd80a/VSCodeUserSetup-x64-1.50.1.exe -o VSCodeUserSetup-x64-1.50.1.exe
IF ERRORLEVEL 1 ECHO "VS Code download has failed."

ECHO.
ECHO Downloading node.js
curl https://nodejs.org/dist/v12.19.0/node-v12.19.0-x64.msi -o node-v12.19.0-x64.msi
IF ERRORLEVEL 1 ECHO "node.js download has failed."

ECHO.
ECHO Downloading arduino-cli
curl -L https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip -o arduino-cli_latest_Windows_64bit.zip
IF ERRORLEVEL 1 ECHO "Arduino-cli download has failed."

ECHO Installing GIT
.\Git-2.29.1-64-bit.exe  /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS="icons,ext\reg\shellhere,assoc,assoc_sh"

ECHO.
ECHO Installing DOTNETCORE
PowerShell -Command { unblock-file dotnet-install.ps1 }
PowerShell -ExecutionPolicy bypass -Command .\dotnet-install.ps1 -Channel Current 

ECHO.
ECHO Installing VSCODE
.\VSCodeUserSetup-x64-1.50.1.exe /VERYSILENT /NORESTART /MERGETASKS=!runcode

ECHO.
ECHO Installing NODE
msiexec /i node-v12.19.0-x64.msi /qn
call "C:\Program Files\nodejs\nodevars.bat"
npm install --global gulp-cli

ECHO.
ECHO Installing arduino-cli
PowerShell Expand-Archive arduino-cli_latest_Windows_64bit.zip C:\build
PeterWone commented 4 years ago

This one

@ECHO OFF
path %path%;C:\build;C:\Program Files\Git\bin;C:\Users\User\AppData\Local\Microsoft\dotnet

ECHO.
ECHO Cloning \build\vscode-arduino-cli and \build\serial-monitor
pushd \build
md vscode-arduino-cli
md serial-monitor
git clone https://github.com/PeterWone/vscode-arduino-cli.git vscode-arduino-cli
git clone https://github.com/PeterWone/serial-monitor.git serial-monitor

ECHO.
ECHO PREPARE vscode-arduino-cli PACKAGE
pushd vscode-arduino-cli
call "C:\Program Files\nodejs\nodevars.bat"
call npm install
call gulp package
popd

ECHO.
ECHO PREPARE serial-monitor PACKAGES FOR LINUX, OSX, WIN
dotnet publish serial-monitor\serial-monitor.csproj -c Release --self-contained -r win-x64
dotnet publish serial-monitor\serial-monitor.csproj -c Release --self-contained -r linux-x64
dotnet publish serial-monitor\serial-monitor.csproj -c Release --self-contained -r osx-x64

ECHO .
ECHO DONE
popd

Next on my agenda is creating a docker container image on this.

PeterWone commented 4 years ago

@trullock @HEMISixty

The next step is to re-implement this using Docker and GitHub Actions so we can have Continuous Integration.

I know what Docker is but only loosely and currently without any real expertise. You know at least as much about it as I do, and we're about to learn a lot more.

I am under considerable pressure to focus on another project with large earning potential, but CICD is essential for team development. We'll start with Windows because we know how to fly it.

Once we know how to build the docker image and set up the pipeline, we need people with OSX and Linux expertise to create equivalent scripts. Actually now that I think about it, we may not need to implement these scripts on all OSs for CI because I produce all the artefacts for all platforms. However, if someone converted to Linux this would resolve the OS licence problem.

MrC74rk commented 4 years ago

Finally something I can help with! Gimme a day or so and I’ll get something together. I’m learning docker for work. I should be able to do this.

On Wed, Oct 28, 2020 at 18:40 Peter Wone notifications@github.com wrote:

@trullock https://github.com/trullock @HEMISixty https://github.com/HEMISixty

The next step is to re-implement this using Docker and GitHub Actions so we can have Continuous Integration.

I know what Docker is but only loosely and currently without any real expertise. You know at least as much about it as I do, and we're about to learn a lot more.

I am under considerable pressure to focus on another project with large earning potential, but CICD is essential for team development. We'll start with Windows because we know how to fly it. Once we know how to build the docker image and set up the pipeline, we need people with OSX and Linux expertise to create equivalent scripts.

Now would be a great time for them to start on adapting the above scripts to their platforms.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-718269926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7RRTKXUYLLHY35ODO3SNCTYPANCNFSM4S4QTYZA .

PeterWone commented 4 years ago

@MrC74rk outstanding. In the interim I shall look at porting the build scripts to Linux. If any of you know what you're doing with Linux feel free to rescue me from a public display of incompetence.

MrC74rk commented 4 years ago

Ok so it might be a little more than a day or so...I'm banging my head against the wall with Git Actions. I'll get it though.

On Thu, Oct 29, 2020 at 1:13 AM Peter Wone notifications@github.com wrote:

@MrC74rk https://github.com/MrC74rk outstanding. In the interim I shall look at porting the build scripts to Linux. If any of you know what you're doing with Linux feel free to rescue me from a public display of incompetence.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-718384227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7QFQ3VW3GPOLBC4L2DSNEBWXANCNFSM4S4QTYZA .

MrC74rk commented 4 years ago

Progress report. After a break and glass of whiskey, I was able to get the automation piece working. Git actions will spin up a docker, run a script that installs VS Code and close. I need to clean it up a bit and I still have to have the startup script install the required extensions before I do a PR.

Whew!

On Thu, Oct 29, 2020 at 2:16 PM Bryan A bryan.angelo@gmail.com wrote:

Ok so it might be a little more than a day or so...I'm banging my head against the wall with Git Actions. I'll get it though.

On Thu, Oct 29, 2020 at 1:13 AM Peter Wone notifications@github.com wrote:

@MrC74rk https://github.com/MrC74rk outstanding. In the interim I shall look at porting the build scripts to Linux. If any of you know what you're doing with Linux feel free to rescue me from a public display of incompetence.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-718384227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7QFQ3VW3GPOLBC4L2DSNEBWXANCNFSM4S4QTYZA .

PeterWone commented 4 years ago

@MrC74rk how's it going? I halted my own researches in anticipation of your triumph! Incidentally I've found a job which means I no longer have to search or interview but also I'm about to be busy again. So one way or another it's important to me to get this project on a sound footing quickly.

MrC74rk commented 4 years ago

Congratulations on the job!

I’ve triumphed pretty well, but I’m at a point where my lack of coding expertise is holding me up.

I need to figure out how to build the visx file and install it in the start up script. Then run the test. I’m hoping I can bang that out tomorrow.

On Fri, Oct 30, 2020 at 22:26 Peter Wone notifications@github.com wrote:

@MrC74rk https://github.com/MrC74rk how's it going? I halted my own researches in anticipation of your triumph! Incidentally I've found a job which means I no longer have to search or interview but also I'm about to be busy again. So one way or another it's important to me to get this project on a sound footing quickly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-719876549, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7Q2CKMBI3TLEC3N2X3SNN7YFANCNFSM4S4QTYZA .

PeterWone commented 4 years ago

I need to figure out how to build the visx file and install it in the start up script. Then run the test. I’m hoping I can bang that out tomorrow.

You don't need to work out how to build a VSIX. The scripts I pasted above will install the pre-requisites and produce not only the VSIX but also build the serial monitor for all three target platforms. The current script doesn't run the tests but I do know how to do that from the command line and the pre-requisites are already satisfied. I will post that part later today.

Or did you mean you need to figure out how to launch the above in the docker container?

MrC74rk commented 4 years ago

Oh that’s awesome! Then I should have a PR ready tomorrow as well!

On Fri, Oct 30, 2020 at 23:18 Peter Wone notifications@github.com wrote:

I need to figure out how to build the visx file and install it in the start up script. Then run the test. I’m hoping I can bang that out tomorrow.

You don't need to work out how to build a VSIX. The scripts I pasted above will install the pre-requisites and produce not only the VSIX but also build the serial monitor for all three target platforms. The current script doesn't run the tests but I do know how to do that from the command line and the pre-requisites are already satisfied. I will post that part later today.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-719881182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7WUOQRO5BO2XCHHZMLSNOFX3ANCNFSM4S4QTYZA .

PeterWone commented 4 years ago

Not quite as successful as I'd hoped. I can run the tests like this (line breaks added for legibility):

code
   --disable-extensions 
   --extensionDevelopmentPath D:\_vscode-arduino-cli\ 
   --extensionTestsPath D:\_vscode-arduino-cli\src\test\runTest.ts

but the outcome doesn't appear on the console. It may be in log files or something but the documentation is inadequate.

RBM-PITT commented 4 years ago

@PeterWone Congratulations on the job!

ghost commented 4 years ago

Glad to hear about the job, congratulations!

MrC74rk commented 4 years ago

I've run into a bit of a problem. The automation works great! But the test keeps failing. See the attached screenshot.

image

/home/runner/work/vscode-arduino-cli is the path that the reop is held in when it's checked out.

Not knowing much about what's under the hood it's hard for me to diagnose from there.

PeterWone commented 4 years ago

Why are you using npm test? Did you create tests for it? The tests I put in the project are mocha tests.

There are many testing frameworks. I used mocha because that is what is used in the sample project from Microsoft.

I don't object to other ways of testing but mocha is what's in the repo.

MrC74rk commented 4 years ago

That explains a lot. (Insert facepalm emoji here) that’s an easy fix.

Cross your fingers

On Sun, Nov 1, 2020 at 01:54 Peter Wone notifications@github.com wrote:

Why are you using npm test? Did you create tests for it? The tests I put in the project are mocha tests.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PeterWone/vscode-arduino-cli/issues/3#issuecomment-720050206, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK2FQ7SCSAA7RKNSS3TSQKLSNUH3HANCNFSM4S4QTYZA .

MrC74rk commented 4 years ago

OK! Got the tests to fire with mocha. I made the following change to the "test" script

image

But...I'm troubleshooting another issue that MAY be related to VS Code 1.49+ This is what I get when the tests fire: image

My research lead me to https://github.com/microsoft/vscode/issues/106569 that seems to be very similar. I just need to see if an older version of VS Code resolves the issue to confirm.

Is there a way to have runTest.ts pull down VS Code 1.48.2? I didn't want to go 'mucking' about in the TypeScript files too much. My background is in operations. I know just enough about code to be dangerous. But if you let me know where that occurs I'm sure I can manage.

PeterWone commented 4 years ago

Could you write some step by step instructions for your process setting up? I know you offered me access to your fork but until I understand how to get to the state you're in I won't be much use troubleshooting.

PeterWone commented 4 years ago

A silly question — can you run the tests interactively in VS Code on your workstation?

While the test runs a second instance of VS Code launches. After the tests run your DEBUG CONSOLE should look like this.

(node:13740) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 warning.js

 spec.js
  Extension Test Suite
 spec.js
    √ Sample test
 spec.js
    1) Sample test 2 which should fail
 spec.js
    √ Sample test 3 which should pass
 spec.js
  2 passing (17ms)
 base.js
  1 failing
 base.js
  1) Extension Test Suite
       Sample test 2 which should fail:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

-1 !== 3

      + expected - actual

      --1
      +3

    at Context.<anonymous> (d:\_vscode-arduino-cli\out\test\suite\extension.test.js:16:16)
    at processImmediate (internal/timers.js:439:21)

 base.js
Error: 1 tests failed.
 extensionHostProcess.js
MrC74rk commented 4 years ago

A silly question — can you run the tests interactively in VS Code on your workstation?

While the test runs a second instance of VS Code launches. After the tests run your DEBUG CONSOLE should look like this.

(node:13740) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 warning.js

 spec.js
  Extension Test Suite
 spec.js
    √ Sample test
 spec.js
    1) Sample test 2 which should fail
 spec.js
    √ Sample test 3 which should pass
 spec.js
  2 passing (17ms)
 base.js
  1 failing
 base.js
  1) Extension Test Suite
       Sample test 2 which should fail:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

-1 !== 3

      + expected - actual

      --1
      +3

      at Context.<anonymous> (d:\_vscode-arduino-cli\out\test\suite\extension.test.js:16:16)
      at processImmediate (internal/timers.js:439:21)

 base.js
Error: 1 tests failed.
 extensionHostProcess.js

Yes. I can get that working on my Wac and on my W10 box.

MrC74rk commented 4 years ago

Could you write some step by step instructions for your process setting up? I know you offered me access to your fork but until I understand how to get to the state you're in I won't be much use troubleshooting.

No problem. This might get long.

I'll skip the part where you go into "Actions" and click new workflow...The setup is pretty simple.

The main.yml file is the director, so to speak, for everything that happens within the workflow. We’ll take it a block at a time:

on:
  push:
    branches:

This sets up the trigger for the action. While I was testing I have it set up for all push requests on all branches. In productions it can be set up for any number of events.

jobs:
  build:
    runs-on: ubuntu-18.04

The yml is broken into Jobs and Steps. Each job has a build it runs on. In this case we tell it to run on Ubuntu-18.04.

  steps:
    - name: Checkout
         uses: actions/checkout@v2
    - run: wget --no-check-certificate https://az764295.vo.msecnd.net/stable/a0479759d6e9ea56afa657e454193f72aef85bd0/code_1.48.2-1598353430_amd64.deb
    - run: sudo apt install ./code_1.48.2-1598353430_amd64.deb
    - run: npm install
    - run: npm install chai mocha ts-node @types/chai @types/mocha --save-dev
    - run: npm test

This is the meat and potatoes. This job only has one step but runs several commands. We'll take these line by line.

uses: actions/checkout@v2

First we check out the repo. This essentially creates a branch of the repo and continues the workflow on that branch.

    - run: wget --no-check-certificate https://az764295.vo.msecnd.net/stable/a0479759d6e9ea56afa657e454193f72aef85bd0/code_1.48.2-1598353430_amd64.deb
    - run: sudo apt install ./code_1.48.2-1598353430_amd64.deb

This was a bit of a testing. The runTest.ts pulls down the latest VS code, but I was trying to get it to default to 1.48.2. We can ignore this because the test updates it anyway.

       - run: npm install

Next we update NPM packages and dependencies before installing chai mocha...which for some reason doesn't get installed.

     - run: npm install chai mocha ts-node @types/chai @types/mocha --save-dev

Next we install Chai.

   - run: npm test

And then we call a script defiled in package.json called 'test'. There you'll see:

"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'src/test/runTest.ts'"

That's it.

Then you get the output pasted above.

PeterWone commented 4 years ago

Well, that looks like it should work.

I'm going to try to interactively execute all the steps for the test proper.