Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticspoon committed Apr 29, 2024
1 parent 869494f commit afe2649
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 33 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/combine_and_report.yml
Original file line number Diff line number Diff line change
@@ -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')
68 changes: 36 additions & 32 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion .rspec_parallel
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -625,6 +627,7 @@ DEPENDENCIES
request_store
rexml
rspec-rails
rspec_junit_formatter
rswag-api
rswag-specs
rswag-ui
Expand Down

0 comments on commit afe2649

Please sign in to comment.