diff --git a/.github/workflows/example-recording.yml b/.github/workflows/example-recording.yml index eb609ef05..1d315ffba 100644 --- a/.github/workflows/example-recording.yml +++ b/.github/workflows/example-recording.yml @@ -73,6 +73,29 @@ jobs: echo Cypress finished with: ${{ steps.cypress.outcome }} echo See results at ${{ steps.cypress.outputs.resultsUrl }} + # print the `runResults` output directly as string + - name: Print Cypress run results output + run: | + echo Cypress run results: ${{ steps.cypress.outputs.runResults }} + + # parse the `runResults` output as JSON. + # Note that the output is a string and empty if there is a custom command passed to the action and the command runs through CLI + - name: Parse the Cypress run results output + uses: actions/github-script@v6 + with: + script: | + if (${{ steps.cypress.outputs.runResults }} == "") { + console.log('No run results found') + return + } + + const runResults = JSON.parse('${{ steps.cypress.outputs.runResults }}') + console.log("TotalPassed: " + runResults.totalPassed) + console.log("TotalFailed: " + runResults.totalFailed) + console.log("TotalPending: " + runResults.totalPending) + console.log("TotalSkipped: " + runResults.totalSkipped) + console.log("TotalDuration: " + runResults.totalDuration) + group: runs-on: ubuntu-22.04 needs: [check-record-key] diff --git a/README.md b/README.md index 253c44d94..5c08ec8a4 100644 --- a/README.md +++ b/README.md @@ -1382,6 +1382,23 @@ This is an example of using the step output `resultsUrl`: The GitHub step output `dashboardUrl` is deprecated. Cypress Dashboard is now [Cypress Cloud](https://on.cypress.io/cloud-introduction). +This action also sets a GitHub step output `runResults` which contains a stringified JSON object. + +This is an example of parsing the `runResults`. + +```yaml +... + steps: + - name: Parse run results + uses: actions/github-script@v6 + with: + script: | + const runResults = JSON.parse('${{ steps.cypress-run.outputs.runResults }}') + console.log(runResults.totalPassed) + ... +``` +Structure of the run results object can be found [here](https://docs.cypress.io/guides/guides/module-api#Results). + [![recording example](https://github.com/cypress-io/github-action/workflows/example-recording/badge.svg?branch=master)](.github/workflows/example-recording.yml) **Note:** every GitHub workflow step can have `outcome` and `conclusion` properties. See the GitHub [Contexts](https://docs.github.com/en/actions/learn-github-actions/contexts) documentation section [steps context](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context). In particular, the `outcome` or `conclusion` value can be `success`, `failure`, `cancelled`, or `skipped` which you can use in any following steps. diff --git a/action.yml b/action.yml index d5d1b4609..f19250c86 100644 --- a/action.yml +++ b/action.yml @@ -96,6 +96,8 @@ outputs: description: 'Cypress Cloud URL if the run was recorded (deprecated)' resultsUrl: description: 'Cypress Cloud URL if the run was recorded' + runResults: + description: 'Cypress run results (stringified JSON object)' runs: using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 80ce2b240..dd3201984 100644 --- a/dist/index.js +++ b/dist/index.js @@ -75212,6 +75212,8 @@ const runTests = async () => { debug(`Cypress options ${JSON.stringify(cypressOptions)}`) const onTestsFinished = (testResults) => { + core.setOutput('runResults', testResults) + const resultsUrl = testResults.runUrl process.chdir(startWorkingDirectory) diff --git a/index.js b/index.js index 2b550e382..869dbfc6e 100644 --- a/index.js +++ b/index.js @@ -816,6 +816,8 @@ const runTests = async () => { debug(`Cypress options ${JSON.stringify(cypressOptions)}`) const onTestsFinished = (testResults) => { + core.setOutput('runResults', testResults) + const resultsUrl = testResults.runUrl process.chdir(startWorkingDirectory)