Merge pull request #485 from codecov/alternate-os

fix: Add override OS and linux default to platform
This commit is contained in:
Tom Hu 2021-08-24 12:06:13 -04:00 committed by GitHub
commit 5a8bb4701e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 7782 additions and 63 deletions

View file

@ -1,3 +1,23 @@
## 2.0.3
### Fixes
- #464 Fix wrong link in the readme
- #485 fix: Add override OS and linux default to platform
### Dependencies
- #447 build(deps): bump openpgp from 5.0.0-4 to 5.0.0-5
- #458 build(deps-dev): bump eslint from 7.31.0 to 7.32.0
- #465 build(deps-dev): bump @typescript-eslint/eslint-plugin from 4.28.4 to 4.29.1
- #466 build(deps-dev): bump @typescript-eslint/parser from 4.28.4 to 4.29.1
- #468 build(deps-dev): bump @types/jest from 26.0.24 to 27.0.0
- #470 build(deps-dev): bump @types/node from 16.4.0 to 16.6.0
- #472 build(deps): bump path-parse from 1.0.6 to 1.0.7
- #473 build(deps-dev): bump @types/jest from 27.0.0 to 27.0.1
- #478 build(deps-dev): bump @typescript-eslint/parser from 4.29.1 to 4.29.2
- #479 build(deps-dev): bump @typescript-eslint/eslint-plugin from 4.29.1 to 4.29.2
- #481 build(deps-dev): bump @types/node from 16.6.0 to 16.6.2
- #483 build(deps-dev): bump @vercel/ncc from 0.29.0 to 0.29.2
- #484 build(deps): bump @actions/core from 1.4.0 to 1.5.0
## 2.0.2
### Fixes
- Underlying uploader fixes issues with tokens not being sent properly for users seeing

View file

@ -53,6 +53,9 @@ inputs:
override_tag:
description: 'Specify the git tag'
required: false
os:
description: 'Override the assumed OS. Options are alpine | linux | macos | windows.'
required: false
root_dir:
description: 'Used when not in git/hg project to identify project root directory'
required: false

63
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

7624
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "codecov-action",
"version": "2.0.2",
"version": "2.0.3",
"description": "Upload coverage reports to Codecov from GitHub Actions",
"main": "index.js",
"scripts": {

View file

@ -27,6 +27,7 @@ const buildExec = () => {
const flags = core.getInput('flags');
const functionalities = core.getInput('functionalities');
const name = core.getInput('name');
const os = core.getInput('os');
const overrideBranch = core.getInput('override_branch');
const overrideBuild = core.getInput('override_build');
const overrideCommit = core.getInput('override_commit');
@ -146,7 +147,7 @@ const buildExec = () => {
options.cwd = workingDir;
}
return {execArgs, options, failCi};
return {execArgs, options, failCi, os};
};
export default buildExec;

61
src/helpers.test.ts Normal file
View file

@ -0,0 +1,61 @@
import {
getBaseUrl,
getPlatform,
isValidPlatform,
isWindows,
PLATFORMS,
} from './helpers';
let OLDOS = process.env.RUNNER_OS;
beforeEach(() => {
jest.resetModules();
OLDOS = process.env.RUNNER_OS;
});
afterAll(() => {
process.env.RUNNER_OS = OLDOS;
});
test('getPlatform', () => {
expect(getPlatform('linux')).toBe('linux');
expect(getPlatform('windows')).toBe('windows');
const defaultPlatform =
process.env.RUNNER_OS ? process.env.RUNNER_OS.toLowerCase() : 'linux';
expect(getPlatform('fakeos')).toBe(defaultPlatform);
expect(getPlatform()).toBe(defaultPlatform);
process.env.RUNNER_OS = 'macos';
expect(getPlatform('fakeos')).toBe('macos');
expect(getPlatform()).toBe('macos');
process.env.RUNNER_OS = 'alsofakeos';
expect(getPlatform()).toBe('linux');
expect(getPlatform('fakeos')).toBe('linux');
});
test('getBaseUrl', () => {
expect(PLATFORMS.map((platform) => {
return getBaseUrl(platform);
})).toEqual([
'https://uploader.codecov.io/latest/alpine/codecov',
'https://uploader.codecov.io/latest/linux/codecov',
'https://uploader.codecov.io/latest/macos/codecov',
'https://uploader.codecov.io/latest/windows/codecov.exe',
]);
});
test('isWindows', () => {
expect(PLATFORMS.map((platform) => {
return isWindows(platform);
})).toEqual([false, false, false, true]);
});
test('isValidPlatform', () => {
expect(PLATFORMS.map((platform) => {
return isValidPlatform(platform);
})).toEqual([true, true, true, true]);
expect(isValidPlatform('fakeos')).toBeFalsy();
});

View file

@ -9,30 +9,47 @@ const setFailure = (message: string, failCi: boolean): void => {
}
};
const getUploaderName = (): string => {
if (isWindows()) {
const getUploaderName = (platform: string): string => {
if (isWindows(platform)) {
return 'codecov.exe';
} else {
return 'codecov';
}
};
const isValidPlatform = (): boolean => {
return PLATFORMS.includes(getPlatform());
const isValidPlatform = (platform: string): boolean => {
return PLATFORMS.includes(platform);
};
const isWindows = (): boolean => {
return getPlatform() === 'windows';
const isWindows = (platform: string): boolean => {
return platform === 'windows';
};
const getPlatform = (): string => {
return process.env.RUNNER_OS.toLowerCase();
const getPlatform = (os?: string): string => {
if (isValidPlatform(os)) {
core.info(`==> ${os} OS provided`);
return os;
}
const platform = process.env.RUNNER_OS?.toLowerCase();
if (isValidPlatform(platform)) {
core.info(`==> ${platform} OS detected`);
return platform;
}
core.info(
'==> Could not detect OS or provided OS is invalid. Defaulting to linux',
);
return 'linux';
};
const BASEURL = `https://uploader.codecov.io/latest/${getPlatform()}/${getUploaderName()}`;
const getBaseUrl = (platform: string): string => {
return `https://uploader.codecov.io/latest/${platform}/${getUploaderName(platform)}`;
};
export {
BASEURL,
PLATFORMS,
getBaseUrl,
getPlatform,
getUploaderName,
isValidPlatform,

View file

@ -6,10 +6,9 @@ import * as exec from '@actions/exec';
import buildExec from './buildExec';
import {
BASEURL,
getBaseUrl,
getPlatform,
getUploaderName,
isValidPlatform,
setFailure,
} from './helpers';
@ -18,16 +17,11 @@ import verify from './validate';
let failCi;
try {
const {execArgs, options, failCi} = buildExec();
const platform = getPlatform();
if (!isValidPlatform()) {
setFailure(
`Codecov: Encountered an unexpected platform: ${platform}`,
failCi,
);
}
const filename = path.join( __dirname, getUploaderName());
https.get(BASEURL, (res) => {
const {execArgs, options, failCi, os} = buildExec();
const platform = getPlatform(os);
const filename = path.join( __dirname, getUploaderName(platform));
https.get(getBaseUrl(platform), (res) => {
// Image will be stored at this path
const filePath = fs.createWriteStream(filename);
res.pipe(filePath);
@ -40,7 +34,7 @@ try {
}).on('finish', async () => {
filePath.close();
await verify(filename);
await verify(filename, platform);
await fs.chmodSync(filename, '777');
const unlink = () => {

View file

@ -7,14 +7,14 @@ import * as openpgp from 'openpgp';
import * as fetch from 'node-fetch';
import {
BASEURL,
getBaseUrl,
getUploaderName,
setFailure,
} from './helpers';
const verify = async (filename: string) => {
const verify = async (filename: string, platform: string) => {
try {
const uploaderName = getUploaderName();
const uploaderName = getUploaderName(platform);
// Read in public key
const publicKeyArmored = await fs.readFileSync(
@ -23,10 +23,10 @@ const verify = async (filename: string) => {
);
// Get SHASUM and SHASUM signature files
const shasumRes = await fetch( `${BASEURL}.SHA256SUM`);
const shasumRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM`);
const shasum = await shasumRes.text();
const shaSigRes = await fetch( `${BASEURL}.SHA256SUM.sig`);
const shaSigRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM.sig`);
const shaSig = await shaSigRes.text();
// Verify shasum