Skip to content

Commit 60eb084

Browse files
author
Massimiliano Pippi
committed
import sources from arduino/actions
0 parents  commit 60eb084

File tree

187 files changed

+19691
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+19691
-0
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test Action
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.operating-system }}
8+
9+
strategy:
10+
matrix:
11+
operating-system: [ubuntu-latest, windows-latest]
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@master
16+
17+
- name: Set Node.js 10.x
18+
uses: actions/[email protected]
19+
with:
20+
node-version: 10.x
21+
22+
- name: npm install
23+
working-directory: ./setup-arduino-cli
24+
run: npm install
25+
26+
- name: npm lint
27+
working-directory: ./setup-arduino-cli
28+
run: npm run format-check
29+
30+
- name: npm test
31+
working-directory: ./setup-arduino-cli
32+
run: npm test

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# setup-arduino-cli
2+
3+
This action makes the `arduino-cli` tool available to Workflows.
4+
5+
## Usage
6+
7+
To get the latest stable version of `arduino-cli` just add this step:
8+
9+
```yaml
10+
- name: Install Arduino CLI
11+
uses: Arduino/actions/setup-arduino-cli@master
12+
```
13+
14+
If you want to pin a major or minor version you can use the `.x` wildcard:
15+
16+
```yaml
17+
- name: Install Arduino CLI
18+
uses: Arduino/actions/setup-arduino-cli@master
19+
with:
20+
version: '0.x'
21+
```
22+
23+
To pin the exact version:
24+
25+
```yaml
26+
- name: Install Arduino CLI
27+
uses: Arduino/actions/setup-arduino-cli@master
28+
with:
29+
version: '0.5.0'
30+
```
31+
32+
## Development
33+
34+
To work on the codebase you have to install all the dependencies:
35+
36+
```sh
37+
# npm install
38+
```
39+
40+
To run the tests:
41+
42+
```sh
43+
# npm run test
44+
```
45+
46+
## Release
47+
48+
We check in the `node_modules` to provide runtime dependencies to the system
49+
using the Action, so be careful not to `git add` all the development dependencies
50+
you might have under your local `node_modules`. To release a new version of the
51+
Action the workflow should be the following:
52+
53+
1. `npm install` to add all the dependencies, included development.
54+
1. `npm run test` to see everything works as expected.
55+
1. `npm build` to build the Action under the `./lib` folder.
56+
1. `rm -rf node_modules` to remove all the dependencies.
57+
1. `npm install --production` to add back **only** the runtime dependencies.
58+
1. `git add lib node_modules` to check in the code that matters.
59+
1. open a PR and request a review.

__tests__/main.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import io = require("@actions/io");
2+
import path = require("path");
3+
import os = require("os");
4+
import fs = require("fs");
5+
import nock = require("nock");
6+
7+
const toolDir = path.join(__dirname, "runner", "tools");
8+
const tempDir = path.join(__dirname, "runner", "temp");
9+
const dataDir = path.join(__dirname, "testdata");
10+
const IS_WINDOWS = process.platform === "win32";
11+
12+
process.env["RUNNER_TEMP"] = tempDir;
13+
process.env["RUNNER_TOOL_CACHE"] = toolDir;
14+
import * as installer from "../src/installer";
15+
16+
describe("installer tests", () => {
17+
beforeEach(async function() {
18+
await io.rmRF(toolDir);
19+
await io.rmRF(tempDir);
20+
await io.mkdirP(toolDir);
21+
await io.mkdirP(tempDir);
22+
});
23+
24+
afterAll(async () => {
25+
try {
26+
await io.rmRF(toolDir);
27+
await io.rmRF(tempDir);
28+
} catch {
29+
console.log("Failed to remove test directories");
30+
}
31+
});
32+
33+
it("Downloads version of Arduino CLI if no matching version is installed", async () => {
34+
await installer.getArduinoCli("0.4.0");
35+
const bindir = path.join(toolDir, "arduino-cli", "0.4.0", os.arch());
36+
37+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
38+
39+
if (IS_WINDOWS) {
40+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
41+
} else {
42+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
43+
}
44+
}, 10000);
45+
46+
describe("Gets the latest release of Arduino CLI", () => {
47+
beforeEach(() => {
48+
nock("https://api.github.com")
49+
.get("/repos/Arduino/arduino-cli/git/refs/tags")
50+
.replyWithFile(200, path.join(dataDir, "tags.json"));
51+
});
52+
53+
afterEach(() => {
54+
nock.cleanAll();
55+
nock.enableNetConnect();
56+
});
57+
58+
it("Gets the latest version of Arduino CLI 0.4.0 using 0.4 and no matching version is installed", async () => {
59+
await installer.getArduinoCli("0.4");
60+
const bindir = path.join(toolDir, "arduino-cli", "0.4.0", os.arch());
61+
62+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
63+
if (IS_WINDOWS) {
64+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
65+
} else {
66+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
67+
}
68+
}, 10000);
69+
70+
it("Gets latest version of Task using 0.x and no matching version is installed", async () => {
71+
await installer.getArduinoCli("0.x");
72+
const bindir = path.join(toolDir, "arduino-cli", "0.5.0", os.arch());
73+
74+
expect(fs.existsSync(`${bindir}.complete`)).toBe(true);
75+
if (IS_WINDOWS) {
76+
expect(fs.existsSync(path.join(bindir, "arduino-cli.exe"))).toBe(true);
77+
} else {
78+
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
79+
}
80+
}, 10000);
81+
});
82+
});

0 commit comments

Comments
 (0)