|
1 | 1 | import { createHash, timingSafeEqual } from 'crypto';
|
2 | 2 | import { readFile, createWriteStream } from 'fs';
|
| 3 | +import { platform } from 'os'; |
3 | 4 | import { promisify } from 'util';
|
4 | 5 | import { getInput } from '@actions/core';
|
5 | 6 | import fetch from 'node-fetch';
|
@@ -180,3 +181,49 @@ export async function verifySignature(
|
180 | 181 | return false;
|
181 | 182 | }
|
182 | 183 | }
|
| 184 | + |
| 185 | +/** |
| 186 | + * Parses a given coverage config line that looks like this – |
| 187 | + * |
| 188 | + * ``` |
| 189 | + * /Users/gp/projects/cc/*.lcov:lcov |
| 190 | + * ``` |
| 191 | + * |
| 192 | + * or – |
| 193 | + * |
| 194 | + * ``` |
| 195 | + * D:\Users\gp\projects\cc\*.lcov:lcov |
| 196 | + * ``` |
| 197 | + * |
| 198 | + * into – |
| 199 | + * |
| 200 | + * ```json |
| 201 | + * { "format": "lcov", "pattern": "/Users/gp/projects/cc/*.lcov" } |
| 202 | + * ``` |
| 203 | + * |
| 204 | + * or – |
| 205 | + * |
| 206 | + * ```json |
| 207 | + * { "format": "lcov", "pattern": "D:\Users\gp\projects\cc\*.lcov" } |
| 208 | + * ``` |
| 209 | + * @param coverageConfigLine |
| 210 | + * @returns |
| 211 | + */ |
| 212 | +export function parsePathAndFormat(coverageConfigLine: string): { |
| 213 | + format: string; |
| 214 | + pattern: string; |
| 215 | +} { |
| 216 | + let lineParts = coverageConfigLine.split(':'); |
| 217 | + // On Windows, if the glob received an absolute path, the path will |
| 218 | + // include the Drive letter and the path – for example, `C:\Users\gp\projects\cc\*.lcov:lcov` |
| 219 | + // which leads to 2 colons. So we handle this special case. |
| 220 | + if ( |
| 221 | + platform() === 'win32' && |
| 222 | + (coverageConfigLine.match(/:/g) || []).length > 1 |
| 223 | + ) { |
| 224 | + lineParts = [lineParts.slice(0, -1).join(':'), lineParts.slice(-1)[0]]; |
| 225 | + } |
| 226 | + const format = lineParts.slice(-1)[0]; |
| 227 | + const pattern = lineParts.slice(0, -1)[0]; |
| 228 | + return { format, pattern }; |
| 229 | +} |
0 commit comments