Skip to content

Commit 63ae7ee

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 example-custom-ci-build-id is moved from using v9 to v10
1 parent 51594fd commit 63ae7ee

File tree

4 files changed

+100
-31
lines changed

4 files changed

+100
-31
lines changed

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

+24-9
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,21 @@
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 (v9) or cypress.config.js (v10 and later).
39+
CYPRESS_PROJECT_ID: ${{ vars.EXAMPLE_PROJECT_ID }}
40+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
2243
jobs:
2344
# single job that generates and outputs a common id
2445
prepare:
@@ -58,10 +79,7 @@ jobs:
5879
group: '1 - smoke tests'
5980
ci-build-id: ${{ needs.prepare.outputs.uuid }}
6081
spec: 'cypress/integration/spec-a.js'
61-
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 }}
82+
working-directory: examples/v10/recording
6583

6684
# if smoke tests pass, run all tests, splitting them in parallel
6785
# because we record with the same build id, smoke and these
@@ -91,7 +109,4 @@ jobs:
91109
npx cypress run --record --parallel \
92110
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
93111
--group "2 - all tests"
94-
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 }}
112+
working-directory: examples/v10/recording

.github/workflows/example-recording.yml

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
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+
#
11+
212
on:
313
push:
414
branches:
515
- 'master'
616
pull_request:
7-
jobs:
817

18+
env:
19+
# Set up the Cypress Cloud project ID and record key as environment variables
20+
# If the Actions variable EXAMPLE_PROJECT_ID is not defined then
21+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
22+
CYPRESS_PROJECT_ID: ${{ vars.EXAMPLE_PROJECT_ID }}
23+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
26+
jobs:
927
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v9 and lower ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
1028

11-
parallel:
29+
parallel-v9:
1230
runs-on: ubuntu-22.04
1331
steps:
1432
- name: Checkout
@@ -30,20 +48,16 @@ jobs:
3048
parallel: true
3149
group: Recording example
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
39-
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
53+
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
4054
# "output" can be success, failure, cancelled, or skipped
4155
- name: Print Dashboard URL
4256
run: |
4357
echo Cypress finished with: ${{ steps.cypress.outcome }}
4458
echo See results at ${{ steps.cypress.outputs.dashboardUrl }}
4559
46-
group:
60+
group-v9:
4761
runs-on: ubuntu-22.04
4862
steps:
4963
- name: Checkout
@@ -58,12 +72,8 @@ jobs:
5872
record: true
5973
# no parallel flag, just the group name
6074
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 }}
6575

66-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
76+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
6777

6878
parallel-v10:
6979
runs-on: ubuntu-22.04
@@ -87,13 +97,9 @@ jobs:
8797
parallel: true
8898
group: Recording example v10
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
96-
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
102+
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
97103
# "output" can be success, failure, cancelled, or skipped
98104
- name: Print Dashboard URL
99105
run: |
@@ -115,7 +121,3 @@ jobs:
115121
record: true
116122
# no parallel flag, just the group name
117123
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

+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)