Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitae67855

Browse files
authored
Requests to Github API are now authenticated using the workflow token (arduino#12)
1 parent051108c commitae67855

File tree

8 files changed

+1498
-853
lines changed

8 files changed

+1498
-853
lines changed

‎.github/workflows/test.yml‎

Lines 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‎

Lines 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 thetests:
42+
To runtests settheenvironment 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‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importcore= require("@actions/core");
12
importio= require("@actions/io");
23
importpath= require("path");
34
importos= require("os");
@@ -13,8 +14,18 @@ process.env["RUNNER_TEMP"] = tempDir;
1314
process.env["RUNNER_TOOL_CACHE"]=toolDir;
1415
import*asinstallerfrom"../src/installer";
1516

17+
// Inputs for mock@actions/core
18+
letinputs={
19+
token:process.env.GITHUB_TOKEN||""
20+
}asany;
21+
1622
describe("installer tests",()=>{
1723
beforeEach(asyncfunction(){
24+
// Mock getInput
25+
jest.spyOn(core,"getInput").mockImplementation((name:string)=>{
26+
returninputs[name];
27+
});
28+
1829
awaitio.rmRF(toolDir);
1930
awaitio.rmRF(tempDir);
2031
awaitio.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+
returninputs[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
awaitinstaller.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‎

Lines 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)

[8]ページ先頭

©2009-2025 Movatter.jp