Skip to content
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

Add support for GITHUB_TOKEN #22

Merged
merged 3 commits into from
Jan 25, 2023
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ jobs:
steps:
# ...
- uses: saucelabs/saucectl-run-action@v2
env:
GITHUB_TOKEN: $${{ github.token }}
# ...
```

:warning: To avoid reaching `API rate limit exceeded` due to unauthenticated requests, be sure to provide `GITHUB_TOKEN` through `env` field.

### Advanced

```
Expand All @@ -27,6 +31,8 @@ jobs:
name: Action Test
steps:
- uses: saucelabs/saucectl-run-action@v2
env:
GITHUB_TOKEN: $${{ github.token }}
with:
sauce-username: ${{ secrets.SAUCE_USERNAME }}
sauce-access-key: ${{ secrets.SAUCE_ACCESS_KEY }}
Expand Down
50 changes: 49 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5534,6 +5534,37 @@ function v4(options, buf, offset) {
module.exports = v4;


/***/ }),

/***/ 20:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";


Object.defineProperty(exports, "__esModule", ({ value: true }));

var authToken = __nccwpck_require__(334);

const createActionAuth = function createActionAuth() {
if (!process.env.GITHUB_ACTION) {
throw new Error("[@octokit/auth-action] `GITHUB_ACTION` environment variable is not set. @octokit/auth-action is meant to be used in GitHub Actions only.");
}
const definitions = [process.env.GITHUB_TOKEN, process.env.INPUT_GITHUB_TOKEN, process.env.INPUT_TOKEN].filter(Boolean);
if (definitions.length === 0) {
throw new Error("[@octokit/auth-action] `GITHUB_TOKEN` variable is not set. It must be set on either `env:` or `with:`. See https://github.com/octokit/auth-action.js#createactionauth");
}
if (definitions.length > 1) {
throw new Error("[@octokit/auth-action] The token variable is specified more than once. Use either `with.token`, `with.GITHUB_TOKEN`, or `env.GITHUB_TOKEN`. See https://github.com/octokit/auth-action.js#createactionauth");
}
const token = definitions.pop();
return authToken.createTokenAuth(token);
};

exports.createActionAuth = createActionAuth;
//# sourceMappingURL=index.js.map


/***/ }),

/***/ 334:
Expand Down Expand Up @@ -16309,6 +16340,7 @@ module.exports = { awaitExecution };
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const { Octokit } = __nccwpck_require__(5375);
const { createActionAuth } = __nccwpck_require__(20);
const semver = __nccwpck_require__(1383);
const os = __nccwpck_require__(2037);
const tc = __nccwpck_require__(7784);
Expand All @@ -16332,7 +16364,17 @@ function getPlatform() {
}

async function selectCompatibleVersion(versionSpec) {
const octokit = new Octokit();
// NOTE: authStrategy is set conditionnaly. Docs specifies that GITHUB_TOKEN needs to be set explicitely.
// To avoid breaking every pipeline that has no GITHUB_TOKEN set, this strategy is not passed until
// a token is available.
//
// References:
// - https://github.com/octokit/auth-action.js#createactionauth
// - https://github.com/octokit/auth-action.js/blob/main/src/index.ts#L16-L20
// - https://github.com/octokit/core.js/blob/main/src/index.ts#L121-L124
const octokit = new Octokit({
authStrategy: process.env.GITHUB_TOKEN ? createActionAuth : undefined,
});
const response = await octokit.request("GET /repos/:org/:repo/releases", {
org: "saucelabs",
repo: "saucectl",
Expand Down Expand Up @@ -16672,6 +16714,12 @@ async function run() {
return;
}

if (!process.env.GITHUB_TOKEN) {
core.warning('No GITHUB_TOKEN detected.')
core.warning('Be sure to explicitly set GITHUB_TOKEN in saucectl-run-action step of your workflow.');
core.warning('Unauthenticated usage may result in "API rate limit exceeded" error.');
}

// Install saucectl
if (!await saucectlInstall({ versionSpec: cfg.saucectlVersion })) {
return;
Expand Down
25 changes: 25 additions & 0 deletions dist/main/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@octokit/auth-action
MIT
The MIT License

Copyright (c) 2019 Octokit contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


@octokit/auth-token
MIT
The MIT License
Expand Down
69 changes: 49 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@actions/github": "^5.1.1",
"@actions/tool-cache": "^2.0.1",
"@octokit/action": "^4.0.8",
"@octokit/auth-action": "^2.0.3",
"@octokit/rest": "^19.0.4",
"semver": "^7.3.8"
},
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ async function run() {
return;
}

if (!process.env.GITHUB_TOKEN) {
core.warning('No GITHUB_TOKEN detected.')
core.warning('Be sure to explicitly set GITHUB_TOKEN in saucectl-run-action step of your workflow.');
core.warning('Unauthenticated usage may result in "API rate limit exceeded" error.');
}

// Install saucectl
if (!await saucectlInstall({ versionSpec: cfg.saucectlVersion })) {
return;
Expand Down
13 changes: 12 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Octokit } = require("@octokit/rest");
const { createActionAuth } = require("@octokit/auth-action");
const semver = require("semver");
const os = require('os');
const tc = require('@actions/tool-cache');
Expand All @@ -22,7 +23,17 @@ function getPlatform() {
}

async function selectCompatibleVersion(versionSpec) {
const octokit = new Octokit();
// NOTE: authStrategy is set conditionnaly. Docs specifies that GITHUB_TOKEN needs to be set explicitely.
// To avoid breaking every pipeline that has no GITHUB_TOKEN set, this strategy is not passed until
// a token is available.
//
// References:
// - https://github.com/octokit/auth-action.js#createactionauth
// - https://github.com/octokit/auth-action.js/blob/main/src/index.ts#L16-L20
// - https://github.com/octokit/core.js/blob/main/src/index.ts#L121-L124
const octokit = new Octokit({
authStrategy: process.env.GITHUB_TOKEN ? createActionAuth : undefined,
});
const response = await octokit.request("GET /repos/:org/:repo/releases", {
org: "saucelabs",
repo: "saucectl",
Expand Down