Skip to content

Commit 90bfd22

Browse files
committed
feat: allow recording in fork with secrets
By defining their own EXAMPLE_PROJECT_ID and EXAMPLE_RECORD_KEY as GitHub environment variables, users can successfully run the recording examples
1 parent d1d2ac8 commit 90bfd22

File tree

5 files changed

+96
-26
lines changed

5 files changed

+96
-26
lines changed

.github/workflows/example-custom-ci-build-id.yml

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
name: example-custom-ci-build-id
2+
#
3+
# If this workflow is failing and you do not want to use it
4+
# then you can disable it individually.
5+
# See GitHub help: Disabling and enabling a workflow
6+
# https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow).
7+
#
8+
# To set it up to work with your own Cypress Cloud refer to the README
9+
# in the example directory examples/v10/recording.
10+
#
11+
# ---
12+
#
113
# Typically you would let this action
214
# determine a unique build id to tie multiple parallel
315
# test jobs together into a single logical Cypress Cloud run.
@@ -13,12 +25,22 @@
1325
# in 2019 so this is replaced by GitHub Environment files, see
1426
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
1527
#
16-
name: example-custom-ci-build-id
28+
1729
on:
1830
push:
1931
branches:
2032
- 'master'
2133
pull_request:
34+
35+
env:
36+
# Set up the Cypress Cloud project ID and record key as environment variables
37+
# If the Actions variable EXAMPLE_PROJECT_ID is not defined then
38+
# the projectId is taken from cypress.json (Legacy configuration)
39+
# or cypress.config.js (v10 and later).
40+
CYPRESS_PROJECT_ID: ${{ vars.EXAMPLE_PROJECT_ID }}
41+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
2244
jobs:
2345
# single job that generates and outputs a common id
2446
prepare:
@@ -59,9 +81,6 @@ jobs:
5981
ci-build-id: ${{ needs.prepare.outputs.uuid }}
6082
spec: 'cypress/e2e/spec-a.cy.js'
6183
working-directory: examples/recording
62-
env:
63-
# pass the Cypress Cloud record key as an environment variable
64-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
6584

6685
# if smoke tests pass, run all tests, splitting them in parallel
6786
# because we record with the same build id, smoke and these
@@ -92,6 +111,3 @@ jobs:
92111
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
93112
--group "2 - all tests"
94113
working-directory: examples/recording
95-
env:
96-
# pass the Cypress Cloud record key as an environment variable
97-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}

.github/workflows/example-recording.yml

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
name: example-recording
2+
#
3+
# If this workflow is failing and you do not want to use it
4+
# then you can disable it individually.
5+
# See GitHub help: Disabling and enabling a workflow
6+
# https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow).
7+
#
8+
# To set it up to work with your own Cypress Cloud refer to the README
9+
# in the corresponding example directory examples/*/recording.
10+
#
211
on:
312
push:
413
branches:
514
- 'master'
615
pull_request:
16+
17+
env:
18+
# Set up the Cypress Cloud project ID and record key as environment variables
19+
# If the Actions variable EXAMPLE_PROJECT_ID is not defined then
20+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
21+
CYPRESS_PROJECT_ID: ${{ vars.EXAMPLE_PROJECT_ID }}
22+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
725
jobs:
826

927
# ~~~~~~~~~~~~~~~~~~ Cypress v9 and below (using Legacy configuration) ~~~~~~~~~~~~~~~~~~~ #
@@ -30,10 +48,6 @@ jobs:
3048
parallel: true
3149
group: Recording example v9
3250
tag: action
33-
env:
34-
# pass the Dashboard record key as an environment variable
35-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3751

3852
# see "outcome" and "conclusion" of a step doc
3953
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -58,10 +72,6 @@ jobs:
5872
record: true
5973
# no parallel flag, just the group name
6074
group: Recording group v9
61-
env:
62-
# pass the Dashboard record key as an environment variable
63-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6575

6676
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
6777

@@ -87,10 +97,6 @@ jobs:
8797
parallel: true
8898
group: Recording example
8999
tag: action
90-
env:
91-
# pass the Dashboard record key as an environment variable
92-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
93-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94100

95101
# see "outcome" and "conclusion" of a step doc
96102
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -115,7 +121,3 @@ jobs:
115121
record: true
116122
# no parallel flag, just the group name
117123
group: Recording group
118-
env:
119-
# pass the Dashboard record key as an environment variable
120-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
121-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ jobs:
331331
with:
332332
record: true
333333
env:
334-
# pass the Cypress Cloud record key as an environment variable
334+
# pass the Cypress Cloud record key as an environment variable (Actions secret)
335335
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
336336
# pass GitHub token to allow accurately detecting a build vs a re-run build
337337
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
338-
# pass the project ID from the secrets through environment variable
339-
CYPRESS_PROJECT_ID: ${{ secrets.PROJECT_ID }}
338+
# pass the project ID as an environment variable (Actions variable)
339+
CYPRESS_PROJECT_ID: ${{ vars.PROJECT_ID }}
340340
```
341341

342342
### Quiet flag

examples/recording/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# example: recording
2+
3+
The recording example uses [Cypress Cloud](https://docs.cypress.io/guides/cloud/introduction) to record results using the Cypress Cloud `projectId` as defined in the [cypress.config.js](cypress.config.js) configuration file.
4+
5+
## Using your own Cypress Cloud project
6+
7+
In order to use the recording example with your own Cypress Cloud project, you need to replace the `projectId` and `record key` with your own values.
8+
9+
Follow the [Cypress Cloud](https://docs.cypress.io/guides/cloud/introduction) documentation to sign up, if you do not already have an account, or to [sign in](https://cloud.cypress.io/) if you have an account.
10+
11+
Create a new project if one does not exist.
12+
13+
Access "Project settings" in Cypress Cloud and copy the contents of each of the following parameters for the project into the Security settings of your GitHub fork, using "Secrets and variables" > "Actions", then "Variables" for the "Project ID" and "Secrets" for the "Record Key" as in the table below:
14+
15+
| Cypress Cloud name | Actions name in fork | Variable type |
16+
| ------------------ | -------------------- | ----------------- |
17+
| Project ID | EXAMPLE_PROJECT_ID | Actions variables |
18+
| Record Keys | EXAMPLE_RECORD_KEY | Actions secrets |
19+
20+
Refer to the GitHub documentation
21+
- [Defining configuration variables for multiple workflows](https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows)
22+
- [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
23+
24+
When you have done this, the example recording will take the `projectId` from the `EXAMPLE_PROJECT_ID` variable instead of from the [cypress.config.js](cypress.config.js) configuration file.
25+
26+
This setup allows the example recording to run in your own Cypress Cloud project, whilst leaving the same example for use in the parent repository [cypress-io/github-action](https://github.com/cypress-io/github-action) unchanged. The parent repository has its own `EXAMPLE_RECORD_KEY` defined as a secret and it uses the `projectId` as defined in the [cypress.config.js](cypress.config.js) configuration file.

examples/v9/recording/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# example: recording
2+
3+
The recording example uses [Cypress Cloud](https://docs.cypress.io/guides/cloud/introduction) to record results using the Cypress Cloud `projectId` as defined in the [cypress.json](cypress.json) configuration file.
4+
5+
## Using your own Cypress Cloud project
6+
7+
In order to use the recording example with your own Cypress Cloud project, you need to replace the `projectId` and `record key` with your own values.
8+
9+
Follow the [Cypress Cloud](https://docs.cypress.io/guides/cloud/introduction) documentation to sign up, if you do not already have an account, or to [sign in](https://cloud.cypress.io/) if you have an account.
10+
11+
Create a new project if one does not exist.
12+
13+
Access "Project settings" in Cypress Cloud and copy the contents of each of the following parameters for the project into the Security settings of your GitHub fork, using "Secrets and variables" > "Actions", then "Variables" for the "Project ID" and "Secrets" for the "Record Key" as in the table below:
14+
15+
| Cypress Cloud name | Actions name in fork | Variable type |
16+
| ------------------ | -------------------- | ----------------- |
17+
| Project ID | EXAMPLE_PROJECT_ID | Actions variables |
18+
| Record Keys | EXAMPLE_RECORD_KEY | Actions secrets |
19+
20+
Refer to the GitHub documentation
21+
- [Defining configuration variables for multiple workflows](https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows)
22+
- [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
23+
24+
When you have done this, the example recording will take the `projectId` from the `EXAMPLE_PROJECT_ID` variable instead of from the [cypress.json](cypress.json) configuration file.
25+
26+
This setup allows the example recording to run in your own Cypress Cloud project, whilst leaving the same example for use in the parent repository [cypress-io/github-action](https://github.com/cypress-io/github-action) unchanged. The parent repository has its own `EXAMPLE_RECORD_KEY` defined as a secret and it uses the `projectId` as defined in the [cypress.json](cypress.json) configuration file.

0 commit comments

Comments
 (0)