Skip to content

Commit

Permalink
feat: set merged result to output (#136)
Browse files Browse the repository at this point in the history
* feat: set merged result to output

* print output step

* small tweaks
  • Loading branch information
bahmutov committed Oct 17, 2023
1 parent 0e2b309 commit 9e192d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ jobs:
runTests: false

- name: Merge example timings ⛙
run: npm run demo-merge
id: merge
run: npm run demo-merge -- --set-gha-output merged

- name: Show merged output
run: |
echo off
echo '${{ steps.merge.outputs.merged }}'
test-split:
needs: prepare
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ For specs not in the timings file, it will use average duration of the known spe

If the timings file does not exist yet, the timings will be written into the file after the run finishes. If the file exists, and the new timings have new entries or the existing entries are off by more than 10% duration, the merged file is written back. Timing for specs without any passes tests or with failed tests is ignored.

## Merging timings files

This module includes a bin utility to merge multiple timings files into one. Example:

```
npx cypress-split-merge \
--parent-folder partials/ \
--split-file timings.json \
--output out-timings.json \
--set-gha-output merged-timing
```

The above command finds all `timings.json` file in the sub folders of `partials/` folder and merges them. It saved the result to `out-timings.json` file and if running on GitHub Actions sets the job output named `merged-timing` to a stringified single line JSON line.

## CI summary

To skip GitHub Actions summary, set an environment variable `SPLIT_SUMMARY=false`. By default, this plugin generates the summary.
Expand Down
11 changes: 11 additions & 0 deletions bin/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const debug = require('debug')('cypress-split')
const globby = require('globby')
const fs = require('fs')
const { mergeSplitTimings } = require('../src/timings')
const ghCore = require('@actions/core')

const label = 'cypress-split-merge'

const args = arg({
'--split-file': String,
'--parent-folder': String,
'--output': String, // output filename to write
'--set-gha-output': String, // output merged json string
// aliases
'-o': '--output',
})
Expand Down Expand Up @@ -57,3 +59,12 @@ if (args['--output']) {
console.log('%s merged timings:', label)
console.log(mergedText)
}

if (args['--set-gha-output']) {
console.log(
'%s setting timings as GHA output named "%s"',
label,
args['--set-gha-output'],
)
ghCore.setOutput(args['--set-gha-output'], JSON.stringify(merged))
}

0 comments on commit 9e192d4

Please sign in to comment.