catch gh auth error

pull/310/head
Frostebite 2022-01-29 23:13:44 +00:00
parent d02831dbe6
commit 3f9853712f
5 changed files with 19 additions and 19 deletions

17
dist/index.js vendored
View File

@ -736,7 +736,7 @@ exports.CloudRunnerSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const remote_client_logger_1 = __webpack_require__(28082);
class CloudRunnerSystem {
static Run(command) {
static Run(command, suppressError = false) {
return __awaiter(this, void 0, void 0, function* () {
for (const element of command.split(`\n`)) {
remote_client_logger_1.RemoteClientLogger.log(element);
@ -744,7 +744,7 @@ class CloudRunnerSystem {
return yield new Promise((promise) => {
let output = '';
const child = child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
if (error && !suppressError) {
throw error;
}
if (stderr) {
@ -758,7 +758,7 @@ class CloudRunnerSystem {
});
child.on('close', function (code) {
remote_client_logger_1.RemoteClientLogger.log(`[Exit code ${code}]`);
if (code !== 0) {
if (code !== 0 && !suppressError) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
@ -3728,8 +3728,11 @@ class GithubCliReader {
static GetGitHubAuthToken() {
return __awaiter(this, void 0, void 0, function* () {
try {
// eslint-disable-next-line github/no-then
return ((yield cloud_runner_system_1.CloudRunnerSystem.Run(`gh auth status -t`).catch(() => { })) || '')
const authStatus = yield cloud_runner_system_1.CloudRunnerSystem.Run(`gh auth status`, true);
if (authStatus.includes('You are not logged') || authStatus === '') {
return '';
}
return (yield cloud_runner_system_1.CloudRunnerSystem.Run(`gh auth status -t`))
.split(`Token: `)[1]
.replace(/ /g, '')
.replace(/\n/g, '');
@ -3927,9 +3930,7 @@ class Input {
}
static githubToken() {
return __awaiter(this, void 0, void 0, function* () {
return (Input.getInput('githubToken') ||
(Input.cloudRunnerCluster !== '' ? yield github_cli_1.GithubCliReader.GetGitHubAuthToken() : '') ||
'');
return Input.getInput('githubToken') || (yield github_cli_1.GithubCliReader.GetGitHubAuthToken()) || '';
});
}
static gitPrivateToken() {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -2,14 +2,14 @@ import { exec } from 'child_process';
import { RemoteClientLogger } from './remote-client-logger';
export class CloudRunnerSystem {
public static async Run(command: string) {
public static async Run(command: string, suppressError = false) {
for (const element of command.split(`\n`)) {
RemoteClientLogger.log(element);
}
return await new Promise<string>((promise) => {
let output = '';
const child = exec(command, (error, stdout, stderr) => {
if (error) {
if (error && !suppressError) {
throw error;
}
if (stderr) {
@ -23,7 +23,7 @@ export class CloudRunnerSystem {
});
child.on('close', function (code) {
RemoteClientLogger.log(`[Exit code ${code}]`);
if (code !== 0) {
if (code !== 0 && !suppressError) {
throw new Error(output);
}
const outputLines = output.split(`\n`);

View File

@ -4,8 +4,11 @@ import * as core from '@actions/core';
export class GithubCliReader {
static async GetGitHubAuthToken() {
try {
// eslint-disable-next-line github/no-then
return ((await CloudRunnerSystem.Run(`gh auth status -t`).catch(() => {})) || '')
const authStatus = await CloudRunnerSystem.Run(`gh auth status`, true);
if (authStatus.includes('You are not logged') || authStatus === '') {
return '';
}
return (await CloudRunnerSystem.Run(`gh auth status -t`))
.split(`Token: `)[1]
.replace(/ /g, '')
.replace(/\n/g, '');

View File

@ -161,11 +161,7 @@ class Input {
}
static async githubToken() {
return (
Input.getInput('githubToken') ||
(Input.cloudRunnerCluster !== '' ? await GithubCliReader.GetGitHubAuthToken() : '') ||
''
);
return Input.getInput('githubToken') || (await GithubCliReader.GetGitHubAuthToken()) || '';
}
static async gitPrivateToken() {