Skip to content

Commit b924225

Browse files
fix: Add override OS and linux default
1 parent 53cd6a7 commit b924225

File tree

9 files changed

+145
-63
lines changed

9 files changed

+145
-63
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ${{ matrix.os }}
66
strategy:
77
matrix:
8-
os: [macos-latest, windows-latest, ubuntu-latest, khadas-vim3]
8+
os: [macos-latest, windows-latest, ubuntu-latest]
99
steps:
1010
- name: Checkout
1111
uses: actions/checkout@v2

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ inputs:
5353
override_tag:
5454
description: 'Specify the git tag'
5555
required: false
56+
os:
57+
description: 'Override the assumed OS. Options are alpine | linux | macos | windows.'
58+
required: false
5659
root_dir:
5760
description: 'Used when not in git/hg project to identify project root directory'
5861
required: false

dist/index.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
22
/******/ var __webpack_modules__ = ({
33

4-
/***/ 7351:
4+
/***/ 5241:
55
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
66

77
"use strict";
@@ -135,7 +135,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
135135
};
136136
Object.defineProperty(exports, "__esModule", ({ value: true }));
137137
exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
138-
const command_1 = __nccwpck_require__(7351);
138+
const command_1 = __nccwpck_require__(5241);
139139
const file_command_1 = __nccwpck_require__(717);
140140
const utils_1 = __nccwpck_require__(5278);
141141
const os = __importStar(__nccwpck_require__(2087));
@@ -626,7 +626,7 @@ const os = __importStar(__nccwpck_require__(2087));
626626
const events = __importStar(__nccwpck_require__(8614));
627627
const child = __importStar(__nccwpck_require__(3129));
628628
const path = __importStar(__nccwpck_require__(5622));
629-
const io = __importStar(__nccwpck_require__(7436));
629+
const io = __importStar(__nccwpck_require__(7351));
630630
const ioUtil = __importStar(__nccwpck_require__(1962));
631631
const timers_1 = __nccwpck_require__(8213);
632632
/* eslint-disable @typescript-eslint/unbound-method */
@@ -2221,7 +2221,7 @@ exports.getCmdPath = getCmdPath;
22212221

22222222
/***/ }),
22232223

2224-
/***/ 7436:
2224+
/***/ 7351:
22252225
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
22262226

22272227
"use strict";
@@ -12842,10 +12842,10 @@ var external_fs_ = __nccwpck_require__(5747);
1284212842
var external_https_ = __nccwpck_require__(7211);
1284312843
// EXTERNAL MODULE: external "path"
1284412844
var external_path_ = __nccwpck_require__(5622);
12845-
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
12846-
var core = __nccwpck_require__(2186);
1284712845
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
1284812846
var exec = __nccwpck_require__(1514);
12847+
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
12848+
var core = __nccwpck_require__(2186);
1284912849
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
1285012850
var github = __nccwpck_require__(5438);
1285112851
;// CONCATENATED MODULE: ./package.json
@@ -12874,6 +12874,7 @@ const buildExec = () => {
1287412874
const flags = core.getInput('flags');
1287512875
const functionalities = core.getInput('functionalities');
1287612876
const name = core.getInput('name');
12877+
const os = core.getInput('os');
1287712878
const overrideBranch = core.getInput('override_branch');
1287812879
const overrideBuild = core.getInput('override_build');
1287912880
const overrideCommit = core.getInput('override_commit');
@@ -12981,7 +12982,7 @@ const buildExec = () => {
1298112982
if (workingDir) {
1298212983
options.cwd = workingDir;
1298312984
}
12984-
return { execArgs, options, failCi };
12985+
return { execArgs, options, failCi, os };
1298512986
};
1298612987
/* harmony default export */ const src_buildExec = (buildExec);
1298712988

@@ -12994,24 +12995,37 @@ const setFailure = (message, failCi) => {
1299412995
process.exit();
1299512996
}
1299612997
};
12997-
const getUploaderName = () => {
12998-
if (isWindows()) {
12998+
const getUploaderName = (platform) => {
12999+
if (isWindows(platform)) {
1299913000
return 'codecov.exe';
1300013001
}
1300113002
else {
1300213003
return 'codecov';
1300313004
}
1300413005
};
13005-
const isValidPlatform = () => {
13006-
return PLATFORMS.includes(getPlatform());
13006+
const isValidPlatform = (platform) => {
13007+
return PLATFORMS.includes(platform);
1300713008
};
13008-
const isWindows = () => {
13009-
return getPlatform() === 'windows';
13009+
const isWindows = (platform) => {
13010+
return platform === 'windows';
1301013011
};
13011-
const getPlatform = () => {
13012-
return process.env.RUNNER_OS.toLowerCase();
13012+
const getPlatform = (os) => {
13013+
var _a;
13014+
if (isValidPlatform(os)) {
13015+
core.info(`==> ${os} OS provided`);
13016+
return os;
13017+
}
13018+
const platform = (_a = process.env.RUNNER_OS) === null || _a === void 0 ? void 0 : _a.toLowerCase();
13019+
if (isValidPlatform(platform)) {
13020+
core.info(`==> ${platform} OS detected`);
13021+
return platform;
13022+
}
13023+
core.info('==> Could not detect OS or provided OS is invalid. Defaulting to linux');
13024+
return 'linux';
13025+
};
13026+
const getBaseUrl = (platform) => {
13027+
return `https://uploader.codecov.io/latest/${platform}/${getUploaderName(platform)}`;
1301313028
};
13014-
const BASEURL = `https://uploader.codecov.io/latest/${getPlatform()}/${getUploaderName()}`;
1301513029

1301613030

1301713031
// EXTERNAL MODULE: external "crypto"
@@ -13037,15 +13051,15 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
1303713051

1303813052

1303913053

13040-
const verify = (filename) => __awaiter(void 0, void 0, void 0, function* () {
13054+
const verify = (filename, platform) => __awaiter(void 0, void 0, void 0, function* () {
1304113055
try {
13042-
const uploaderName = getUploaderName();
13056+
const uploaderName = getUploaderName(platform);
1304313057
// Read in public key
1304413058
const publicKeyArmored = yield external_fs_.readFileSync(__nccwpck_require__.ab + "pgp_keys.asc", 'utf-8');
1304513059
// Get SHASUM and SHASUM signature files
13046-
const shasumRes = yield lib(`${BASEURL}.SHA256SUM`);
13060+
const shasumRes = yield lib(`${getBaseUrl(platform)}.SHA256SUM`);
1304713061
const shasum = yield shasumRes.text();
13048-
const shaSigRes = yield lib(`${BASEURL}.SHA256SUM.sig`);
13062+
const shaSigRes = yield lib(`${getBaseUrl(platform)}.SHA256SUM.sig`);
1304913063
const shaSig = yield shaSigRes.text();
1305013064
// Verify shasum
1305113065
const verified = yield openpgp_min/* verify */.T({
@@ -13102,17 +13116,12 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu
1310213116

1310313117

1310413118

13105-
1310613119
let failCi;
1310713120
try {
13108-
const { execArgs, options, failCi } = src_buildExec();
13109-
const platform = getPlatform();
13110-
core.info(`==> ${platform} OS detected`);
13111-
if (!isValidPlatform()) {
13112-
setFailure(`Codecov: Encountered an unexpected platform: ${platform}`, failCi);
13113-
}
13114-
const filename = external_path_.join(__dirname, getUploaderName());
13115-
external_https_.get(BASEURL, (res) => {
13121+
const { execArgs, options, failCi, os } = src_buildExec();
13122+
const platform = getPlatform(os);
13123+
const filename = external_path_.join(__dirname, getUploaderName(platform));
13124+
external_https_.get(getBaseUrl(platform), (res) => {
1311613125
// Image will be stored at this path
1311713126
const filePath = external_fs_.createWriteStream(filename);
1311813127
res.pipe(filePath);
@@ -13121,7 +13130,7 @@ try {
1312113130
setFailure(`Codecov: Failed to write uploader binary: ${err.message}`, true);
1312213131
}).on('finish', () => src_awaiter(void 0, void 0, void 0, function* () {
1312313132
filePath.close();
13124-
yield validate(filename);
13133+
yield validate(filename, platform);
1312513134
yield external_fs_.chmodSync(filename, '777');
1312613135
const unlink = () => {
1312713136
external_fs_.unlink(filename, (err) => {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildExec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const buildExec = () => {
2727
const flags = core.getInput('flags');
2828
const functionalities = core.getInput('functionalities');
2929
const name = core.getInput('name');
30+
const os = core.getInput('os');
3031
const overrideBranch = core.getInput('override_branch');
3132
const overrideBuild = core.getInput('override_build');
3233
const overrideCommit = core.getInput('override_commit');
@@ -146,7 +147,7 @@ const buildExec = () => {
146147
options.cwd = workingDir;
147148
}
148149

149-
return {execArgs, options, failCi};
150+
return {execArgs, options, failCi, os};
150151
};
151152

152153
export default buildExec;

src/helpers.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {
2+
getBaseUrl,
3+
getPlatform,
4+
isValidPlatform,
5+
isWindows,
6+
PLATFORMS,
7+
} from './helpers';
8+
9+
let OLDOS = process.env.RUNNER_OS;
10+
11+
beforeEach(() => {
12+
jest.resetModules();
13+
OLDOS = process.env.RUNNER_OS;
14+
});
15+
16+
afterAll(() => {
17+
process.env.RUNNER_OS = OLDOS;
18+
});
19+
20+
test('getPlatform', () => {
21+
expect(getPlatform('linux')).toBe('linux');
22+
expect(getPlatform('windows')).toBe('windows');
23+
24+
const defaultPlatform =
25+
process.env.RUNNER_OS ? process.env.RUNNER_OS.toLowerCase() : 'linux';
26+
expect(getPlatform('fakeos')).toBe(defaultPlatform);
27+
expect(getPlatform()).toBe(defaultPlatform);
28+
29+
process.env.RUNNER_OS = 'macos';
30+
expect(getPlatform('fakeos')).toBe('macos');
31+
expect(getPlatform()).toBe('macos');
32+
33+
process.env.RUNNER_OS = 'alsofakeos';
34+
expect(getPlatform()).toBe('linux');
35+
expect(getPlatform('fakeos')).toBe('linux');
36+
});
37+
38+
test('getBaseUrl', () => {
39+
expect(PLATFORMS.map((platform) => {
40+
return getBaseUrl(platform);
41+
})).toEqual([
42+
'https://uploader.codecov.io/latest/alpine/codecov',
43+
'https://uploader.codecov.io/latest/linux/codecov',
44+
'https://uploader.codecov.io/latest/macos/codecov',
45+
'https://uploader.codecov.io/latest/windows/codecov.exe',
46+
]);
47+
});
48+
49+
test('isWindows', () => {
50+
expect(PLATFORMS.map((platform) => {
51+
return isWindows(platform);
52+
})).toEqual([false, false, false, true]);
53+
});
54+
55+
test('isValidPlatform', () => {
56+
expect(PLATFORMS.map((platform) => {
57+
return isValidPlatform(platform);
58+
})).toEqual([true, true, true, true]);
59+
60+
expect(isValidPlatform('fakeos')).toBeFalsy();
61+
});

src/helpers.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,47 @@ const setFailure = (message: string, failCi: boolean): void => {
99
}
1010
};
1111

12-
const getUploaderName = (): string => {
13-
if (isWindows()) {
12+
const getUploaderName = (platform: string): string => {
13+
if (isWindows(platform)) {
1414
return 'codecov.exe';
1515
} else {
1616
return 'codecov';
1717
}
1818
};
1919

20-
const isValidPlatform = (): boolean => {
21-
return PLATFORMS.includes(getPlatform());
20+
const isValidPlatform = (platform: string): boolean => {
21+
return PLATFORMS.includes(platform);
2222
};
2323

24-
const isWindows = (): boolean => {
25-
return getPlatform() === 'windows';
24+
const isWindows = (platform: string): boolean => {
25+
return platform === 'windows';
2626
};
2727

28-
const getPlatform = (): string => {
29-
return process.env.RUNNER_OS.toLowerCase();
28+
const getPlatform = (os?: string): string => {
29+
if (isValidPlatform(os)) {
30+
core.info(`==> ${os} OS provided`);
31+
return os;
32+
}
33+
34+
const platform = process.env.RUNNER_OS?.toLowerCase();
35+
if (isValidPlatform(platform)) {
36+
core.info(`==> ${platform} OS detected`);
37+
return platform;
38+
}
39+
40+
core.info(
41+
'==> Could not detect OS or provided OS is invalid. Defaulting to linux',
42+
);
43+
return 'linux';
3044
};
3145

32-
const BASEURL = `https://uploader.codecov.io/latest/${getPlatform()}/${getUploaderName()}`;
46+
const getBaseUrl = (platform: string): string => {
47+
return `https://uploader.codecov.io/latest/${platform}/${getUploaderName(platform)}`;
48+
};
3349

3450
export {
35-
BASEURL,
51+
PLATFORMS,
52+
getBaseUrl,
3653
getPlatform,
3754
getUploaderName,
3855
isValidPlatform,

src/index.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import * as fs from 'fs';
22
import * as https from 'https';
33
import * as path from 'path';
44

5-
import * as core from '@actions/core';
65
import * as exec from '@actions/exec';
76

87
import buildExec from './buildExec';
98
import {
10-
BASEURL,
9+
getBaseUrl,
1110
getPlatform,
1211
getUploaderName,
13-
isValidPlatform,
1412
setFailure,
1513
} from './helpers';
1614

@@ -19,18 +17,11 @@ import verify from './validate';
1917
let failCi;
2018

2119
try {
22-
const {execArgs, options, failCi} = buildExec();
23-
const platform = getPlatform();
24-
core.info(`==> ${platform} OS detected`);
20+
const {execArgs, options, failCi, os} = buildExec();
21+
const platform = getPlatform(os);
2522

26-
if (!isValidPlatform()) {
27-
setFailure(
28-
`Codecov: Encountered an unexpected platform: ${platform}`,
29-
failCi,
30-
);
31-
}
32-
const filename = path.join( __dirname, getUploaderName());
33-
https.get(BASEURL, (res) => {
23+
const filename = path.join( __dirname, getUploaderName(platform));
24+
https.get(getBaseUrl(platform), (res) => {
3425
// Image will be stored at this path
3526
const filePath = fs.createWriteStream(filename);
3627
res.pipe(filePath);
@@ -43,7 +34,7 @@ try {
4334
}).on('finish', async () => {
4435
filePath.close();
4536

46-
await verify(filename);
37+
await verify(filename, platform);
4738
await fs.chmodSync(filename, '777');
4839

4940
const unlink = () => {

src/validate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import * as openpgp from 'openpgp';
77
import * as fetch from 'node-fetch';
88

99
import {
10-
BASEURL,
10+
getBaseUrl,
1111
getUploaderName,
1212
setFailure,
1313
} from './helpers';
1414

15-
const verify = async (filename: string) => {
15+
const verify = async (filename: string, platform: string) => {
1616
try {
17-
const uploaderName = getUploaderName();
17+
const uploaderName = getUploaderName(platform);
1818

1919
// Read in public key
2020
const publicKeyArmored = await fs.readFileSync(
@@ -23,10 +23,10 @@ const verify = async (filename: string) => {
2323
);
2424

2525
// Get SHASUM and SHASUM signature files
26-
const shasumRes = await fetch( `${BASEURL}.SHA256SUM`);
26+
const shasumRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM`);
2727
const shasum = await shasumRes.text();
2828

29-
const shaSigRes = await fetch( `${BASEURL}.SHA256SUM.sig`);
29+
const shaSigRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM.sig`);
3030
const shaSig = await shaSigRes.text();
3131

3232
// Verify shasum

0 commit comments

Comments
 (0)