Skip to content

Commit b6d0d6b

Browse files
authored
Merge pull request #2 from rchougule/binary_check
code fixes and refactoring for both the actions (review comments).
2 parents c8340ca + 35112f6 commit b6d0d6b

File tree

13 files changed

+116
-91
lines changed

13 files changed

+116
-91
lines changed

setup-env/dist/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ class InputValidator {
597597
* 1. Push
598598
* 2. Pull Request
599599
* 3. Release
600+
* 4. Other events
600601
* @returns {String} Metadata
601602
*/
602603
static _getBuildInfo() {
@@ -665,7 +666,7 @@ class InputValidator {
665666
* @param {String} inputUsername BrowserStack Username
666667
* @returns {String} Modified Username
667668
*/
668-
static validateUsername(inputUsername) {
669+
static updateUsername(inputUsername) {
669670
return `${inputUsername}-GitHubAction`;
670671
}
671672

@@ -4297,9 +4298,7 @@ const ActionInput = __webpack_require__(972);
42974298
/**
42984299
* Entry point to initiate the Action.
42994300
* 1. Triggers parsing of action input values
4300-
* 2. Decides requirement of Local Binary
4301-
* 3. Start/Stop Local Binary if required
4302-
* 4. Triggers uploading of artifacts
4301+
* 2. Sets the environment variables required for BrowserStack
43034302
*/
43044303
const run = async () => {
43054304
try {
@@ -6103,11 +6102,10 @@ class ActionInput {
61036102
}
61046103

61056104
/**
6106-
* Triggers conditional validation of action input values based on the operation
6107-
* to be performed, i.e. start/no local connection required, stopping of local connection
6105+
* Validates the input values
61086106
*/
61096107
_validateInput() {
6110-
this.username = InputValidator.validateUsername(this.username);
6108+
this.username = InputValidator.updateUsername(this.username);
61116109
this.buildName = InputValidator.validateBuildName(this.buildName);
61126110
this.projectName = InputValidator.validateProjectName(this.projectName);
61136111
}
@@ -6119,7 +6117,10 @@ class ActionInput {
61196117
core.startGroup('Setting Environment Variables');
61206118

61216119
core.exportVariable(ENV_VARS.BROWSERSTACK_USERNAME, this.username);
6120+
core.info(`Use ${ENV_VARS.BROWSERSTACK_USERNAME} environment variable for your username in your tests\n`);
6121+
61226122
core.exportVariable(ENV_VARS.BROWSERSTACK_ACCESS_KEY, this.accessKey);
6123+
core.info(`Use ${ENV_VARS.BROWSERSTACK_ACCESS_KEY} environment variable for your access key in your tests\n`);
61236124

61246125
core.exportVariable(ENV_VARS.BROWSERSTACK_PROJECT_NAME, this.projectName);
61256126
core.info(`${ENV_VARS.BROWSERSTACK_PROJECT_NAME} environment variable set as: ${this.projectName}`);

setup-env/src/actionInput/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ class ActionInput {
3636
}
3737

3838
/**
39-
* Triggers conditional validation of action input values based on the operation
40-
* to be performed, i.e. start/no local connection required, stopping of local connection
39+
* Validates the input values
4140
*/
4241
_validateInput() {
43-
this.username = InputValidator.validateUsername(this.username);
42+
this.username = InputValidator.updateUsername(this.username);
4443
this.buildName = InputValidator.validateBuildName(this.buildName);
4544
this.projectName = InputValidator.validateProjectName(this.projectName);
4645
}
@@ -52,7 +51,10 @@ class ActionInput {
5251
core.startGroup('Setting Environment Variables');
5352

5453
core.exportVariable(ENV_VARS.BROWSERSTACK_USERNAME, this.username);
54+
core.info(`Use ${ENV_VARS.BROWSERSTACK_USERNAME} environment variable for your username in your tests\n`);
55+
5556
core.exportVariable(ENV_VARS.BROWSERSTACK_ACCESS_KEY, this.accessKey);
57+
core.info(`Use ${ENV_VARS.BROWSERSTACK_ACCESS_KEY} environment variable for your access key in your tests\n`);
5658

5759
core.exportVariable(ENV_VARS.BROWSERSTACK_PROJECT_NAME, this.projectName);
5860
core.info(`${ENV_VARS.BROWSERSTACK_PROJECT_NAME} environment variable set as: ${this.projectName}`);

setup-env/src/actionInput/inputValidator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class InputValidator {
1111
* 1. Push
1212
* 2. Pull Request
1313
* 3. Release
14+
* 4. Other events
1415
* @returns {String} Metadata
1516
*/
1617
static _getBuildInfo() {
@@ -79,7 +80,7 @@ class InputValidator {
7980
* @param {String} inputUsername BrowserStack Username
8081
* @returns {String} Modified Username
8182
*/
82-
static validateUsername(inputUsername) {
83+
static updateUsername(inputUsername) {
8384
return `${inputUsername}-GitHubAction`;
8485
}
8586

setup-env/src/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const ActionInput = require('./actionInput');
44
/**
55
* Entry point to initiate the Action.
66
* 1. Triggers parsing of action input values
7-
* 2. Decides requirement of Local Binary
8-
* 3. Start/Stop Local Binary if required
9-
* 4. Triggers uploading of artifacts
7+
* 2. Sets the environment variables required for BrowserStack
108
*/
119
const run = async () => {
1210
try {

setup-env/test/actionInput/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ describe('Action Input operations for fetching all inputs, triggering validation
1616

1717
beforeEach(() => {
1818
stubbedInput = sinon.stub(core, 'getInput');
19-
sinon.stub(InputValidator, 'validateUsername').returns('validatedUsername');
19+
sinon.stub(InputValidator, 'updateUsername').returns('validatedUsername');
2020
sinon.stub(InputValidator, 'validateBuildName').returns('validatedBuildName');
2121
sinon.stub(InputValidator, 'validateProjectName').returns('validatedProjectName');
2222
});
2323

2424
afterEach(() => {
2525
core.getInput.restore();
26-
InputValidator.validateUsername.restore();
26+
InputValidator.updateUsername.restore();
2727
InputValidator.validateBuildName.restore();
2828
InputValidator.validateProjectName.restore();
2929
});
@@ -38,7 +38,7 @@ describe('Action Input operations for fetching all inputs, triggering validation
3838
sinon.assert.calledWith(core.getInput, INPUT.ACCESS_KEY, { required: true });
3939
sinon.assert.calledWith(core.getInput, INPUT.BUILD_NAME);
4040
sinon.assert.calledWith(core.getInput, INPUT.PROJECT_NAME);
41-
sinon.assert.calledWith(InputValidator.validateUsername, 'someUsername');
41+
sinon.assert.calledWith(InputValidator.updateUsername, 'someUsername');
4242
sinon.assert.calledWith(InputValidator.validateBuildName, 'someBuildName');
4343
sinon.assert.calledWith(InputValidator.validateProjectName, 'someProjectName');
4444
expect(actionInput.username).to.eq('validatedUsername');
@@ -54,7 +54,7 @@ describe('Action Input operations for fetching all inputs, triggering validation
5454
} catch (e) {
5555
expect(e.message).to.eq('Action input failed for reason: Username Required');
5656
}
57-
sinon.assert.notCalled(InputValidator.validateUsername);
57+
sinon.assert.notCalled(InputValidator.updateUsername);
5858
sinon.assert.notCalled(InputValidator.validateBuildName);
5959
sinon.assert.notCalled(InputValidator.validateProjectName);
6060
});
@@ -67,7 +67,7 @@ describe('Action Input operations for fetching all inputs, triggering validation
6767
} catch (e) {
6868
expect(e.message).to.eq('Action input failed for reason: Access Key Required');
6969
}
70-
sinon.assert.notCalled(InputValidator.validateUsername);
70+
sinon.assert.notCalled(InputValidator.updateUsername);
7171
sinon.assert.notCalled(InputValidator.validateBuildName);
7272
sinon.assert.notCalled(InputValidator.validateProjectName);
7373
});

setup-env/test/actionInput/inputValidator.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('InputValidator class to validate individual fields of the action input
88
context('Validates Username', () => {
99
it("Returns the username with '-GitHubAction' suffix", () => {
1010
const inputUsername = 'someUsername';
11-
expect(InputValidator.validateUsername(inputUsername)).to.eq(`${inputUsername}-GitHubAction`);
11+
expect(InputValidator.updateUsername(inputUsername)).to.eq(`${inputUsername}-GitHubAction`);
1212
});
1313
});
1414

setup-local/dist/index.js

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ const os = __webpack_require__(87);
10721072
const path = __webpack_require__(622);
10731073
const fs = __webpack_require__(747);
10741074
const Utils = __webpack_require__(353);
1075-
const ArtifactsManager = __webpack_require__(513);
1075+
const ArtifactsManager = __webpack_require__(275);
10761076
const constants = __webpack_require__(613);
10771077

10781078
const {
@@ -1107,15 +1107,21 @@ class BinaryControl {
11071107
* platform and the architecture
11081108
*/
11091109
_decidePlatformAndBinary() {
1110-
if (this.platform === PLATFORMS.DARWIN) {
1111-
this.binaryLink = BINARY_LINKS.DARWIN;
1112-
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1113-
} else if (this.platform === PLATFORMS.LINUX) {
1114-
this.binaryLink = os.arch() === 'x32' ? BINARY_LINKS.LINUX_32 : BINARY_LINKS.LINUX_64;
1115-
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1116-
} else if (this.platform === PLATFORMS.WIN32) {
1117-
this.binaryLink = BINARY_LINKS.WINDOWS;
1118-
this.binaryFolder = path.resolve(process.env.GITHUB_WORKSPACE, '..', '..', 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1110+
switch (this.platform) {
1111+
case PLATFORMS.DARWIN:
1112+
this.binaryLink = BINARY_LINKS.DARWIN;
1113+
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1114+
break;
1115+
case PLATFORMS.LINUX:
1116+
this.binaryLink = os.arch() === 'x32' ? BINARY_LINKS.LINUX_32 : BINARY_LINKS.LINUX_64;
1117+
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1118+
break;
1119+
case PLATFORMS.WIN32:
1120+
this.binaryLink = BINARY_LINKS.WINDOWS;
1121+
this.binaryFolder = path.resolve(process.env.GITHUB_WORKSPACE, '..', '..', 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
1122+
break;
1123+
default:
1124+
throw Error(`Unsupported Platform: ${this.platform}. No BrowserStackLocal binary found.`);
11191125
}
11201126
}
11211127

@@ -1205,11 +1211,11 @@ class BinaryControl {
12051211
* Downloads the Local Binary, extracts it and adds it in the PATH variable
12061212
*/
12071213
async downloadBinary() {
1214+
if (Utils.checkToolInCache(LOCAL_BINARY_NAME)) {
1215+
core.info('BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
1216+
return;
1217+
}
12081218
try {
1209-
if (Utils.checkToolInCache(LOCAL_BINARY_NAME)) {
1210-
core.info('BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
1211-
return;
1212-
}
12131219
await this._makeDirectory();
12141220
core.info('Downloading BrowserStackLocal binary...');
12151221
const downloadPath = await tc.downloadTool(this.binaryLink, path.resolve(this.binaryFolder, 'binaryZip'));
@@ -4986,6 +4992,40 @@ class Context {
49864992
exports.Context = Context;
49874993
//# sourceMappingURL=context.js.map
49884994

4995+
/***/ }),
4996+
4997+
/***/ 275:
4998+
/***/ (function(module, __unusedexports, __webpack_require__) {
4999+
5000+
const artifact = __webpack_require__(214);
5001+
const core = __webpack_require__(470);
5002+
5003+
class ArtifactsManager {
5004+
/**
5005+
* Upload artifacts to GitHub workflow
5006+
* @param {String} artifactName Name by which the artifact should be available post uploading
5007+
* @param {String[]} files Files to upload
5008+
* @param {String} rootFolder Folder in which the files reside
5009+
* @returns {Promise<artifact.UploadResponse>} Response of the upload operation
5010+
*/
5011+
static async uploadArtifacts(artifactName, files, rootFolder) {
5012+
const artifactClient = artifact.create();
5013+
const response = await artifactClient.uploadArtifact(
5014+
artifactName,
5015+
files,
5016+
rootFolder, {
5017+
continueOnError: true,
5018+
},
5019+
);
5020+
core.info(`Response for upload: ${JSON.stringify(response)}`);
5021+
return response;
5022+
}
5023+
}
5024+
5025+
// eslint-disable-next-line import/prefer-default-export
5026+
module.exports = ArtifactsManager;
5027+
5028+
49895029
/***/ }),
49905030

49915031
/***/ 280:
@@ -11143,40 +11183,6 @@ function addHook (state, kind, name, hook) {
1114311183
}
1114411184

1114511185

11146-
/***/ }),
11147-
11148-
/***/ 513:
11149-
/***/ (function(module, __unusedexports, __webpack_require__) {
11150-
11151-
const artifact = __webpack_require__(214);
11152-
const core = __webpack_require__(470);
11153-
11154-
class ArtifactsManager {
11155-
/**
11156-
* Upload artifacts to GitHub workflow
11157-
* @param {String} artifactName Name by which the artifact should be available post uploading
11158-
* @param {String[]} files Files to upload
11159-
* @param {String} rootFolder Folder in which the files reside
11160-
* @returns {Promise<artifact.UploadResponse>} Response of the upload operation
11161-
*/
11162-
static async uploadArtifacts(artifactName, files, rootFolder) {
11163-
const artifactClient = artifact.create();
11164-
const response = await artifactClient.uploadArtifact(
11165-
artifactName,
11166-
files,
11167-
rootFolder, {
11168-
continueOnError: true,
11169-
},
11170-
);
11171-
core.info(`Response for upload: ${JSON.stringify(response)}`);
11172-
return response;
11173-
}
11174-
}
11175-
11176-
// eslint-disable-next-line import/prefer-default-export
11177-
module.exports = ArtifactsManager;
11178-
11179-
1118011186
/***/ }),
1118111187

1118211188
/***/ 521:
@@ -13975,8 +13981,8 @@ const {
1397513981
* Entry point to initiate the Action.
1397613982
* 1. Triggers parsing of action input values
1397713983
* 2. Decides requirement of Local Binary
13978-
* 3. Start/Stop Local Binary if required
13979-
* 4. Triggers uploading of artifacts
13984+
* 3. Start/Stop Local Binary
13985+
* 4. Triggers uploading of artifacts after stopping binary
1398013986
*/
1398113987
const run = async () => {
1398213988
try {
@@ -16953,7 +16959,7 @@ class ActionInput {
1695316959

1695416960
/**
1695516961
* Triggers conditional validation of action input values based on the operation
16956-
* to be performed, i.e. start/no local connection required, stopping of local connection
16962+
* to be performed, i.e. starting/stopping of local connection
1695716963
*/
1695816964
_validateInput() {
1695916965
this.localTesting = InputValidator.validateLocalTesting(this.localTesting);

setup-local/src/actionInput/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ActionInput {
4343

4444
/**
4545
* Triggers conditional validation of action input values based on the operation
46-
* to be performed, i.e. start/no local connection required, stopping of local connection
46+
* to be performed, i.e. starting/stopping of local connection
4747
*/
4848
_validateInput() {
4949
this.localTesting = InputValidator.validateLocalTesting(this.localTesting);
File renamed without changes.

setup-local/src/binaryControl.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const os = require('os');
77
const path = require('path');
88
const fs = require('fs');
99
const Utils = require('./utils');
10-
const ArtifactsManager = require('./artifacts');
10+
const ArtifactsManager = require('./artifactsManager');
1111
const constants = require('../config/constants');
1212

1313
const {
@@ -42,15 +42,21 @@ class BinaryControl {
4242
* platform and the architecture
4343
*/
4444
_decidePlatformAndBinary() {
45-
if (this.platform === PLATFORMS.DARWIN) {
46-
this.binaryLink = BINARY_LINKS.DARWIN;
47-
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
48-
} else if (this.platform === PLATFORMS.LINUX) {
49-
this.binaryLink = os.arch() === 'x32' ? BINARY_LINKS.LINUX_32 : BINARY_LINKS.LINUX_64;
50-
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
51-
} else if (this.platform === PLATFORMS.WIN32) {
52-
this.binaryLink = BINARY_LINKS.WINDOWS;
53-
this.binaryFolder = path.resolve(process.env.GITHUB_WORKSPACE, '..', '..', 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
45+
switch (this.platform) {
46+
case PLATFORMS.DARWIN:
47+
this.binaryLink = BINARY_LINKS.DARWIN;
48+
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
49+
break;
50+
case PLATFORMS.LINUX:
51+
this.binaryLink = os.arch() === 'x32' ? BINARY_LINKS.LINUX_32 : BINARY_LINKS.LINUX_64;
52+
this.binaryFolder = path.resolve(process.env.HOME, 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
53+
break;
54+
case PLATFORMS.WIN32:
55+
this.binaryLink = BINARY_LINKS.WINDOWS;
56+
this.binaryFolder = path.resolve(process.env.GITHUB_WORKSPACE, '..', '..', 'work', 'binary', LOCAL_BINARY_FOLDER, this.platform);
57+
break;
58+
default:
59+
throw Error(`Unsupported Platform: ${this.platform}. No BrowserStackLocal binary found.`);
5460
}
5561
}
5662

@@ -140,11 +146,11 @@ class BinaryControl {
140146
* Downloads the Local Binary, extracts it and adds it in the PATH variable
141147
*/
142148
async downloadBinary() {
149+
if (Utils.checkToolInCache(LOCAL_BINARY_NAME)) {
150+
core.info('BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
151+
return;
152+
}
143153
try {
144-
if (Utils.checkToolInCache(LOCAL_BINARY_NAME)) {
145-
core.info('BrowserStackLocal binary already exists in cache. Using that instead of downloading again...');
146-
return;
147-
}
148154
await this._makeDirectory();
149155
core.info('Downloading BrowserStackLocal binary...');
150156
const downloadPath = await tc.downloadTool(this.binaryLink, path.resolve(this.binaryFolder, 'binaryZip'));

0 commit comments

Comments
 (0)