Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ae67855

Browse filesBrowse files
authored
Requests to Github API are now authenticated using the workflow token (#12)
1 parent 051108c commit ae67855
Copy full SHA for ae67855

File tree

Expand file treeCollapse file tree

8 files changed

+1498
-853
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+1498
-853
lines changed

‎.github/workflows/test.yml

Copy file name to clipboardExpand all lines: .github/workflows/test.yml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ jobs:
66
test:
77
runs-on: ${{ matrix.operating-system }}
88

9+
env:
10+
GITHUB_TOKEN: ${{ github.token }}
11+
912
strategy:
1013
matrix:
1114
operating-system: [ubuntu-latest, windows-latest]

‎README.md

Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ To work on the codebase you have to install all the dependencies:
3939
# npm install
4040
```
4141

42-
To run the tests:
42+
To run tests set the environment variable `GITHUB_TOKEN` with a valid Personal Access Token and then:
4343

4444
```sh
4545
# npm run test
4646
```
4747

48+
See the [official Github documentation][pat-docs] to know more about Personal Access Tokens.
49+
4850
## Release
4951

5052
1. `npm install` to add all the dependencies, included development.
@@ -53,3 +55,5 @@ To run the tests:
5355
4. `npm run pack` to package for distribution
5456
5. `git add src dist` to check in the code that matters.
5557
6. open a PR and request a review.
58+
59+
[pat-docs]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token

‎__tests__/main.test.ts

Copy file name to clipboardExpand all lines: __tests__/main.test.ts
+20-3Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import core = require("@actions/core");
12
import io = require("@actions/io");
23
import path = require("path");
34
import os = require("os");
@@ -13,8 +14,18 @@ process.env["RUNNER_TEMP"] = tempDir;
1314
process.env["RUNNER_TOOL_CACHE"] = toolDir;
1415
import * as installer from "../src/installer";
1516

17+
// Inputs for mock @actions/core
18+
let inputs = {
19+
token: process.env.GITHUB_TOKEN || ""
20+
} as any;
21+
1622
describe("installer tests", () => {
1723
beforeEach(async function() {
24+
// Mock getInput
25+
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
26+
return inputs[name];
27+
});
28+
1829
await io.rmRF(toolDir);
1930
await io.rmRF(tempDir);
2031
await io.mkdirP(toolDir);
@@ -28,6 +39,7 @@ describe("installer tests", () => {
2839
} catch {
2940
console.log("Failed to remove test directories");
3041
}
42+
jest.restoreAllMocks();
3143
});
3244

3345
it("Downloads version of Arduino CLI if no matching version is installed", async () => {
@@ -41,10 +53,14 @@ describe("installer tests", () => {
4153
} else {
4254
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
4355
}
44-
}, 10000);
56+
}, 20000);
4557

4658
describe("Gets the latest release of Arduino CLI", () => {
4759
beforeEach(() => {
60+
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
61+
return inputs[name];
62+
});
63+
4864
nock("https://api.github.com")
4965
.get("/repos/Arduino/arduino-cli/git/refs/tags")
5066
.replyWithFile(200, path.join(dataDir, "tags.json"));
@@ -53,6 +69,7 @@ describe("installer tests", () => {
5369
afterEach(() => {
5470
nock.cleanAll();
5571
nock.enableNetConnect();
72+
jest.clearAllMocks();
5673
});
5774

5875
it("Gets the latest version of Arduino CLI 0.4.0 using 0.4 and no matching version is installed", async () => {
@@ -65,7 +82,7 @@ describe("installer tests", () => {
6582
} else {
6683
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
6784
}
68-
}, 10000);
85+
}, 20000);
6986

7087
it("Gets latest version of Task using 0.x and no matching version is installed", async () => {
7188
await installer.getArduinoCli("0.x");
@@ -77,6 +94,6 @@ describe("installer tests", () => {
7794
} else {
7895
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
7996
}
80-
}, 10000);
97+
}, 20000);
8198
});
8299
});

‎action.yml

Copy file name to clipboardExpand all lines: action.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ inputs:
55
version:
66
description: "Version to use. Example: 0.5.0"
77
default: "0.x"
8+
token:
9+
description: "Personal access token (PAT) used to call the Github API."
10+
required: false
11+
default: ${{ github.token }}
812
runs:
913
using: "node12"
1014
main: "dist/index.js"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.