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

Skip ahead to re-run only Cypress #1885

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ jobs:
echo $endpoint
echo "storybook-endpoint=$endpoint" >> "$GITHUB_OUTPUT"

- name: Generate unique ID for Cypress
id: uuid
run: echo "value=sha-$GITHUB_SHA-time-$(date +"%s")" >> "$GITHUB_OUTPUT"

end-deployment:
needs: [begin-deployment, deploy-app, finishing-prep]
if: always() && needs.begin-deployment.result == 'success'
Expand Down Expand Up @@ -491,7 +487,7 @@ jobs:
parallel: true
browser: chrome
group: 'Chrome'
ci-build-id: ${{ needs.finishing-prep.outputs.cypress-uuid }}
ci-build-id: ${{ github.run_id }}-${{ github.run_attempt }}
# Point to the cypress config file from root
config-file: services/cypress/cypress.config.ts
env:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ If you are going to need to modify the migration that prisma generates you can u

Whenever you run `./dev postgres` we start a new postgres docker container and run `prisma migrate reset --force` to clean it out and run all of our checked in migrations there. After that you should be ready to develop.

## Build & Deploy
## Build & Deploy in CI

See main build/deploy [here](https://github.com/Enterprise-CMCS/managed-care-review/actions/workflows/promote.yml?query=branch%3Amain)

Expand All @@ -184,7 +184,9 @@ This application is deployed into three different AWS accounts: Dev, Val, and Pr

In the Dev account, in addition to deploying the main branch, we deploy a full version of the app on every branch that is pushed that is not the main branch. We call these deployments "review apps" since they host all the changes for a PR in a full deployment. These review apps are differentiated by their Serverless "stack" name. This is set to the branch name and all infra ends up being prefixed with it to keep from there being any overlapping.

We have a script (`getChangedServices`) that runs in CI to check if a service needs to be re-deployed due to your most recent commit or if a service can be skipped in order to save CI deploy time. For example, if you're just making changes to `app-web`, it's likely that you won't need to re-deploy any infra services, such as postgres, after an initial branch deploy. However, if you do need your branch to be fully re-deployed, you can add the string `force-ci-run` to your commit message and the entire deploy workflow will be run.
#### CI stage skipping script

We have a script (`getChangedServices`) that runs in CI to check if a service needs to be re-deployed due to your most recent commit or if a service can be skipped in order to save CI deploy time. For example, if you're just making changes to `app-web`, it's likely that you won't need to re-deploy any infra services, such as postgres, after an initial branch deploy. However, if you do need your branch to be fully re-deployed, you can add the string `force-ci-run` to your commit message and the entire deploy workflow will be run. If you have a failing Cypress container and want to skip over deploying infra and the application, use the string `cypress re-run` in a commit message and the `getChangedServices` script will skip you to the Cypress run (unit tests will still run, but it still saves time).

You can see the deploys for review apps [here](https://github.com/Enterprise-CMCS/managed-care-review/actions/workflows/deploy.yml)

Expand Down
8 changes: 8 additions & 0 deletions scripts/get-changed-services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ async function main() {
// get the latest commit in the branch to see if we are forcing a run
const latestCommit = await getLatestCommitSHA()
const commitMessage = await getLatestCommitMessage(latestCommit)

// force a complete CI run
if (commitMessage.includes('ci-force-run')) {
core.setOutput('changed-services', deployAllServices)
return
}

// force just a cypress re-run
if (commitMessage.includes('cypress re-run')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about ci-force-run, where would be a good place to document these CI incantations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The force-ci-run is in the main Readme, but it looks like it's a little buried and hard to pick out. I just pushed up a change that documents the new cypress re-run and breaks those docs out into a section so it's easier to run across!

core.setOutput('changed-services', [])
return
}

// if we haven't had a run on this branch, we need to deploy everything
if (allWorkflowRuns.data.total_count === 0) {
core.setOutput('changed-services', deployAllServices)
Expand Down
Loading