Skip to content

Requests to Github API are now authenticated using the workflow token #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
test:
runs-on: ${{ matrix.operating-system }}

env:
GITHUB_TOKEN: ${{ github.token }}

strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ To work on the codebase you have to install all the dependencies:
# npm install
```

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

```sh
# npm run test
```

See the [official Github documentation][pat-docs] to know more about Personal Access Tokens.

## Release

1. `npm install` to add all the dependencies, included development.
Expand All @@ -53,3 +55,5 @@ To run the tests:
4. `npm run pack` to package for distribution
5. `git add src dist` to check in the code that matters.
6. open a PR and request a review.

[pat-docs]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
23 changes: 20 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import core = require("@actions/core");
import io = require("@actions/io");
import path = require("path");
import os = require("os");
Expand All @@ -13,8 +14,18 @@ process.env["RUNNER_TEMP"] = tempDir;
process.env["RUNNER_TOOL_CACHE"] = toolDir;
import * as installer from "../src/installer";

// Inputs for mock @actions/core
let inputs = {
token: process.env.GITHUB_TOKEN || ""
} as any;

describe("installer tests", () => {
beforeEach(async function() {
// Mock getInput
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});

await io.rmRF(toolDir);
await io.rmRF(tempDir);
await io.mkdirP(toolDir);
Expand All @@ -28,6 +39,7 @@ describe("installer tests", () => {
} catch {
console.log("Failed to remove test directories");
}
jest.restoreAllMocks();
});

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

describe("Gets the latest release of Arduino CLI", () => {
beforeEach(() => {
jest.spyOn(core, "getInput").mockImplementation((name: string) => {
return inputs[name];
});

nock("https://api.github.com")
.get("/repos/Arduino/arduino-cli/git/refs/tags")
.replyWithFile(200, path.join(dataDir, "tags.json"));
Expand All @@ -53,6 +69,7 @@ describe("installer tests", () => {
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
jest.clearAllMocks();
});

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

it("Gets latest version of Task using 0.x and no matching version is installed", async () => {
await installer.getArduinoCli("0.x");
Expand All @@ -77,6 +94,6 @@ describe("installer tests", () => {
} else {
expect(fs.existsSync(path.join(bindir, "arduino-cli"))).toBe(true);
}
}, 10000);
}, 20000);
});
});
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
version:
description: "Version to use. Example: 0.5.0"
default: "0.x"
token:
description: "Personal access token (PAT) used to call the Github API."
required: false
default: ${{ github.token }}
runs:
using: "node12"
main: "dist/index.js"
Expand Down
Loading