github-action icon indicating copy to clipboard operation
github-action copied to clipboard

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

Open wagnerpereira opened this issue 4 years ago • 4 comments

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 avatar Feb 18 '22 15:02 wagnerpereira

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 avatar Mar 04 '22 12:03 wagnerpereira

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.

wagnerpereira avatar Mar 10 '22 15:03 wagnerpereira