Skip to content

Commit a414863

Browse files
committed
feat: allow recording in fork with secrets
By defining their own EXAMPLE_PROJECT_ID and EXAMPLE_RECORD_KEY as GitHub Actions secrets, users can successfully run the recording examples
1 parent 32831a3 commit a414863

File tree

4 files changed

+71
-29
lines changed

4 files changed

+71
-29
lines changed

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# multiple testing jobs running in parallel
1010
# based on the recipe written in
1111
# https://medium.com/attest-r-and-d/adding-a-unique-github-build-identifier-7aa2e83cadca
12-
# The use of set-output is however deprecated by GitHub since the above blog was written
12+
# The use of set-output is however deprecated by GitHub since the above blog was written
1313
# in 2019 so this is replaced by GitHub Environment files, see
1414
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
1515
#
@@ -19,6 +19,14 @@ on:
1919
branches:
2020
- 'master'
2121
pull_request:
22+
23+
env:
24+
# Set up the Cypress Cloud record key and project ID as environment variables
25+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
26+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
27+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
28+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
29+
2230
jobs:
2331
# single job that generates and outputs a common id
2432
prepare:
@@ -59,9 +67,6 @@ jobs:
5967
ci-build-id: ${{ needs.prepare.outputs.uuid }}
6068
spec: 'cypress/integration/spec-a.js'
6169
working-directory: examples/v9/recording
62-
env:
63-
# pass the Cypress Cloud record key as an environment variable
64-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
6570

6671
# if smoke tests pass, run all tests, splitting them in parallel
6772
# because we record with the same build id, smoke and these
@@ -92,6 +97,3 @@ jobs:
9297
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
9398
--group "2 - all tests"
9499
working-directory: examples/v9/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

+14-22
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ on:
44
branches:
55
- 'master'
66
pull_request:
7-
jobs:
87

8+
env:
9+
# Set up the Cypress Cloud record key and project ID as environment variables
10+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
11+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
12+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
13+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
16+
jobs:
917
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v9 and lower ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
1018

11-
parallel:
19+
parallel-v9:
1220
runs-on: ubuntu-20.04
1321
steps:
1422
- name: Checkout
@@ -30,20 +38,16 @@ jobs:
3038
parallel: true
3139
group: Recording example
3240
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 }}
3741

3842
# see "outcome" and "conclusion" of a step doc
39-
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
43+
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
4044
# "output" can be success, failure, cancelled, or skipped
4145
- name: Print Dashboard URL
4246
run: |
4347
echo Cypress finished with: ${{ steps.cypress.outcome }}
4448
echo See results at ${{ steps.cypress.outputs.dashboardUrl }}
4549
46-
group:
50+
group-v9:
4751
runs-on: ubuntu-20.04
4852
steps:
4953
- name: Checkout
@@ -58,12 +62,8 @@ jobs:
5862
record: true
5963
# no parallel flag, just the group name
6064
group: Recording group
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 }}
6565

66-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
66+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
6767

6868
parallel-v10:
6969
runs-on: ubuntu-20.04
@@ -87,13 +87,9 @@ jobs:
8787
parallel: true
8888
group: Recording example v10
8989
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 }}
9490

9591
# see "outcome" and "conclusion" of a step doc
96-
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
92+
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
9793
# "output" can be success, failure, cancelled, or skipped
9894
- name: Print Dashboard URL
9995
run: |
@@ -115,7 +111,3 @@ jobs:
115111
record: true
116112
# no parallel flag, just the group name
117113
group: Recording group v10
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 }}

examples/v10/recording/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 yours.
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" and copy the contents of each of the following parameters for the project into Actions Secrets of your fork:
14+
15+
| Cypress Cloud name | Actions secrets name in fork |
16+
| ------------------ | ---------------------------- |
17+
| Project ID | EXAMPLE_PROJECT_ID |
18+
| Record Keys | EXAMPLE_RECORD_KEY |
19+
20+
Refer to the GitHub documentation [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
21+
22+
When you have done this, the example recording will take the `projectId` from the `EXAMPLE_PROJECT_ID` secret instead of from the [cypress.config.js](cypress.config.js) configuration file.
23+
24+
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_PROJECT_ID` 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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 yours.
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" and copy the contents of each of the following parameters for the project into Actions Secrets of your fork:
14+
15+
| Cypress Cloud name | Actions secrets name in fork |
16+
| ------------------ | ---------------------------- |
17+
| Project ID | EXAMPLE_PROJECT_ID |
18+
| Record Keys | EXAMPLE_RECORD_KEY |
19+
20+
Refer to the GitHub documentation [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
21+
22+
When you have done this, the example recording will take the `projectId` from the `EXAMPLE_PROJECT_ID` secret instead of from the [cypress.json](cypress.json) configuration file.
23+
24+
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_PROJECT_ID` defined as a secret and it uses the `projectId` as defined in the [cypress.json](cypress.json) configuration file.

0 commit comments

Comments
 (0)