Skip to content

Commit

Permalink
fix: add output param to specify output folder
Browse files Browse the repository at this point in the history
  • Loading branch information
edd committed Jul 3, 2023
1 parent 03b2bb7 commit 4ddd8b1
Show file tree
Hide file tree
Showing 6 changed files with 2,754 additions and 11 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest check-filena
| `--show-file-stats` | boolean | display detailed stats per file | - |
| `--output-csv` | boolean | Outputs a CSV file to summarise the console output | - |
| `--output-jenkins` | boolean | Outputs a text file to summarise the console output, to sendover to jenkins | - |
| `--output` | string | A path to write the CSV or Jenkins output to | `./results` |
| `--verbose` | boolean | MORE output | - |
### check-references example
Expand All @@ -80,7 +81,7 @@ docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest check-filena
npx github:vegaprotocol/approbation@latest check-references --specs="./specs/protocol/**/*.{md,ipynb}" --tests="./MultisigControl/test/*.js" --ignore="./specs/protocol/{0001-*}" --categories="specs/protocol/categories.json" --show-branches --show-mystery
# Or run the docker image
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest check-references --specs="/run/specs/protocol/**/*.{md,ipynb}" --tests="/run/MultisigControl/test/*.js" --ignore="/run/specs/protocol/{0001-*}" --categories="/run/specs/protocol/categories.json" --show-branches --show-mystery
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest check-references --specs="/run/specs/protocol/**/*.{md,ipynb}" --tests="/run/MultisigControl/test/*.js" --ignore="/run/specs/protocol/{0001-*}" --categories="/run/specs/protocol/categories.json" --show-branches --show-mystery --output-csv --output="/run/results/"
```
Expand Down
25 changes: 24 additions & 1 deletion bin/approbation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const pc = require('picocolors')
const { outputBranches } = require('../src/lib/get-project-branches')
const argv = require('minimist')(process.argv.slice(2))
const command = argv._[0]
const IS_DEBUG = process.env.debug !== undefined

function debugOutput (text) {
if (IS_DEBUG) {
console.log(pc.purple(text))
}
}

function warn (lines) {
console.warn('')
Expand Down Expand Up @@ -60,6 +67,7 @@ if (command === 'check-filenames') {
res = checkCodes(paths, ignoreGlob, isVerbose)
process.exit(res.exitCode)
} else if (command === 'check-references') {
debugOutput('check-references')
const specsGlob = argv.specs
const testsGlob = argv.tests
const categories = argv.categories
Expand All @@ -69,6 +77,7 @@ if (command === 'check-filenames') {
const isVerbose = argv.verbose === true
const showFiles = argv['show-files'] === true
const shouldOutputCSV = argv['output-csv'] === true
let outputPath = argv.output
const shouldOutputJenkins = argv['output-jenkins'] === true
const shouldShowFileStats = argv['show-file-stats'] === true

Expand All @@ -87,8 +96,22 @@ if (command === 'check-filenames') {
process.exit(1)
}

if (shouldOutputCSV || shouldOutputJenkins) {
if (!outputPath || outputPath.length === 0) {
console.error(pc.yellow('Output path should be provided with --output if CSV or Jenkins output are enabled. Defaulting to ./results'))
outputPath = './results'
} else {
// Ensure we don't have a trailing slash for consistency with the default
if (outputPath && outputPath.endsWith('/')) {
debugOutput(`Removing trailing slash from output path: ${outputPath}`)
outputPath = outputPath.slice(0, -1)
}
console.info(pc.yellow(`Output folder: ${outputPath}`))
}
}

// TODO: Turn in to an object
res = checkReferences(specsGlob, testsGlob, categories, ignoreGlob, showMystery, isVerbose, showCategoryStats, showFiles, shouldOutputCSV, shouldOutputJenkins, shouldShowFileStats)
res = checkReferences(specsGlob, testsGlob, categories, ignoreGlob, showMystery, isVerbose, showCategoryStats, showFiles, shouldOutputCSV, shouldOutputJenkins, shouldShowFileStats, outputPath)

process.exit(res.exitCode)
} else {
Expand Down
Loading

0 comments on commit 4ddd8b1

Please sign in to comment.