Skip to content

Commit

Permalink
Check GitHub token (#99)
Browse files Browse the repository at this point in the history
* Reeplace createCheck option with check for githubToken

* Fix index.js
  • Loading branch information
davidmfinol authored Feb 28, 2021
1 parent 43d90c2 commit 215f660
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
12 changes: 4 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ inputs:
customParameters:
required: false
description: 'Extra parameters to configure the Unity editor run.'
createCheck:
githubToken:
required: false
default: 'false'
description: 'Creates a check with the Test Results'
default: ''
description: 'Token to authorize access to the GitHub REST API. If provided, a check run will be created with the test results.'
checkName:
required: false
default: 'Test Results'
description: 'Name for the check created when createCheck is true.'
githubToken:
required: false
default: ''
description: 'Token to authorize access to the GitHub REST API. Required if and only if createCheck is true.'
description: 'Name for the check run that is created when a github token is provided.'
outputs:
artifactsPath:
description: 'Path where the artifacts are stored'
Expand Down
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ async function action() {
testMode,
artifactsPath,
useHostNetwork,
createCheck,
checkName,
githubToken,
customParameters,
githubToken,
checkName,
} = Input.getFromUser();
const baseImage = ImageTag.createForBase({ version: unityVersion, customImage });

Expand All @@ -31,16 +30,16 @@ async function action() {
testMode,
artifactsPath,
useHostNetwork,
createCheck,
customParameters,
githubToken,
});
} finally {
// Set output
await Output.setArtifactsPath(artifactsPath);
}

if (createCheck) {
const failedTestCount = await ResultsCheck.createCheck(artifactsPath, checkName, githubToken);
if (githubToken) {
const failedTestCount = await ResultsCheck.createCheck(artifactsPath, githubToken, checkName);
if (failedTestCount >= 1) {
core.setFailed(`Test(s) Failed! Check '${checkName}' for details.`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/model/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Docker {
testMode,
artifactsPath,
useHostNetwork,
createCheck,
customParameters,
githubToken,
} = parameters;

const command = `docker run \
Expand Down Expand Up @@ -63,7 +63,7 @@ class Docker {
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
--volume "${workspace}":"/github/workspace" \
${useHostNetwork ? '--net=host' : ''} \
${createCheck ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image}`;

await exec(command, undefined, { silent });
Expand Down
11 changes: 4 additions & 7 deletions src/model/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class Input {
const rawProjectPath = getInput('projectPath') || '.';
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
const rawCreateCheck = getInput('createCheck') || 'false';
const checkName = getInput('checkName') || 'Test Results';
const githubToken = getInput('githubToken') || '';
const customParameters = getInput('customParameters') || '';
const githubToken = getInput('githubToken') || '';
const checkName = getInput('checkName') || 'Test Results';

// Validate input
if (!includes(this.testModes, testMode)) {
Expand All @@ -47,7 +46,6 @@ class Input {
const projectPath = rawProjectPath.replace(/\/$/, '');
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const createCheck = rawCreateCheck === 'true';
const unityVersion =
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion;

Expand All @@ -59,10 +57,9 @@ class Input {
testMode,
artifactsPath,
useHostNetwork,
createCheck,
checkName,
githubToken,
customParameters,
githubToken,
checkName,
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/model/results-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import ResultsParser from './results-parser';
import { RunMeta } from './ts/results-meta.ts';

class ResultsCheck {
static async createCheck(artifactsPath, checkName, githubToken) {
static async createCheck(artifactsPath, githubToken, checkName) {
// Validate input
if (!artifactsPath || !checkName || !githubToken) {
throw new Error(
`Missing input! {"artifactsPath": "${artifactsPath}", "checkName": "${checkName}", "githubToken": "${githubToken}`,
`Missing input! {"artifactsPath": "${artifactsPath}", "githubToken": "${githubToken}, "checkName": "${checkName}"`,
);
}

Expand Down

0 comments on commit 215f660

Please sign in to comment.