Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record to Cypress Cloud in fork #694

Closed
wants to merge 1 commit into from

Conversation

MikeMcC399
Copy link
Collaborator

@MikeMcC399 MikeMcC399 commented Dec 30, 2022

This PR resolves the issue #693 "Workflows using Cypress Cloud fail in fork".

It follows the recommendation in the README: Record test results on Cypress Cloud documentation, Tip 4, to pass the project id using an environment variable.

The two examples are modified so that they accept and use a new GitHub Actions variable EXAMPLE_PROJECT_ID in addition to the existing EXAMPLE_RECORDING_KEY which is an Actions secret:

This is backward compatible to the current workflows.

In the parent repository cypress-io/github-action the Actions secret EXAMPLE_RECORDING_KEY is defined for the Project ID 3tb7jn. Runs are publicly viewable via the Cypress Cloud on https://cloud.cypress.io/projects/3tb7jn.

If fork users define EXAMPLE_PROJECT_ID as Actions variable and EXAMPLE_RECORDING_KEY as Actions secret in their forked repository then the workflows record into the user's own project. If this step is not taken, then the workflows will simply continue to report failures if they are triggered in a fork, exactly as happens before this PR was introduced.

README files have been added as:

  • examples/v9/recording/README.md
  • examples/recording/README.md

to explain how to obtain and add a user's own EXAMPLE_PROJECT_ID and EXAMPLE_RECORDING_KEY.

The README files are reviewable in

Verification

Backwards compatibility

Ensure that the workflows for the parent repository cypress-io/github-action continue to report success:

New functionality

Follow the instructions to create new EXAMPLE_PROJECT_ID Actions variable and EXAMPLE_RECORDING_KEY Actions secret and check that the results are published on Cypress Cloud.

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399 MikeMcC399 marked this pull request as draft December 30, 2022 08:19
@MikeMcC399 MikeMcC399 force-pushed the feat/record-in-fork branch 2 times, most recently from a414863 to 598c8c9 Compare January 5, 2023 17:18
@MikeMcC399 MikeMcC399 marked this pull request as ready for review January 5, 2023 17:26
@MikeMcC399 MikeMcC399 marked this pull request as draft January 10, 2023 21:18
@MikeMcC399 MikeMcC399 force-pushed the feat/record-in-fork branch 2 times, most recently from 63ae7ee to 08ab74a Compare January 12, 2023 11:52
@MikeMcC399 MikeMcC399 changed the title Allow recording to Cypress Cloud in fork with secrets Record to Cypress Cloud in fork Jan 12, 2023
@MikeMcC399
Copy link
Collaborator Author

MikeMcC399 commented Jan 12, 2023

Reworked to set EXAMPLE_PROJECT_ID as Actions variable instead of Actions secret.

example-custom-ci-build-id was previously running only on v9. I have changed it to run only on v10. Is that acceptable or does the v9 example need to be retained?

This is still in draft state whilst I check through the logs.

@MikeMcC399

This comment was marked as outdated.

By defining their own EXAMPLE_PROJECT_ID and EXAMPLE_RECORD_KEY as GitHub environment variables, users can successfully run the recording examples
@MikeMcC399
Copy link
Collaborator Author

@jaffrepaul

I have successfully tested this for the two scenarios:

  1. As in https://github.com/cypress-io/github-action with no change to any project id or secrets
  2. In a fork with project id and recording key specified via environment variables

so it is now ready for review.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review January 20, 2023 16:26
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeMcC399 I think I would prefer the route of skipping recording on external contributors for this. We employ this strategy on the main cypress repo, since we have the same issue there with external contributors. I don't see it being convenient for external contributors to setup their own example project in this case just to submit a fix. https://github.com/cypress-io/cypress/blob/develop/.circleci/workflows.yml#L484:L484

@MikeMcC399 MikeMcC399 marked this pull request as draft January 26, 2023 08:46
@MikeMcC399
Copy link
Collaborator Author

@jennifer-shehane Thank you for your feedback!

My suggestion was more oriented to users who wanted to use the examples to practice the use of the action rather than just to fix submitters.

I would however not want to force anyone, including fix submitters, to have to set up a Cypress Cloud project.

An easy way out would be to suppress the action from running in a fork, however that would be at the disadvantage of any user who genuinely wanted to get deeper into using the recording examples with low effort, so I don't want to take this route.

A better solution is to add a condition to this proposed PR that recording is only attempted if secrets.EXAMPLE_RECORDING_KEY is defined (not null). A default fork would not have this secret defined, so this would cover default external contributors.

I will take a look at how to implement this best. In the meantime I have set the PR into Draft status.

@MikeMcC399
Copy link
Collaborator Author

  • This PR is superseded by feat: allow recording in fork with secrets #751 which adds the functionality of skipping tests if the Actions secret secrets.EXAMPLE_RECORDING_KEY is not defined. Since this was a non-trivial enhancement I elected to put the enhancement into a new PR and leave this one untouched for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants