Skip to content

Commit 07c13ea

Browse files
committed
feat: allow recording in fork with secrets
1 parent 821aeac commit 07c13ea

File tree

4 files changed

+124
-27
lines changed

4 files changed

+124
-27
lines changed

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

+38-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
name: example-custom-ci-build-id
2+
#
3+
# To set up this workflow to work with your own Cypress Cloud project
4+
# refer to the README in the example directory examples/recording.
5+
#
6+
# ---
7+
#
18
# Typically you would let this action
29
# determine a unique build id to tie multiple parallel
310
# test jobs together into a single logical Cypress Cloud run.
@@ -9,20 +16,46 @@
916
# multiple testing jobs running in parallel
1017
# based on the recipe written in
1118
# 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
13-
# in 2019 so this is replaced by GitHub Environment files, see
19+
# The use of set-output is however deprecated by GitHub since the above blog # was written in 2019 so this is replaced by GitHub Environment files, see
1420
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
1521
#
16-
name: example-custom-ci-build-id
22+
1723
on:
1824
push:
1925
branches:
2026
- 'master'
2127
pull_request:
28+
29+
env:
30+
# Set up the Cypress Cloud project ID and record key as environment variables
31+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
32+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
33+
# If the Actions secret EXAMPLE_RECORDING_KEY is not defined then recording jobs are skipped.
34+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
35+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
2238
jobs:
39+
40+
check-record-key:
41+
runs-on: ubuntu-22.04
42+
outputs:
43+
record-key-exists: ${{ steps.record-key-check.outputs.defined }}
44+
steps:
45+
- name: Check for record key
46+
id: record-key-check
47+
run: |
48+
if [ "${{ secrets.EXAMPLE_RECORDING_KEY }}" != '' ]; then
49+
echo "defined=true" >> $GITHUB_OUTPUT;
50+
else
51+
echo "defined=false" >> $GITHUB_OUTPUT;
52+
fi
53+
2354
# single job that generates and outputs a common id
2455
prepare:
56+
needs: [check-record-key]
2557
runs-on: ubuntu-22.04
58+
if: needs.check-record-key.outputs.record-key-exists == 'true'
2659
outputs:
2760
uuid: ${{ steps.uuid.outputs.value }}
2861
steps:
@@ -39,7 +72,7 @@ jobs:
3972
# let's run a small subset of the tests
4073
# and record it to the Cypress Cloud
4174
smoke-tests:
42-
needs: ['prepare']
75+
needs: [prepare]
4376
runs-on: ubuntu-22.04
4477
steps:
4578
- name: Checkout 🛎
@@ -59,16 +92,13 @@ jobs:
5992
ci-build-id: ${{ needs.prepare.outputs.uuid }}
6093
spec: 'cypress/e2e/spec-a.cy.js'
6194
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 }}
6595

6696
# if smoke tests pass, run all tests, splitting them in parallel
6797
# because we record with the same build id, smoke and these
6898
# tests should be under the same logical recorded run
6999
# under different groups
70100
all-tests:
71-
needs: ['prepare', 'smoke-tests']
101+
needs: [prepare, smoke-tests]
72102
runs-on: ubuntu-22.04
73103
strategy:
74104
fail-fast: false
@@ -92,6 +122,3 @@ jobs:
92122
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
93123
--group "2 - all tests"
94124
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

+36-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
name: example-recording
2+
#
3+
# To set up this workflow to work with your own Cypress Cloud project
4+
# refer to the README in the example directory examples/recording.
5+
#
26
on:
37
push:
48
branches:
59
- 'master'
610
pull_request:
11+
12+
env:
13+
# Set up the Cypress Cloud project ID and record key as environment variables
14+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
15+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
16+
# If the Actions secret EXAMPLE_RECORDING_KEY is not defined then recording jobs are skipped.
17+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
18+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
721
jobs:
822

23+
check-record-key:
24+
runs-on: ubuntu-22.04
25+
outputs:
26+
record-key-exists: ${{ steps.record-key-check.outputs.defined }}
27+
steps:
28+
- name: Check for record key
29+
id: record-key-check
30+
run: |
31+
if [ "${{ secrets.EXAMPLE_RECORDING_KEY }}" != '' ]; then
32+
echo "defined=true" >> $GITHUB_OUTPUT;
33+
else
34+
echo "defined=false" >> $GITHUB_OUTPUT;
35+
fi
36+
937
# ~~~~~~~~~~~~~~~~~~ Cypress v9 and below (using Legacy configuration) ~~~~~~~~~~~~~~~~~~~ #
1038

1139
parallel-v9:
1240
runs-on: ubuntu-22.04
41+
needs: [check-record-key]
42+
if: needs.check-record-key.outputs.record-key-exists == 'true'
1343
steps:
1444
- name: Checkout
1545
uses: actions/checkout@v3
@@ -30,10 +60,6 @@ jobs:
3060
parallel: true
3161
group: Recording example v9
3262
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 }}
3763

3864
# see "outcome" and "conclusion" of a step doc
3965
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -45,6 +71,8 @@ jobs:
4571
4672
group-v9:
4773
runs-on: ubuntu-22.04
74+
needs: [check-record-key]
75+
if: needs.check-record-key.outputs.record-key-exists == 'true'
4876
steps:
4977
- name: Checkout
5078
uses: actions/checkout@v3
@@ -58,15 +86,13 @@ jobs:
5886
record: true
5987
# no parallel flag, just the group name
6088
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 }}
6589

6690
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
6791

6892
parallel:
6993
runs-on: ubuntu-22.04
94+
needs: [check-record-key]
95+
if: needs.check-record-key.outputs.record-key-exists == 'true'
7096
steps:
7197
- name: Checkout
7298
uses: actions/checkout@v3
@@ -87,10 +113,6 @@ jobs:
87113
parallel: true
88114
group: Recording example
89115
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 }}
94116

95117
# see "outcome" and "conclusion" of a step doc
96118
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -102,6 +124,8 @@ jobs:
102124
103125
group:
104126
runs-on: ubuntu-22.04
127+
needs: [check-record-key]
128+
if: needs.check-record-key.outputs.record-key-exists == 'true'
105129
steps:
106130
- name: Checkout
107131
uses: actions/checkout@v3
@@ -115,7 +139,3 @@ jobs:
115139
record: true
116140
# no parallel flag, just the group name
117141
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 }}

examples/recording/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 "Secrets" for the "Project ID" and 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 secrets |
18+
| Record Keys | EXAMPLE_RECORDING_KEY | Actions secrets |
19+
20+
Refer to the GitHub documentation
21+
- [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
22+
23+
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.
24+
25+
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_RECORDING_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

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 "Secrets" for the "Project ID" and 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 secrets |
18+
| Record Keys | EXAMPLE_RECORDING_KEY | Actions secrets |
19+
20+
Refer to the GitHub documentation
21+
- [Creating encrypted secrets for a repository](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
22+
-
23+
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.
24+
25+
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_RECORDING_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)