Skip to content

Commit

Permalink
feat: allow recording in fork with secrets
Browse files Browse the repository at this point in the history
By defining their own EXAMPLE_PROJECT_ID and EXAMPLE_RECORD_KEY as GitHub Actions secrets, users can successfully run the recording examples
  • Loading branch information
MikeMcC399 committed Jan 5, 2023
1 parent d2a9e4e commit 598c8c9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 29 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/example-custom-ci-build-id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# multiple testing jobs running in parallel
# based on the recipe written in
# https://medium.com/attest-r-and-d/adding-a-unique-github-build-identifier-7aa2e83cadca
# The use of set-output is however deprecated by GitHub since the above blog was written
# 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
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
#
Expand All @@ -19,6 +19,14 @@ on:
branches:
- 'master'
pull_request:

env:
# Set up the Cypress Cloud record key and project ID as environment variables
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}

jobs:
# single job that generates and outputs a common id
prepare:
Expand Down Expand Up @@ -59,9 +67,6 @@ jobs:
ci-build-id: ${{ needs.prepare.outputs.uuid }}
spec: 'cypress/integration/spec-a.js'
working-directory: examples/v9/recording
env:
# pass the Cypress Cloud record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}

# if smoke tests pass, run all tests, splitting them in parallel
# because we record with the same build id, smoke and these
Expand Down Expand Up @@ -92,6 +97,3 @@ jobs:
--ci-build-id ${{ needs.prepare.outputs.uuid }} \
--group "2 - all tests"
working-directory: examples/v9/recording
env:
# pass the Cypress Cloud record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
36 changes: 14 additions & 22 deletions .github/workflows/example-recording.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ on:
branches:
- 'master'
pull_request:
jobs:

env:
# Set up the Cypress Cloud record key and project ID as environment variables
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
# If the Actions secret EXAMPLE_PROJECT_ID is not defined then
# the projectId is taken from cypress.json (v9) or cypress.config.js (v10 and later).
CYPRESS_PROJECT_ID: ${{ secrets.EXAMPLE_PROJECT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v9 and lower ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

parallel:
parallel-v9:
runs-on: ubuntu-20.04
steps:
- name: Checkout
Expand All @@ -30,20 +38,16 @@ jobs:
parallel: true
group: Recording example
tag: action
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# see "outcome" and "conclusion" of a step doc
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
# "output" can be success, failure, cancelled, or skipped
- name: Print Dashboard URL
run: |
echo Cypress finished with: ${{ steps.cypress.outcome }}
echo See results at ${{ steps.cypress.outputs.dashboardUrl }}
group:
group-v9:
runs-on: ubuntu-20.04
steps:
- name: Checkout
Expand All @@ -58,12 +62,8 @@ jobs:
record: true
# no parallel flag, just the group name
group: Recording group
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cypress v10 and higher ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

parallel-v10:
runs-on: ubuntu-20.04
Expand All @@ -87,13 +87,9 @@ jobs:
parallel: true
group: Recording example v10
tag: action
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# see "outcome" and "conclusion" of a step doc
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
# https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
# "output" can be success, failure, cancelled, or skipped
- name: Print Dashboard URL
run: |
Expand All @@ -115,7 +111,3 @@ jobs:
record: true
# no parallel flag, just the group name
group: Recording group v10
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions examples/v10/recording/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# example: recording

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.

## Using your own Cypress Cloud project

In order to use the recording example with your own Cypress Cloud project, you need to replace the `projectId` and `record key` with yours.

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.

Create a new project if one does not exist.

Access "Project settings" and copy the contents of each of the following parameters for the project into Actions Secrets of your fork:

| Cypress Cloud name | Actions secrets name in fork |
| ------------------ | ---------------------------- |
| Project ID | EXAMPLE_PROJECT_ID |
| Record Keys | EXAMPLE_RECORD_KEY |

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

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.

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.
24 changes: 24 additions & 0 deletions examples/v9/recording/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# example: recording

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.

## Using your own Cypress Cloud project

In order to use the recording example with your own Cypress Cloud project, you need to replace the `projectId` and `record key` with yours.

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.

Create a new project if one does not exist.

Access "Project settings" and copy the contents of each of the following parameters for the project into Actions Secrets of your fork:

| Cypress Cloud name | Actions secrets name in fork |
| ------------------ | ---------------------------- |
| Project ID | EXAMPLE_PROJECT_ID |
| Record Keys | EXAMPLE_RECORD_KEY |

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

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.

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 comments on commit 598c8c9

Please sign in to comment.