From afe26499f5498717f25d01dc49d67a68be1daa53 Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Mon, 29 Apr 2024 16:55:41 -0400 Subject: [PATCH] fixup! --- .github/workflows/ci.yml | 37 +++++++++++++ .github/workflows/combine_and_report.yml | 34 ++++++++++++ .github/workflows/rspec.yml | 68 +++++++++++++----------- .rspec_parallel | 3 +- Gemfile | 1 + Gemfile.lock | 3 ++ 6 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/combine_and_report.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..9f41432abe --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: Continuous Integration + +on: + push: + branches: + - main + paths-ignore: + - "doc/**" + - "**/*.md" + pull_request: + branches: + - main + +jobs: + rspec: + # this is the job for the unit tests (non-integration tests) + strategy: + fail-fast: false + matrix: + groups: + [ + "[0, 1, 2, 3]", + "[4, 5, 6, 7]", + "[8, 9, 10, 11]", + ] + uses: ./.github/workflows/rspec.yml + secrets: inherit + with: + groups: ${{ matrix.groups }} + group_count: 12 # the total number of test groups, must match the groups listed in the matrix.groups + parallel_processes_count: 4 # the number of parallel processes to run tests in worker, must match the size of the + # inner arrays in the matrix.groups + combine_and_report: + # this is the job that combines the results of the previous two jobs and reports them + uses: ./.github/workflows/combine_and_report.yml + needs: [rspec] + secrets: inherit diff --git a/.github/workflows/combine_and_report.yml b/.github/workflows/combine_and_report.yml new file mode 100644 index 0000000000..e9ce344f68 --- /dev/null +++ b/.github/workflows/combine_and_report.yml @@ -0,0 +1,34 @@ +on: + workflow_call: +jobs: + combine_and_report: + runs-on: ubuntu-latest + steps: + - name: Checkout Project + uses: actions/checkout@v4 + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + - name: Decompress chunk test reports + run: | + find artifacts -name "test_reports*.zip" -exec unzip -d test_reports {} \; + find test_reports -name "**/test_reports*.zip" -exec unzip -d test_reports {} \; + - name: Merge parallel runtime log parts + run: | + cat artifacts/**/parallel_runtime_rspec*.log > parallel_runtime.log + - name: Test Summary + id: test_summary + uses: test-summary/action@v2 + with: + paths: | + test_reports/**/rspec*.xml + if: always() + - name: Set job status + # In this step we set the status of the job. Normally in case of failures, the next steps fail, so we have to + # use `if: always()` to make sure the next steps run. + if: ${{ steps.test_summary.outputs.failed > 0 }} + uses: actions/github-script@v6 + with: + script: | + core.setFailed('There are test failures') diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 2c183ffff7..84b6182fd9 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -1,27 +1,30 @@ name: rspec on: - push: - branches: - - main - paths-ignore: - - "doc/**" - - "**/*.md" - pull_request: - branches: - - main + workflow_call: + inputs: + groups: + required: true + type: string + group_count: + required: true + type: number + parallel_processes_count: + required: true + type: number +env: + GROUPS_COMMA: ${{ join(fromJSON(inputs.groups), ',') }} + GROUPS_UNDERSCORE: ${{ join(fromJSON(inputs.groups), '_') }} jobs: rspec: - name: RSpec Groups ${{ matrix.ci_job_index }} + name: RSpec Groups ${{ inputs.groups }} runs-on: ubuntu-latest env: RAILS_ENV: test BUNDLE_WITHOUT: "development" - CI_TOTAL_JOBS: ${{ matrix.ci_total_jobs }} - CI_JOB_INDEX: ${{ matrix.ci_job_index }} - GROUPS_COMMA: ${{ join(fromJSON(matrix.ci_job_index), ',') }} - GROUPS_UNDERSCORE: ${{ join(fromJSON(matrix.ci_job_index), '_') }} + CI_TOTAL_JOBS: ${{ inputs.group_count }} + CI_JOB_INDEX: ${{ inputs.groups }} services: db: image: postgres:14.8 @@ -34,21 +37,6 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - strategy: - fail-fast: false - matrix: - # Set N number of parallel jobs you want to run. - # Normally equal to the number of CPU cores but in this case relates to the total number of test groups to be run across all runners. - ci_total_jobs: [12] - # Remember to update ci_node_index below to 0..N-1 - # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc. For larger runners runners with more CPU adjust accordingly. - ci_job_index: - [ - "[0, 1, 2, 3]", - "[4, 5, 6, 7]", - "[8, 9, 10, 11]", - ] - steps: - uses: actions/checkout@v4 @@ -83,7 +71,7 @@ jobs: bundle exec rails css:build bundle exec rails javascript:build - - name: Run rspec group ${{ matrix.ci_job_index }} + - name: Run rspec group ${{ inputs.group }} env: RAILS_ENV: test POSTGRES_HOST: localhost @@ -96,10 +84,26 @@ jobs: RUN_SIMPLECOV: true CC_TEST_REPORTER_ID: 31464536e34ab26588cb951d0fa6b5898abdf401dbe912fd47274df298e432ac run: | - bundle exec parallel_rspec -n "${CI_TOTAL_JOBS}" --only-group "${CI_JOB_INDEX}" ./spec + bundle exec parallel_rspec -n "${CI_TOTAL_JOBS}" --only-group "${CI_JOB_INDEX}" ./spec || true + + - name: Compress artifacts + run: | + zip -r test_reports_${{ env.GROUPS_UNDERSCORE }}.zip tmp/reports + mv tmp/parallel_runtime_rspec.log parallel_runtime_rspec_${{ env.GROUPS_UNDERSCORE }}.log + + - name: Upload test reports + uses: actions/upload-artifact@v4 + with: + name: test_reports_${{ env.GROUPS_UNDERSCORE }}.zip + path: test_reports_${{ env.GROUPS_UNDERSCORE }}.zip + + - name: Upload file parallel tests runtime log + uses: actions/upload-artifact@v4 + with: + name: parallel_runtime_rspec_${{ env.GROUPS_UNDERSCORE }}.log + path: parallel_runtime_rspec_${{ env.GROUPS_UNDERSCORE }}.log - name: Upload Selenium Screenshots - if: ${{ failure() }} uses: actions/upload-artifact@v4 with: name: screenshots_${{ env.GROUPS_UNDERSCORE }} diff --git a/.rspec_parallel b/.rspec_parallel index 252e250b49..5163dccefa 100644 --- a/.rspec_parallel +++ b/.rspec_parallel @@ -1,4 +1,5 @@ ---format progress +--format RspecJunitFormatter +--out tmp/reports/rspec_<%= ENV["GROUPS_UNDERSCORE"] %>_<%= ENV["TEST_ENV_NUMBER"] %>.xml --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log --format ParallelTests::RSpec::SummaryLogger --out tmp/spec_summary.log --format ParallelTests::RSpec::FailuresLogger --out tmp/failing_specs.log diff --git a/Gemfile b/Gemfile index d555b8c80a..5e7ca59f7c 100644 --- a/Gemfile +++ b/Gemfile @@ -66,6 +66,7 @@ group :development, :test do gem "shoulda-matchers" gem "standard", "~> 1.31.0" gem "parallel_tests" + gem "rspec_junit_formatter" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index cacf79f9c6..820fd07a30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -435,6 +435,8 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) rspec-support (3.12.1) + rspec_junit_formatter (0.6.0) + rspec-core (>= 2, < 4, != 2.12.0) rswag-api (2.13.0) activesupport (>= 3.1, < 7.2) railties (>= 3.1, < 7.2) @@ -625,6 +627,7 @@ DEPENDENCIES request_store rexml rspec-rails + rspec_junit_formatter rswag-api rswag-specs rswag-ui