Skip to content

Commit c579dc0

Browse files
author
Massimiliano Pippi
committed
first import
1 parent 3aec203 commit c579dc0

File tree

191 files changed

+62790
-1
lines changed

Some content is hidden

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

191 files changed

+62790
-1
lines changed

Diff for: .github/workflows/test.yml

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

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<https://www.gnu.org/licenses/why-not-lgpl.html>.
674+
<https://www.gnu.org/licenses/why-not-lgpl.html>.

Diff for: README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# setup-protoc
2+
3+
This action makes the `protoc` compiler available to Workflows.
4+
5+
## Usage
6+
7+
To get the latest stable version of `protoc` just add this step:
8+
9+
```yaml
10+
- name: Install Protoc
11+
uses: Arduino/actions/setup-protoc@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 Protoc
18+
uses: Arduino/actions/setup-protoc@master
19+
with:
20+
version: '3.x'
21+
```
22+
23+
You can also require to include releases marked as `pre-release` in Github using the `include-pre-releases` flag (the dafault value for this flag is `false`)
24+
25+
```yaml
26+
- name: Install Protoc
27+
uses: Arduino/actions/setup-protoc@master
28+
with:
29+
version: '3.x'
30+
include-pre-releases: true
31+
```
32+
33+
To pin the exact version:
34+
35+
```yaml
36+
- name: Install Protoc
37+
uses: Arduino/actions/setup-protoc@master
38+
with:
39+
version: '3.9.1'
40+
```
41+
42+
## Development
43+
44+
To work on the codebase you have to install all the dependencies:
45+
46+
```sh
47+
# npm install
48+
```
49+
50+
To run the tests:
51+
52+
```sh
53+
# npm run test
54+
```
55+
56+
## Enable verbose logging for a pipeline
57+
Additional log events with the prefix ::debug:: can be enabled by setting the secret `ACTIONS_STEP_DEBUG` to `true`.
58+
59+
See [step-debug-logs](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md#step-debug-logs) for reference.
60+
61+
62+
63+
## Release
64+
65+
We check in the `node_modules` to provide runtime dependencies to the system
66+
using the Action, so be careful not to `git add` all the development dependencies
67+
you might have under your local `node_modules`. To release a new version of the
68+
Action the workflow should be the following:
69+
70+
1. `npm install` to add all the dependencies, included development.
71+
1. `npm run test` to see everything works as expected.
72+
1. `npm run build` to build the Action under the `./lib` folder.
73+
1. `rm -rf node_modules` to remove all the dependencies.
74+
1. `npm install --production` to add back **only** the runtime dependencies.
75+
1. `git add lib node_modules` to check in the code that matters.
76+
1. open a PR and request a review.

Diff for: __tests__/main.test.ts

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 protoc if no matching version is installed", async () => {
34+
await installer.getProtoc("3.9.0", true);
35+
const protocDir = path.join(toolDir, "protoc", "3.9.0", os.arch());
36+
37+
expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
38+
39+
if (IS_WINDOWS) {
40+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc.exe"))).toBe(
41+
true
42+
);
43+
} else {
44+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
45+
}
46+
}, 100000);
47+
48+
describe("Gets the latest release of protoc", () => {
49+
beforeEach(() => {
50+
nock("https://api.github.com")
51+
.get("/repos/protocolbuffers/protobuf/releases")
52+
.replyWithFile(200, path.join(dataDir, "releases.json"));
53+
});
54+
55+
afterEach(() => {
56+
nock.cleanAll();
57+
nock.enableNetConnect();
58+
});
59+
60+
it("Gets the latest 3.7.x version of protoc using 3.7 and no matching version is installed", async () => {
61+
await installer.getProtoc("3.7", true);
62+
const protocDir = path.join(toolDir, "protoc", "3.7.1", os.arch());
63+
64+
expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
65+
if (IS_WINDOWS) {
66+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc.exe"))).toBe(
67+
true
68+
);
69+
} else {
70+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
71+
}
72+
}, 100000);
73+
74+
it("Gets latest version of protoc using 3.x and no matching version is installed", async () => {
75+
await installer.getProtoc("3.x", true);
76+
const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch());
77+
78+
expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
79+
if (IS_WINDOWS) {
80+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc.exe"))).toBe(
81+
true
82+
);
83+
} else {
84+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
85+
}
86+
}, 100000);
87+
});
88+
89+
describe("Gets the latest release of protoc with broken latest rc tag", () => {
90+
beforeEach(() => {
91+
nock("https://api.github.com")
92+
.get("/repos/protocolbuffers/protobuf/releases")
93+
.replyWithFile(200, path.join(dataDir, "releases-broken-rc-tag.json"));
94+
});
95+
96+
afterEach(() => {
97+
nock.cleanAll();
98+
nock.enableNetConnect();
99+
});
100+
101+
it("Gets latest version of protoc using 3.x with a broken rc tag, filtering pre-releases", async () => {
102+
await installer.getProtoc("3.x", false);
103+
const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch());
104+
105+
expect(fs.existsSync(`${protocDir}.complete`)).toBe(true);
106+
if (IS_WINDOWS) {
107+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc.exe"))).toBe(
108+
true
109+
);
110+
} else {
111+
expect(fs.existsSync(path.join(protocDir, "bin", "protoc"))).toBe(true);
112+
}
113+
}, 100000);
114+
});
115+
});

0 commit comments

Comments
 (0)