cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests
https://on.cypress.io/guides/continuous-integration/github-actions
MIT License
1.35k stars 357 forks source link

How to end the rails started process to generate simplecov coverage report #508

Open wagnerpereira opened 2 years ago

wagnerpereira commented 2 years ago

I'm using Cypress to do system on our Rails application and simplecov to generate the coverage report, but simplecov only generate the reports when the rails server process is terminated with sucess exit(0).

https://github.com/cypress-io/github-action#start-server

...

- name: Cypress Run
  uses: cypress-io/github-action@v2
  env:
    CYPRESS_RAILS_PORT: 9999
    CYPRESS_BASE_URL: "http://localhost:9999/"
    COVERAGE: true
  with:
    start: bundle exec rails server -b 0.0.0.0 -p 9999
    wait-on: "http://localhost:9999"

...

Cypress suite test runs perfectly but in the end I didn't get the simplecov reports to be uploaded to codecov. I'm guessing this is because the "started" rails process was note terminated by the cypress github action.

e.g

^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2022-02-18 11:48:09 -0300 ===
- Goodbye!
Exiting
Coverage report generated to /Users/wagner/src/tia/coverage/coverage.xml. 1469 / 3460 LOC (42.46%) covered
Coverage report generated to /Users/wagner/src/tia/coverage. 1469 / 3460 LOC (42.46%) covered.

Any idea how to achieve this ? Get the simplecov report in the end of the cypress github action execution?

Thanks a lot in advance.

wagnerpereira commented 2 years ago

Any way to stop/kill the with: start process after tests ends?

- name: Cypress Run
  uses: cypress-io/github-action@v2
  env:
    CYPRESS_RAILS_PORT: 9999
    CYPRESS_BASE_URL: "http://localhost:9999/"
    COVERAGE: true
  with:
    start: bundle exec rails server -b 0.0.0.0 -p 9999
    wait-on: "http://localhost:9999"
wagnerpereira commented 2 years ago

Issue hacked with this "external" kill of the started process by cypress.io/github-actions. It should nice to have this inside the github action.

Check what I have to do to solve my issue.

      - name: Cypress Run
        uses: cypress-io/github-action@v3
        id: cypress
        env:
          DATABASE_URL: postgres://postgres:@localhost:5432/test
          REDIS_URL: redis://localhost:6379/0
          RAILS_ENV: test
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          CYPRESS_BASE_URL: "http://localhost:9999/"
          COVERAGE: true
        with:
          project: ./spec
          record: true
          start: bundle exec rails server -b 0.0.0.0 -p 9999
          wait-on: "http://localhost:9999"

      - name: Stop Rails to generate coverage report
        run: |
          kill -2 `cat tmp/pids/server.pid`

      - name: Rename coverage report
        run: |
          while [ ! -f coverage/coverage.xml ]
          do
            sleep 2
          done
          mv coverage/coverage.xml coverage/coverage-e2e-tests.xml

      - name: Upload PR Coverage Report
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./coverage/coverage-e2e-tests.xml
          flags: testes-integracao
          name: ${{ needs.setup.outputs.repo_name }}-${{ needs.setup.outputs.image_tag }}
          fail_ci_if_error: true
          verbose: true

It should be great if we have some thing like this. A way to customize and send the stop command.

      - name: Cypress Run
        uses: cypress-io/github-action@v3
        id: cypress
        env:
          DATABASE_URL: postgres://postgres:@localhost:5432/test
          REDIS_URL: redis://localhost:6379/0
          RAILS_ENV: test
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          CYPRESS_BASE_URL: "http://localhost:9999/"
          COVERAGE: true
        with:
          project: ./spec
          record: true
          start: bundle exec rails server -b 0.0.0.0 -p 9999
          stop-command:  kill -2 `cat tmp/pids/server.pid`
          wait-on: "http://localhost:9999"

Thank you very much.

JonTheStone commented 1 month ago

Thanks for this! Just ran into the same thing and trying your solution now. Bumping the custom stop-command request