Skip to content

Commit 435b438

Browse files
authored
docs: rework recording instructions with CYPRESS_RECORD_KEY (#1443)
1 parent 6f72d0f commit 435b438

File tree

1 file changed

+19
-39
lines changed

1 file changed

+19
-39
lines changed

README.md

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ The following examples demonstrate the actions' functions.
3939
- Run only some [spec files](#specs)
4040
- Test [project in subfolder](#project)
4141
- [Record results](#record-test-results-on-cypress-cloud) on Cypress Cloud
42-
- Storing the [Project ID and Record Key](#project-id-and-record-key)
4342
- Getting [Git information](#git-information) environment variables
4443
- Getting [PR and URL](#automatic-pr-number-and-url-detection) automatically
4544
- Overwriting [Merge SHA into SHA](#merge-sha-into-sha) message
@@ -383,9 +382,13 @@ For more information, visit [the Cypress command-line docs](https://on.cypress.i
383382

384383
### Record test results on Cypress Cloud
385384

386-
By setting the parameter `record` to `true`, you can record your test results into the [Cypress Cloud](https://on.cypress.io/cloud). Read the [Cypress Cloud documentation](https://on.cypress.io/guides/cloud/introduction) to learn how to sign up and create a Cypress Cloud project.
385+
By setting the parameter `record` to `true`, you can record your test results into [Cypress Cloud](https://on.cypress.io/cloud). Read the [Cypress Cloud setup](https://on.cypress.io/cloud/get-started/setup) documentation to learn how to sign up to Cypress Cloud, to create and set up a [Cloud project](https://on.cypress.io/cloud/account-management/projects) to get the required `projectId` and record key for recording.
387386

388-
We recommend passing the `GITHUB_TOKEN` secret (created by the GH Action automatically) as an environment variable. This will allow correctly identifying every build and avoid confusion when re-running a build.
387+
- The `projectId` can either be stored in the [Cypress Configuration File](https://on.cypress.io/app/references/configuration#Configuration-File) or passed to the action as an environment variable `CYPRESS_PROJECT_ID`. In the example below, it is retrieved from a [GitHub secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) variable.
388+
389+
- The record key is passed to the action as an environment variable `CYPRESS_RECORD_KEY`. We recommend you treat this value as sensitive and store it as a [GitHub secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) variable, so that access is restricted.
390+
391+
- We recommend passing the `GITHUB_TOKEN` secret (created by the GH Action automatically) as an environment variable. This will allow correctly identifying every build and avoid confusion when re-running a build.
389392

390393
```yml
391394
name: Cypress tests
@@ -403,40 +406,16 @@ jobs:
403406
with:
404407
record: true
405408
env:
409+
# pass the Cypress Cloud project ID as an environment variable or store it in the Cypress configuration file
410+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
411+
# pass the Cypress Cloud record key as an environment variable
412+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
406413
# pass GitHub token to allow accurately detecting a build vs a re-run build
407414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
408415
```
409416

410417
[![recording example](https://github.com/cypress-io/github-action/actions/workflows/example-recording.yml/badge.svg)](.github/workflows/example-recording.yml)
411418

412-
### Project ID and Record Key
413-
414-
To record the project needs `projectId` and `recordKey`.
415-
416-
Typically, the `projectId` is stored in the [Cypress Configuration File](https://docs.cypress.io/guides/references/configuration#Configuration-File), while the `recordKey` is set as a [CLI parameter](https://docs.cypress.io/guides/guides/command-line#cypress-run-record-key-lt-record-key-gt). If you want to avoid this, both the `projectId` and `recordKey` can be provided as environment variables using [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
417-
418-
```yml
419-
name: Cypress tests
420-
on: push
421-
jobs:
422-
cypress-run:
423-
name: Cypress run
424-
runs-on: ubuntu-24.04
425-
steps:
426-
- name: Checkout
427-
uses: actions/checkout@v4
428-
429-
- name: Cypress run
430-
uses: cypress-io/github-action@v6
431-
with:
432-
record: true
433-
env:
434-
# pass the Cypress Cloud record key as an environment variable
435-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
436-
# pass the project ID from the secrets through environment variable
437-
CYPRESS_PROJECT_ID: ${{ secrets.PROJECT_ID }}
438-
```
439-
440419
### Git information
441420

442421
Cypress uses the [@cypress/commit-info](https://github.com/cypress-io/commit-info) package to associate Git details (branch, commit message, author) with each run. It typically uses Git commands, expecting a .git folder. In Docker or similar environments where .git is absent, or if you need different data in the Cypress Cloud, Git information can be passed via custom environment variables.
@@ -451,14 +430,14 @@ jobs:
451430
steps:
452431
- name: Checkout
453432
uses: actions/checkout@v4
454-
455433
- name: Cypress run
456434
uses: cypress-io/github-action@v6
457435
with:
458436
record: true
459437
env:
460438
# Get the short ref name of the branch that triggered the workflow run
461439
COMMIT_INFO_BRANCH: ${{ github.ref_name }}
440+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
462441
```
463442

464443
Please refer to the [Cypress Cloud Git information environment variables](https://on.cypress.io/guides/continuous-integration/introduction#Git-information) section in our documentation for more examples.
@@ -491,7 +470,7 @@ jobs:
491470
- run: echo "PR number is $CYPRESS_PULL_REQUEST_ID"
492471
- run: echo "PR URL is $CYPRESS_PULL_REQUEST_URL"
493472
env:
494-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
473+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
495474
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
496475
```
497476

@@ -532,6 +511,7 @@ jobs:
532511
COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
533512
# re-enable PR comment bot
534513
COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}}
514+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
535515
```
536516

537517
See [issue 124](https://github.com/cypress-io/github-action/issues/124#issuecomment-1076826988) for details.
@@ -567,7 +547,7 @@ jobs:
567547
record: true
568548
tag: node-${{ matrix.node }}
569549
env:
570-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
550+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
571551
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
572552
```
573553

@@ -601,7 +581,7 @@ jobs:
601581
# Cancel the run after 2 failed tests
602582
auto-cancel-after-failures: 2
603583
env:
604-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
584+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
605585
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
606586
```
607587

@@ -742,7 +722,7 @@ jobs:
742722
group: 'Actions example'
743723
env:
744724
# pass the Cypress Cloud record key as an environment variable
745-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
725+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
746726
# Recommended: pass the GitHub token lets this action correctly
747727
# determine the unique run id necessary to re-run the checks
748728
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -1025,7 +1005,7 @@ jobs:
10251005
ci-build-id: '${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}'
10261006
env:
10271007
# pass the Cypress Cloud record key as an environment variable
1028-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
1008+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
10291009
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10301010
```
10311011

@@ -1340,7 +1320,7 @@ jobs:
13401320
group: Tests on Node v${{ matrix.node }}
13411321
cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('yarn.lock') }}
13421322
env:
1343-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
1323+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
13441324
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13451325
```
13461326

@@ -1578,7 +1558,7 @@ This is an example of using the step output `resultsUrl`:
15781558
with:
15791559
record: true
15801560
env:
1581-
CYPRESS_RECORD_KEY: ${{ secrets.RECORDING_KEY }}
1561+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
15821562
- name: Print Cypress Cloud URL
15831563
if: always()
15841564
run: |

0 commit comments

Comments
 (0)