Allow specifying version of Codecov uploader

This commit is contained in:
Tom Hu
2021-09-09 13:15:02 -04:00
parent f6d4366a4c
commit 72dfd4782e
14 changed files with 170 additions and 35 deletions

View File

@@ -37,8 +37,9 @@ const buildExec = () => {
const searchDir = core.getInput('directory');
const slug = core.getInput('slug');
const token = core.getInput('token');
const verbose = isTrue(core.getInput('verbose'));
let uploaderVersion = core.getInput('version');
const url = core.getInput('url');
const verbose = isTrue(core.getInput('verbose'));
const workingDir = core.getInput('working-directory');
const execArgs = [];
@@ -147,7 +148,11 @@ const buildExec = () => {
options.cwd = workingDir;
}
return {execArgs, options, failCi, os};
if (uploaderVersion == '') {
uploaderVersion = 'latest';
}
return {execArgs, options, failCi, os, uploaderVersion};
};
export default buildExec;

View File

@@ -37,13 +37,22 @@ test('getPlatform', () => {
test('getBaseUrl', () => {
expect(PLATFORMS.map((platform) => {
return getBaseUrl(platform);
return getBaseUrl(platform, 'latest');
})).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',
]);
expect(PLATFORMS.map((platform) => {
return getBaseUrl(platform, 'v0.1.0_8880');
})).toEqual([
'https://uploader.codecov.io/v0.1.0_8880/alpine/codecov',
'https://uploader.codecov.io/v0.1.0_8880/linux/codecov',
'https://uploader.codecov.io/v0.1.0_8880/macos/codecov',
'https://uploader.codecov.io/v0.1.0_8880/windows/codecov.exe',
]);
});
test('isWindows', () => {

View File

@@ -43,8 +43,8 @@ const getPlatform = (os?: string): string => {
return 'linux';
};
const getBaseUrl = (platform: string): string => {
return `https://uploader.codecov.io/latest/${platform}/${getUploaderName(platform)}`;
const getBaseUrl = (platform: string, version: string): string => {
return `https://uploader.codecov.io/${version}/${platform}/${getUploaderName(platform)}`;
};
export {

View File

@@ -13,15 +13,16 @@ import {
} from './helpers';
import verify from './validate';
import versionInfo from './version';
let failCi;
try {
const {execArgs, options, failCi, os} = buildExec();
const {execArgs, options, failCi, os, uploaderVersion} = buildExec();
const platform = getPlatform(os);
const filename = path.join( __dirname, getUploaderName(platform));
https.get(getBaseUrl(platform), (res) => {
https.get(getBaseUrl(platform, uploaderVersion), (res) => {
// Image will be stored at this path
const filePath = fs.createWriteStream(filename);
res.pipe(filePath);
@@ -34,7 +35,8 @@ try {
}).on('finish', async () => {
filePath.close();
await verify(filename, platform);
await verify(filename, platform, uploaderVersion);
await versionInfo(platform, uploaderVersion);
await fs.chmodSync(filename, '777');
const unlink = () => {

View File

@@ -12,7 +12,7 @@ import {
setFailure,
} from './helpers';
const verify = async (filename: string, platform: string) => {
const verify = async (filename: string, platform: string, version: string) => {
try {
const uploaderName = getUploaderName(platform);
@@ -23,10 +23,15 @@ const verify = async (filename: string, platform: string) => {
);
// Get SHASUM and SHASUM signature files
const shasumRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM`);
console.log(`${getBaseUrl(platform, version)}.SHA256SUM`);
const shasumRes = await fetch(
`${getBaseUrl(platform, version)}.SHA256SUM`,
);
const shasum = await shasumRes.text();
const shaSigRes = await fetch( `${getBaseUrl(platform)}.SHA256SUM.sig`);
const shaSigRes = await fetch(
`${getBaseUrl(platform, version)}.SHA256SUM.sig`,
);
const shaSig = await shaSigRes.text();
// Verify shasum

19
src/version.ts Normal file
View File

@@ -0,0 +1,19 @@
import * as core from '@actions/core';
import * as fetch from 'node-fetch';
const versionInfo = async (platform: string, version?: string) => {
if (version) {
core.info(`==> Running version ${version}`);
}
try {
const metadataRes = await fetch( `https://uploader.codecov.io/${platform}/latest`, {
headers: {'Accept': 'application/json'},
});
const metadata = await metadataRes.json();
core.info(`==> Running version ${metadata['version']}`);
} catch (err) {
core.info(`Could not pull latest version information: ${err}`);
}
};
export default versionInfo;