Skip to content

Commit

Permalink
docs: Add Parallel Test Example
Browse files Browse the repository at this point in the history
  • Loading branch information
aki77 committed Jun 28, 2024
1 parent 1ee6b97 commit 653d1ce
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ on:
jobs:
rspec:
steps:
# setup...

- name: Test
run: bundle exec rspec -f j -o tmp/rspec_results.json -f p

Expand All @@ -33,3 +35,63 @@ jobs:
json-path: tmp/rspec_results.json
if: always()
```
## Parallel Test Example
```yaml
name: Build
on:
pull_request:

jobs:
rspec:
strategy:
fail-fast: false
matrix:
ci_node_index: [0, 1]
ci_node_total: [2]
steps:
# setup...

# Recommend using `r7kamura/split-tests-by-timings`.
- id: split-tests
run: |
PATHS=$(
find spec -type f -name '*_spec.rb' | \
xargs wc -l | \
head -n -1 | \
sort -n | \
awk -v node=${{ matrix.ci_node_index }} -v total=${{ matrix.ci_node_total }} 'NR % total == node {print $2}' | \
tr '\n' ' '
)
echo "paths=$PATHS" >> "$GITHUB_OUTPUT"
shell: bash

- name: Test
run: |
bundle exec rspec \
-f j -o tmp/json-reports/rspec_results-${{ matrix.ci_node_index }}.json \
-f p \
${{ steps.split-tests.outputs.paths }}
- uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: json-reports-${{ matrix.ci_node_index }}
path: tmp/json-reports
if: always()

report-rspec:
needs: rspec
if: always()
steps:
- name: Download all rspec results
uses: actions/download-artifact@v4
with:
pattern: json-reports-*
path: /tmp/json-reports
merge-multiple: true
- name: RSpec Report
uses: SonicGarden/rspec-report-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
json-path: /tmp/json-reports/rspec_results-*.json
```

0 comments on commit 653d1ce

Please sign in to comment.