Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying version of Codecov uploader #515

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
file: ./coverage/coverage-final.json
flags: demo,${{ matrix.os }}
name: codecov-demo
- name: Upload coverage to Codecov (version)
uses: ./
with:
files: ./coverage/calculator/coverage-final.json,./coverage/coverage-test/coverage-final.json
file: ./coverage/coverage-final.json
flags: version,${{ matrix.os }}
name: codecov-version
version: v0.1.0_8880
run:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -49,3 +57,11 @@ jobs:
file: ./coverage/coverage-final.json
flags: demo,${{ matrix.os }}
name: codecov-demo
- name: Upload coverage to Codecov (version)
uses: ./
with:
files: ./coverage/calculator/coverage-final.json,./coverage/coverage-test/coverage-final.json
file: ./coverage/coverage-final.json
flags: version,${{ matrix.os }}
name: codecov-version
version: v0.1.0_8880
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2.1.0
### Features
- #515 Allow specifying version of Codecov uploader

### Dependencies
- #499 build(deps-dev): bump @vercel/ncc from 0.29.0 to 0.30.0
- #508 build(deps): bump openpgp from 5.0.0-5 to 5.0.0
- #514 build(deps-dev): bump @types/node from 16.6.0 to 16.9.0

## 2.0.3
### Fixes
- #464 Fix wrong link in the readme
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Codecov's Action currently supports five inputs from the user: `token`, `file`,
| `slug` | Specify the slug manually (Enterprise use) | Optional
| `url` | Change the upload host (Enterprise use) | Optional
| `verbose` | Specify whether the Codecov output should be verbose | Optional
| `version` | Specify which version of the Codecov Uploader should be used. Defaults to `latest` | Optional
| `working-directory` | Directory in which to execute `codecov.sh` | Optional

### Example `workflow.yml` with Codecov Action
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ inputs:
verbose:
description: 'Specify whether the Codecov output should be verbose'
required: false
version:
description: 'Specify which version of the Codecov Uploader should be used. Defaults to `latest`'
required: false
working-directory:
description: 'Directory in which to execute codecov.sh'
required: false
Expand Down
106 changes: 86 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = 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;
const command_1 = __nccwpck_require__(5241);
const file_command_1 = __nccwpck_require__(717);
const utils_1 = __nccwpck_require__(5278);
Expand Down Expand Up @@ -312,19 +312,30 @@ exports.debug = debug;
/**
* Adds an error issue
* @param message error issue message. Errors will be converted to string via toString()
* @param properties optional properties to add to the annotation.
*/
function error(message) {
command_1.issue('error', message instanceof Error ? message.toString() : message);
function error(message, properties = {}) {
command_1.issueCommand('error', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports.error = error;
/**
* Adds an warning issue
* Adds a warning issue
* @param message warning issue message. Errors will be converted to string via toString()
* @param properties optional properties to add to the annotation.
*/
function warning(message) {
command_1.issue('warning', message instanceof Error ? message.toString() : message);
function warning(message, properties = {}) {
command_1.issueCommand('warning', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports.warning = warning;
/**
* Adds a notice issue
* @param message notice issue message. Errors will be converted to string via toString()
* @param properties optional properties to add to the annotation.
*/
function notice(message, properties = {}) {
command_1.issueCommand('notice', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports.notice = notice;
/**
* Writes info to log with console.log.
* @param message info message
Expand Down Expand Up @@ -458,7 +469,7 @@ exports.issueCommand = issueCommand;
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toCommandValue = void 0;
exports.toCommandProperties = exports.toCommandValue = void 0;
/**
* Sanitizes an input into a string so it can be passed into issueCommand safely
* @param input input to sanitize into a string
Expand All @@ -473,6 +484,25 @@ function toCommandValue(input) {
return JSON.stringify(input);
}
exports.toCommandValue = toCommandValue;
/**
*
* @param annotationProperties
* @returns The command properties to send with the actual annotation command
* See IssueCommandProperties: https://github.com/actions/runner/blob/main/src/Runner.Worker/ActionCommandManager.cs#L646
*/
function toCommandProperties(annotationProperties) {
if (!Object.keys(annotationProperties).length) {
return {};
}
return {
title: annotationProperties.title,
line: annotationProperties.startLine,
endLine: annotationProperties.endLine,
col: annotationProperties.startColumn,
endColumn: annotationProperties.endColumn
};
}
exports.toCommandProperties = toCommandProperties;
//# sourceMappingURL=utils.js.map

/***/ }),
Expand Down Expand Up @@ -12829,7 +12859,7 @@ function wrappy (fn, cb) {

/***/ }),

/***/ 3997:
/***/ 5765:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

"use strict";
Expand All @@ -12849,7 +12879,7 @@ var core = __nccwpck_require__(2186);
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
var github = __nccwpck_require__(5438);
;// CONCATENATED MODULE: ./package.json
const package_namespaceObject = {"i8":"2.0.3"};
const package_namespaceObject = {"i8":"2.1.0"};
;// CONCATENATED MODULE: ./src/buildExec.ts


Expand Down Expand Up @@ -12884,8 +12914,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 = [];
execArgs.push('-n', `${name}`, '-Q', `github-action-${package_namespaceObject.i8}`);
Expand Down Expand Up @@ -12982,7 +13013,10 @@ const buildExec = () => {
if (workingDir) {
options.cwd = workingDir;
}
return { execArgs, options, failCi, os };
if (uploaderVersion == '') {
uploaderVersion = 'latest';
}
return { execArgs, options, failCi, os, uploaderVersion };
};
/* harmony default export */ const src_buildExec = (buildExec);

Expand Down Expand Up @@ -13023,8 +13057,8 @@ const getPlatform = (os) => {
core.info('==> Could not detect OS or provided OS is invalid. Defaulting to linux');
return 'linux';
};
const getBaseUrl = (platform) => {
return `https://uploader.codecov.io/latest/${platform}/${getUploaderName(platform)}`;
const getBaseUrl = (platform, version) => {
return `https://uploader.codecov.io/${version}/${platform}/${getUploaderName(platform)}`;
};


Expand All @@ -13051,15 +13085,16 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume



const verify = (filename, platform) => __awaiter(void 0, void 0, void 0, function* () {
const verify = (filename, platform, version) => __awaiter(void 0, void 0, void 0, function* () {
try {
const uploaderName = getUploaderName(platform);
// Read in public key
const publicKeyArmored = yield external_fs_.readFileSync(__nccwpck_require__.ab + "pgp_keys.asc", 'utf-8');
// Get SHASUM and SHASUM signature files
const shasumRes = yield lib(`${getBaseUrl(platform)}.SHA256SUM`);
console.log(`${getBaseUrl(platform, version)}.SHA256SUM`);
const shasumRes = yield lib(`${getBaseUrl(platform, version)}.SHA256SUM`);
const shasum = yield shasumRes.text();
const shaSigRes = yield lib(`${getBaseUrl(platform)}.SHA256SUM.sig`);
const shaSigRes = yield lib(`${getBaseUrl(platform, version)}.SHA256SUM.sig`);
const shaSig = yield shaSigRes.text();
// Verify shasum
const verified = yield openpgp_min/* verify */.T({
Expand Down Expand Up @@ -13099,6 +13134,35 @@ const verify = (filename, platform) => __awaiter(void 0, void 0, void 0, functio
});
/* harmony default export */ const validate = (verify);

;// CONCATENATED MODULE: ./src/version.ts
var version_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};


const versionInfo = (platform, version) => version_awaiter(void 0, void 0, void 0, function* () {
if (version) {
core.info(`==> Running version ${version}`);
}
try {
const metadataRes = yield lib(`https://uploader.codecov.io/${platform}/latest`, {
headers: { 'Accept': 'application/json' },
});
const metadata = yield metadataRes.json();
core.info(`==> Running version ${metadata['version']}`);
}
catch (err) {
core.info(`Could not pull latest version information: ${err}`);
}
});
/* harmony default export */ const version = (versionInfo);

;// CONCATENATED MODULE: ./src/index.ts
var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand All @@ -13116,12 +13180,13 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu




let failCi;
try {
const { execArgs, options, failCi, os } = src_buildExec();
const { execArgs, options, failCi, os, uploaderVersion } = src_buildExec();
const platform = getPlatform(os);
const filename = external_path_.join(__dirname, getUploaderName(platform));
external_https_.get(getBaseUrl(platform), (res) => {
external_https_.get(getBaseUrl(platform, uploaderVersion), (res) => {
// Image will be stored at this path
const filePath = external_fs_.createWriteStream(filename);
res.pipe(filePath);
Expand All @@ -13130,7 +13195,8 @@ try {
setFailure(`Codecov: Failed to write uploader binary: ${err.message}`, true);
}).on('finish', () => src_awaiter(void 0, void 0, void 0, function* () {
filePath.close();
yield validate(filename, platform);
yield validate(filename, platform, uploaderVersion);
yield version(platform, uploaderVersion);
yield external_fs_.chmodSync(filename, '777');
const unlink = () => {
external_fs_.unlink(filename, (err) => {
Expand Down Expand Up @@ -13372,7 +13438,7 @@ module.exports = require("zlib");
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module doesn't tell about it's top-level declarations so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(3997);
/******/ var __webpack_exports__ = __nccwpck_require__(5765);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codecov-action",
"version": "2.0.3",
"version": "2.1.0",
"description": "Upload coverage reports to Codecov from GitHub Actions",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
11 changes: 10 additions & 1 deletion src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = () => {
Expand Down
Loading