Skip to content

Commit

Permalink
docs: updates on workflows
Browse files Browse the repository at this point in the history
Added information on documentation
  • Loading branch information
ADMSK\AVROGAL1 committed Mar 27, 2021
1 parent ed7962a commit 0d2fe95
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 12 deletions.
53 changes: 53 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
codecov:
notify:
wait_for_ci: false
require_ci_to_pass: true
strict_yaml_branch: master
branch: master

coverage:
precision: 2
round: down
range: "70...100"

status:
project:
default:
base: auto
informational: true
target: 95%
threshold: 1%
patch:
default:
informational: true
target: 80%
threshold: 1%
changes: no

notify:
# Wait for reasonable amount of tests to complete before
# reporting coverage
after_n_builds: 8

ignore:
- "**/generated/**"
- "data"
- "dist"
- "docs"
- "tests"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "header, reach, diff, flags, files, footer"
behavior: default
require_changes: false
require_base: false
require_head: true
branches: [ "master" ]
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ npm run changelog

git add docs/
git add src/
git add tests/
git add typings/

git add -f dist/index.js
git add CHANGELOG.md
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [0.0.0-dev](https://github.com/AlexRogalskiy/github-action-json-fields/compare/v2.0.1...v0.0.0-dev) (2021-03-25)
# [0.0.0-dev](https://github.com/AlexRogalskiy/github-action-json-fields/compare/v2.0.1...v0.0.0-dev) (2021-03-27)



2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"dependencies": {
"@actions/core": "^1.2.6",
"env-cmd": "^10.1.0",
"jsonpath": "^1.1.0"
"jsonpath": "^1.1.0",
"lodash": "^4.17.20"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
Expand All @@ -56,10 +57,12 @@
"@types/jest": "^26.0.20",
"@types/node": "^14.14.35",
"@types/prettier": "^2.1.5",
"@types/lodash.mergewith": "^4.6.6",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"@typescript-eslint/typescript-estree": "^4.17.0",
"@vercel/ncc": "~>0.27.0",
"dateformat": "^4.5.1",
"boxen": "^5.0.0",
"cz-conventional-changelog": "^3.3.0",
"conventional-changelog-cli": "^2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import * as core from '@actions/core'
import * as jp from 'jsonpath'

import { basename } from 'path'
import boxen from 'boxen'

import { ConfigOptions } from '../typings/domain-types'
import { JsonMode } from '../typings/enum-types'
import { BiPredicate, Comparator } from '../typings/standard-types'

import { valueError } from './errors/errors'

import { getType, isArray, isValidFile } from './utils/validators'
import { compareBy, compareByPropertyKey, compareIgnoreCase } from './utils/comparators'
import { getDataAsJson, storeDataAsJson } from './utils/files'
import { serialize } from './utils/serializers'

import { profile } from './utils/profiles'
import { coreError, coreInfo } from './utils/loggers'

const getFilter = <T>(jsonMode: JsonMode): BiPredicate<T> => (a: T, b: T) =>
jsonMode === JsonMode.unique ? a === b : a !== b
Expand Down Expand Up @@ -55,7 +55,7 @@ const processJsonQuery = async <T>(
}

const processSourceFile = async (options: ConfigOptions): Promise<boolean> => {
core.info(boxen(`Processing input file with options: ${serialize(options)}`, profile.outputOptions))
coreInfo(`Processing input file with options: ${serialize(options)}`)

const { sourceFile, targetPath, targetFile, mode, jsonPath, jsonFields } = options

Expand All @@ -68,7 +68,7 @@ const processSourceFile = async (options: ConfigOptions): Promise<boolean> => {

return true
} catch (e) {
core.error(`Cannot process input file: ${sourceFile}`)
coreError(`Cannot process input file: ${sourceFile}`)
throw e
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/commons.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash'

import { hasProperty } from './validators'

export const toString = (value: string | string[]): string => (Array.isArray(value) ? value[0] : value)
Expand All @@ -10,6 +12,11 @@ export const getDataByKeys = <T>(obj: T, keys: PropertyKey[]): any => {
return obj
}

export const mergeProps = <T>(...obj: any[]): T =>
_.mergeWith({}, ...obj, (o, s) => {
return _.isArray(s) && _.isArray(o) ? _.union(o, s) : _.isNull(s) ? o : s
})

export const setDataByKeys = <T>(obj: T, value: any, keys: PropertyKey[]): void => {
const last = keys.length - 1
const prop = keys[last]
Expand Down
115 changes: 115 additions & 0 deletions src/utils/loggers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import * as core from '@actions/core'
import dateFormat from 'dateformat'
import boxen from 'boxen'

import { Processor } from '../../typings/standard-types'

import { profile } from './profiles'

import { mergeProps } from './commons'

/**
* Logger
* @desc Type representing logging function
*/
type Logger<T, V> = (message: T, ...args: V[]) => void

const DATETIME_FORMAT = 'dddd, mmmm dS, yyyy, hh:MM:ss TT'

const getColor = (value: string, defaultValue = ''): string => (process.stdout.isTTY ? value : defaultValue)

const COLORS = {
RESET: getColor('\x1b[0m'),
BLACK: getColor('\x1b[0;30m'),
RED: getColor('\x1b[0;31m'),
GREEN: getColor('\x1b[0;32m'),
BROWN: getColor('\x1b[0;33m'),
BLUE: getColor('\x1b[0;34m'),
PURPLE: getColor('\x1b[0;35m'),
CYAN: getColor('\x1b[0;36m'),
LIGHT_GRAY: getColor('\x1b[0;37m'),
DARK_GRAY: getColor('\x1b[1;30m'),
LIGHT_RED: getColor('\x1b[1;31m'),
LIGHT_GREEN: getColor('\x1b[1;32m'),
YELLOW: getColor('\x1b[1;33m'),
LIGHT_BLUE: getColor('\x1b[1;34m'),
LIGHT_PURPLE: getColor('\x1b[1;35m'),
LIGHT_CYAN: getColor('\x1b[1;36m'),
WHITE: getColor('\x1b[1;37m'),
}

const getTime = (format = DATETIME_FORMAT, utc = false): string => {
return dateFormat(Date.now(), format, utc)
}

export const toLog = (message: string, ...args: any[]): void => {
console.group('>>>')
console.log(`${COLORS.PURPLE}${getTime()}:${COLORS.RESET}`, message, ...args)
console.groupEnd()
}

export const createLogger = <T>(logger: Logger<T, any>, processor?: Processor<T, T>): Logger<T, any> => {
return (message, ...args) => {
logger(processor ? processor(message) : message, ...args)
}
}

export const logs = createLogger((message, ...args) =>
console.log(`${COLORS.PURPLE}${getTime()}:${COLORS.RESET}`, message, args)
)
export const errorLogs = createLogger((message, ...args) =>
console.error(`${COLORS.RED}${getTime()}:${COLORS.RESET}`, message, args)
)
export const warnLogs = createLogger((message, ...args) =>
console.warn(`${COLORS.GREEN}${getTime()}:${COLORS.RESET}`, message, args)
)
export const debugLogs = createLogger((message, ...args) =>
console.debug(`${COLORS.BLUE}${getTime()}:${COLORS.RESET}`, message, args)
)
export const traceLogs = createLogger((message, ...args) =>
console.trace(`${COLORS.CYAN}${getTime()}:${COLORS.RESET}`, message, args)
)

export const boxenLogs = createLogger(console.log, message => boxen(message, profile.outputOptions))

export const boxenErrorLogs = createLogger(console.error, message =>
boxen(
message,
mergeProps(profile.outputOptions, {
borderColor: 'red',
borderStyle: 'double',
})
)
)
export const boxenWarnLogs = createLogger(console.warn, message =>
boxen(message, mergeProps(profile.outputOptions, { borderColor: 'green' }))
)
export const boxenDebugLogs = createLogger(console.debug, message =>
boxen(message, mergeProps(profile.outputOptions, { borderColor: 'blue' }))
)
export const boxenTraceLogs = createLogger(console.trace, message =>
boxen(message, mergeProps(profile.outputOptions, { borderColor: 'cyan' }))
)

export const coreInfo = createLogger(core.info, message => boxen(message, profile.outputOptions))

export const coreError = createLogger(core.error, message => boxen(message.toString(), profile.outputOptions))

export const logArrayElements = <T>(index: number, array: T[]): void => {
logs(`array[${index}] = ${array[index]}`)
}

export const dumpObject = (obj: any): string => {
let out = ''
if (obj && typeof obj === 'object') {
for (const i in obj) {
if (Object.prototype.hasOwnProperty.call(obj, i)) {
out += `${i}: ${obj[i]}n`
}
}
} else {
out = obj
}

return out
}
8 changes: 8 additions & 0 deletions typings/standard-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
*/
export type Optional<T> = T | null | undefined

/**
* Processor
* @desc Type representing processor function type in TypeScript
* @example
* type Processor = (v) => return new String(v)
*/
export type Processor<T, V> = (v: T) => V

/**
* BiPredicate
* @desc Type representing binary predicate function type in TypeScript
Expand Down

0 comments on commit 0d2fe95

Please sign in to comment.