Skip to content

Commit 45aa1c2

Browse files
committed
feat: allow recording in fork with secrets
1 parent 3ef1333 commit 45aa1c2

File tree

4 files changed

+122
-27
lines changed

4 files changed

+122
-27
lines changed

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

+37-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,22 +16,47 @@
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:
2228
workflow_dispatch:
2329

30+
env:
31+
# Set up the Cypress Cloud project ID and record key as environment variables
32+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
33+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
34+
# If the Actions secret EXAMPLE_RECORDING_KEY is not defined then recording jobs are skipped.
35+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
36+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
2439
jobs:
40+
41+
check-record-key:
42+
runs-on: ubuntu-22.04
43+
outputs:
44+
record-key-exists: ${{ steps.record-key-check.outputs.defined }}
45+
steps:
46+
- name: Check for record key
47+
id: record-key-check
48+
run: |
49+
if [ "${{ secrets.EXAMPLE_RECORDING_KEY }}" != '' ]; then
50+
echo "defined=true" >> $GITHUB_OUTPUT;
51+
else
52+
echo "defined=false" >> $GITHUB_OUTPUT;
53+
fi
54+
2555
# single job that generates and outputs a common id
2656
prepare:
57+
needs: [check-record-key]
2758
runs-on: ubuntu-22.04
59+
if: needs.check-record-key.outputs.record-key-exists == 'true'
2860
outputs:
2961
uuid: ${{ steps.uuid.outputs.value }}
3062
steps:
@@ -41,7 +73,7 @@ jobs:
4173
# let's run a small subset of the tests
4274
# and record it to the Cypress Cloud
4375
smoke-tests:
44-
needs: ['prepare']
76+
needs: [prepare]
4577
runs-on: ubuntu-22.04
4678
steps:
4779
- name: Checkout 🛎
@@ -61,16 +93,13 @@ jobs:
6193
ci-build-id: ${{ needs.prepare.outputs.uuid }}
6294
spec: 'cypress/e2e/spec-a.cy.js'
6395
working-directory: examples/recording
64-
env:
65-
# pass the Cypress Cloud record key as an environment variable
66-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
6796

6897
# if smoke tests pass, run all tests, splitting them in parallel
6998
# because we record with the same build id, smoke and these
7099
# tests should be under the same logical recorded run
71100
# under different groups
72101
all-tests:
73-
needs: ['prepare', 'smoke-tests']
102+
needs: [prepare, smoke-tests]
74103
runs-on: ubuntu-22.04
75104
strategy:
76105
fail-fast: false
@@ -94,6 +123,3 @@ jobs:
94123
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
95124
--group "2 - all tests"
96125
working-directory: examples/recording
97-
env:
98-
# pass the Cypress Cloud record key as an environment variable
99-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}

.github/workflows/example-recording.yml

+35-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
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:
711
workflow_dispatch:
812

13+
env:
14+
# Set up the Cypress Cloud project ID and record key as environment variables
15+
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
16+
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
17+
# If the Actions secret EXAMPLE_RECORDING_KEY is not defined then recording jobs are skipped.
18+
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
19+
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
922
jobs:
1023

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

1340
parallel-v9:
1441
runs-on: ubuntu-22.04
42+
needs: [check-record-key]
43+
if: needs.check-record-key.outputs.record-key-exists == 'true'
1544
steps:
1645
- name: Checkout
1746
uses: actions/checkout@v3
@@ -32,10 +61,6 @@ jobs:
3261
parallel: true
3362
group: Recording example v9
3463
tag: action
35-
env:
36-
# pass the Dashboard record key as an environment variable
37-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3964

4065
# see "outcome" and "conclusion" of a step doc
4166
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -47,6 +72,8 @@ jobs:
4772
4873
group-v9:
4974
runs-on: ubuntu-22.04
75+
needs: [check-record-key]
76+
if: needs.check-record-key.outputs.record-key-exists == 'true'
5077
steps:
5178
- name: Checkout
5279
uses: actions/checkout@v3
@@ -60,15 +87,13 @@ jobs:
6087
record: true
6188
# no parallel flag, just the group name
6289
group: Recording group v9
63-
env:
64-
# pass the Dashboard record key as an environment variable
65-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
66-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6790

6891
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
6992

7093
parallel:
7194
runs-on: ubuntu-22.04
95+
needs: [check-record-key]
96+
if: needs.check-record-key.outputs.record-key-exists == 'true'
7297
steps:
7398
- name: Checkout
7499
uses: actions/checkout@v3
@@ -89,10 +114,6 @@ jobs:
89114
parallel: true
90115
group: Recording example
91116
tag: action
92-
env:
93-
# pass the Dashboard record key as an environment variable
94-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96117

97118
# see "outcome" and "conclusion" of a step doc
98119
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
@@ -104,6 +125,8 @@ jobs:
104125
105126
group:
106127
runs-on: ubuntu-22.04
128+
needs: [check-record-key]
129+
if: needs.check-record-key.outputs.record-key-exists == 'true'
107130
steps:
108131
- name: Checkout
109132
uses: actions/checkout@v3
@@ -117,7 +140,3 @@ jobs:
117140
record: true
118141
# no parallel flag, just the group name
119142
group: Recording group
120-
env:
121-
# pass the Dashboard record key as an environment variable
122-
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
123-
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)