-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2aa285
commit 285f6f5
Showing
10 changed files
with
383 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
function add (a,b) { | ||
return a+b | ||
if (a>b){ | ||
return a-b | ||
} | ||
return a+b | ||
} | ||
|
||
add(1, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IProvider } from '../types' | ||
|
||
import * as providerGitHubactions from './provider_githubactions' | ||
import * as providerGitLabci from './provider_gitlabci' | ||
|
||
const providerList: IProvider[] = [ | ||
providerGitHubactions, | ||
providerGitLabci, | ||
] | ||
|
||
export default providerList |
70 changes: 70 additions & 0 deletions
70
plugins/babel-plugin-canyon/src/ci_providers/provider_githubactions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types' | ||
|
||
|
||
export function detect(envs: UploaderEnvs): boolean { | ||
return Boolean(envs.GITHUB_ACTIONS) | ||
} | ||
|
||
function _getBranch(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
const branchRegex = /refs\/heads\/(.*)/ | ||
const branchMatches = branchRegex.exec(envs.GITHUB_REF || '') | ||
let branch | ||
if (branchMatches) { | ||
branch = branchMatches[1] | ||
} | ||
|
||
if (envs.GITHUB_HEAD_REF && envs.GITHUB_HEAD_REF !== '') { | ||
branch = envs.GITHUB_HEAD_REF | ||
} | ||
return args.branch || branch || '' | ||
} | ||
|
||
function _getJob(envs: UploaderEnvs): string { | ||
return (envs.GITHUB_WORKFLOW || '') | ||
} | ||
|
||
function _getService(): string { | ||
return 'github-actions' | ||
} | ||
|
||
export function getServiceName(): string { | ||
return 'GitHub Actions' | ||
} | ||
|
||
function _getSHA(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
return args.sha || envs.GITHUB_SHA | ||
} | ||
|
||
function _getSlug(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
if (args.slug !== '') return args.slug | ||
return envs.GITHUB_REPOSITORY || '' | ||
} | ||
|
||
export function getServiceParams(inputs: UploaderInputs): IServiceParams { | ||
return { | ||
branch: _getBranch(inputs), | ||
// build: _getBuild(inputs), | ||
// buildURL: await _getBuildURL(inputs), | ||
commit: _getSHA(inputs), | ||
// job: _getJob(inputs.envs), | ||
// pr: _getPR(inputs), | ||
service: _getService(), | ||
slug: _getSlug(inputs), | ||
} | ||
} | ||
|
||
export function getEnvVarNames(): string[] { | ||
return [ | ||
'GITHUB_ACTION', | ||
'GITHUB_HEAD_REF', | ||
'GITHUB_REF', | ||
'GITHUB_REPOSITORY', | ||
'GITHUB_RUN_ID', | ||
'GITHUB_SERVER_URL', | ||
'GITHUB_SHA', | ||
'GITHUB_WORKFLOW', | ||
] | ||
} |
83 changes: 83 additions & 0 deletions
83
plugins/babel-plugin-canyon/src/ci_providers/provider_gitlabci.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types' | ||
|
||
// import { parseSlugFromRemoteAddr } from '../helpers/git' | ||
|
||
export function detect(envs: UploaderEnvs): boolean { | ||
return Boolean(envs.GITLAB_CI) | ||
} | ||
|
||
function _getBuild(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
return args.build || envs.CI_BUILD_ID || envs.CI_JOB_ID || '' | ||
} | ||
|
||
function _getBuildURL(): string { | ||
return '' | ||
} | ||
|
||
function _getBranch(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
return args.branch || envs.CI_BUILD_REF_NAME || envs.CI_COMMIT_REF_NAME || '' | ||
} | ||
|
||
function _getJob(): string { | ||
return '' | ||
} | ||
|
||
function _getPR(inputs: UploaderInputs): string { | ||
const { args } = inputs | ||
return args.pr || '' | ||
} | ||
|
||
function _getService(): string { | ||
return 'gitlab' | ||
} | ||
|
||
export function getServiceName(): string { | ||
return 'GitLab CI' | ||
} | ||
|
||
function _getSHA(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
return args.sha || envs.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || envs.CI_BUILD_REF || envs.CI_COMMIT_SHA || '' | ||
} | ||
|
||
function _getSlug(inputs: UploaderInputs): string { | ||
const { args, envs } = inputs | ||
if (args.slug !== '') return args.slug | ||
const remoteAddr = envs.CI_BUILD_REPO || envs.CI_REPOSITORY_URL || '' | ||
return ( | ||
envs.CI_PROJECT_PATH || | ||
// parseSlugFromRemoteAddr(remoteAddr) || | ||
'' | ||
) | ||
} | ||
|
||
export function getServiceParams(inputs: UploaderInputs): IServiceParams { | ||
return { | ||
branch: _getBranch(inputs), | ||
// build: _getBuild(inputs), | ||
// buildURL: _getBuildURL(), | ||
commit: _getSHA(inputs), | ||
// job: _getJob(), | ||
// pr: _getPR(inputs), | ||
service: _getService(), | ||
slug: _getSlug(inputs), | ||
} | ||
} | ||
|
||
export function getEnvVarNames(): string[] { | ||
return [ | ||
'CI_BUILD_ID', | ||
'CI_BUILD_REF', | ||
'CI_BUILD_REF_NAME', | ||
'CI_BUILD_REPO', | ||
'CI_COMMIT_REF_NAME', | ||
'CI_COMMIT_SHA', | ||
'CI_JOB_ID', | ||
'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA', | ||
'CI_PROJECT_PATH', | ||
'CI_REPOSITORY_URL', | ||
'GITLAB_CI', | ||
] | ||
} |
23 changes: 23 additions & 0 deletions
23
plugins/babel-plugin-canyon/src/helpers/extract-coverage-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function extractCoverageData(scriptContent) { | ||
const reg0 = /var\s+coverageData\s*=\s*({[\s\S]*?});/; | ||
const reg1 = /var\s+(\w+)\s*=\s*function\s*\(\)\s*\{([\s\S]*?)\}\(\);/ | ||
try { | ||
// 可能性一 | ||
const match0 = reg0.exec(scriptContent); | ||
if (match0) { | ||
const objectString = match0[1]; | ||
return new Function('return ' + objectString)(); | ||
} | ||
// 可能性二 | ||
const match1 = reg1.exec(scriptContent); | ||
if (match1) { | ||
const functionBody = match1[2]; | ||
const func = new Function(functionBody + 'return coverageData;'); | ||
const result = func(); | ||
return result; | ||
} | ||
} catch (e) { | ||
return null; | ||
} | ||
return null | ||
} |
19 changes: 19 additions & 0 deletions
19
plugins/babel-plugin-canyon/src/helpers/generate-initial-coverage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import fs from 'fs'; | ||
import path from 'path' | ||
import {extractCoverageData} from "./extract-coverage-data"; | ||
|
||
export const generateInitialCoverage = (paramsPath) => { | ||
const initialCoverageDataForTheCurrentFile = extractCoverageData(paramsPath) | ||
const filePath = './.canyon_output/coverage-final.json'; | ||
const dir = path.dirname(filePath); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, {recursive: true}); | ||
} | ||
// 防止返回的数据为空 | ||
if (initialCoverageDataForTheCurrentFile && initialCoverageDataForTheCurrentFile.path) { | ||
fs.writeFileSync(`./.canyon_output/coverage-map-${Math.random()}.json`, JSON.stringify({ | ||
[initialCoverageDataForTheCurrentFile.path]: initialCoverageDataForTheCurrentFile | ||
}, null, 2), 'utf-8'); | ||
} | ||
return initialCoverageDataForTheCurrentFile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// import { Dispatcher, ProxyAgent } from "undici"; | ||
|
||
export interface UploaderArgs { | ||
branch?: string // Specify the branch manually | ||
build?: string // Specify the build number manually | ||
changelog?: string // Displays the changelog and exits | ||
clean?: string // Move discovered coverage reports to the trash | ||
dir?: string // Directory to search for coverage reports. | ||
dryRun?: string // Don't upload files to Codecov | ||
env?: string // Specify environment variables to be included with this build | ||
feature?: string // Toggle features | ||
file?: string | string[] // Target file(s) to upload | ||
flags: string | string[] // Flag the upload to group coverage metrics | ||
fullReport?: string // Specify the path to a previously uploaded Codecov report | ||
gcov?: string // Run with gcov support | ||
gcovArgs?: string | string[] // Extra arguments to pass to gcov | ||
gcovIgnore?: string | string[] // Paths to ignore during gcov gathering | ||
gcovInclude?: string | string[] // Paths to include during gcov gathering | ||
gcovExecutable?: string // gcov executable to run. | ||
name?: string // Custom defined name of the upload. Visible in Codecov UI | ||
networkFilter?: string // Specify a prefix on the files listed in the network section of the Codecov report. Useful for upload-specific path fixing | ||
networkPrefix?: string // Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing | ||
nonZero?: string // Should errors exit with a non-zero (default: false) | ||
parent?: string // The commit SHA of the parent for which you are uploading coverage. | ||
pr?: string // Specify the pull request number manually | ||
preventSymbolicLinks?: string // Specifies whether to prevent following of symoblic links | ||
rootDir?: string // Specify the project root directory when not in a git repo | ||
sha?: string // Specify the commit SHA manually | ||
slug: string // Specify the slug manually | ||
source?: string // Track wrappers of the uploader | ||
swift?: string // Run with swift support | ||
swiftProject?: string // Specify the swift project | ||
tag?: string // Specify the git tag | ||
token?: string // Codecov upload token | ||
upstream: string // Upstream proxy to connect to | ||
url?: string // Change the upload host (Enterprise use) | ||
useCwd?: boolean | ||
verbose?: string // Run with verbose logging | ||
xcode?: string // Run with xcode support | ||
xcodeArchivePath?: string // Specify the xcode archive path. Likely specified as the -resultBundlePath and should end in .xcresult | ||
} | ||
|
||
export type UploaderEnvs = NodeJS.Dict<string> | ||
|
||
export interface UploaderInputs { | ||
envs: UploaderEnvs | ||
args: UploaderArgs | ||
} | ||
|
||
export interface IProvider { | ||
detect: (arg0: UploaderEnvs) => boolean | ||
getServiceName: () => string | ||
getServiceParams: (arg0: UploaderInputs) => IServiceParams | ||
getEnvVarNames: () => string[] | ||
} | ||
|
||
export interface IServiceParams { | ||
branch: string | ||
// build: string | ||
// buildURL: string | ||
commit: string | ||
// job: string | ||
// pr: string | '' | ||
service: string | ||
slug: string | ||
// name?: string | ||
// tag?: string | ||
// flags?: string | ||
// parent?: string | ||
// project?: string | ||
// server_uri?: string | ||
} | ||
|
||
// export interface IRequestHeaders { | ||
// agent?: ProxyAgent | ||
// url: URL | ||
// options: Dispatcher.RequestOptions | ||
// } | ||
|
||
export interface PostResults { | ||
putURL: URL | ||
resultURL: URL | ||
} | ||
|
||
export interface PutResults { | ||
status: string | ||
resultURL: URL | ||
} | ||
|
||
export type XcodeCoverageFileReport = Record<string, string | null> | ||
export type XcodeCoverageReport = Record<string, XcodeCoverageFileReport> |
Oops, something went wrong.