Skip to content

Commit d12356d

Browse files
committed
fix: platform check for binary. modify comments. modify: unit tests
1 parent 80d1894 commit d12356d

File tree

7 files changed

+94
-71
lines changed

7 files changed

+94
-71
lines changed

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'));

setup-local/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const {
1313
* Entry point to initiate the Action.
1414
* 1. Triggers parsing of action input values
1515
* 2. Decides requirement of Local Binary
16-
* 3. Start/Stop Local Binary if required
17-
* 4. Triggers uploading of artifacts
16+
* 3. Start/Stop Local Binary
17+
* 4. Triggers uploading of artifacts after stopping binary
1818
*/
1919
const run = async () => {
2020
try {

setup-local/test/artifacts.test.js renamed to setup-local/test/artifactsManager.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const chai = require('chai');
22
const sinon = require('sinon');
33
const artifact = require('@actions/artifact');
44
const core = require('@actions/core');
5-
const ArtifactsManager = require('../src/artifacts');
5+
const ArtifactsManager = require('../src/artifactsManager');
66

77
const { expect } = chai;
88

@@ -26,7 +26,7 @@ describe('Artifacts Handling', () => {
2626
it('by specifying the file location', () => {
2727
const artifactName = 'RandomName';
2828
const files = ['/some/path/file'];
29-
const rootFolder = ['/some/path'];
29+
const rootFolder = '/some/path';
3030
const options = {
3131
continueOnError: true,
3232
};

setup-local/test/binaryControl.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const github = require('@actions/github');
99
const os = require('os');
1010
const fs = require('fs');
1111
const BinaryControl = require('../src/binaryControl');
12-
const ArtifactsManager = require('../src/artifacts');
12+
const ArtifactsManager = require('../src/artifactsManager');
1313
const constants = require('../config/constants');
1414
const Utils = require('../src/utils');
1515

@@ -78,6 +78,17 @@ describe('Binary Control Operations', () => {
7878
});
7979
});
8080

81+
it(`Throws error and exits the workflow if the platform is not supported`, () => {
82+
sinon.stub(os, 'platform').returns('somePlatform');
83+
try {
84+
// eslint-disable-next-line no-new
85+
new BinaryControl();
86+
} catch (e) {
87+
expect(e.message).to.eq('Unsupported Platform: somePlatform. No BrowserStackLocal binary found.');
88+
}
89+
os.platform.restore();
90+
});
91+
8192
it('Makes Directory for the binary folder in recursive manner', async () => {
8293
sinon.stub(io, 'mkdirP').returns(true);
8394
sinon.stub(os, 'platform').returns('darwin');

0 commit comments

Comments
 (0)