-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (122 loc) · 4.8 KB
/
run-rspec-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Ensure RSpec Tests Pass
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
generate-runtime-log:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install Dependencies
run: bundle install
- name: Disable Coverage Tools
run: echo "COVERAGE=false" >> $GITHUB_ENV
- name: Generate Runtime Log
run: |
mkdir -p tmp
COVERAGE=false bundle exec rspec --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log --pattern 'spec/**/*_spec.rb'
- name: Debug Runtime Log
run: |
echo "Runtime log contents:"
cat tmp/parallel_runtime_rspec.log || echo "Runtime log is missing or empty."
- name: Upload Runtime Log
uses: actions/upload-artifact@v4
with:
name: parallel-runtime-log
path: tmp/parallel_runtime_rspec.log
rspec:
needs: generate-runtime-log
strategy:
matrix:
job_index: [0, 1, 2, 3]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Set Environment Variables
run: |
echo "DATABASE_USERNAME=apache" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=" >> $GITHUB_ENV
echo "COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }}" >> $GITHUB_ENV
- name: Download Runtime Log
uses: actions/download-artifact@v4
with:
name: parallel-runtime-log
path: tmp
- name: Install Dependencies
run: bundle install
- name: Pre-create Test Results Directory
run: mkdir -p tmp/test_results
- name: Run Tests for Job Index ${{ matrix.job_index }}
run: |
TEST_ENV_NUMBER=${{ matrix.job_index }} bundle exec parallel_rspec --group-by runtime --only-group ${{ matrix.job_index }} -- \
"spec" --format RspecJunitFormatter --out tmp/test_results/result-${{ matrix.job_index }}.xml \
|| TEST_ENV_NUMBER=${{ matrix.job_index }} bundle exec parallel_rspec --group-by filesize --only-group ${{ matrix.job_index }} -- \
"spec" --format RspecJunitFormatter --out tmp/test_results/result-${{ matrix.job_index }}.xml
env:
COVERALLS_PARALLEL: true
- name: Debug Test Output
run: |
echo "Checking if test output was generated for job index ${{ matrix.job_index }}:"
cat tmp/test_results/result-${{ matrix.job_index }}.xml || echo "No test output found."
- name: Save Test Results
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.job_index }}
path: tmp/test_results/result-${{ matrix.job_index }}.xml
if-no-files-found: error
- name: Save Partial Coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.job_index }}
path: coverage/lcov/coverage-${{ matrix.job_index }}.info
if-no-files-found: error
combine-results-and-coverage:
needs: rspec
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download Partial Test Results
run: |
mkdir -p tmp/test_results
for i in 0 1 2 3; do
actions/download-artifact@v4 --name test-results-${i} --path tmp/test_results || exit 1
done
- name: Combine Test Results
run: |
mkdir -p coverage
cat tmp/test_results/*.xml > coverage/combined_results.xml
- name: Upload Combined Test Results
uses: actions/upload-artifact@v4
with:
name: combined-test-results
path: coverage/combined_results.xml
- name: Download Partial Coverage Files
run: |
mkdir -p coverage/lcov
for i in 0 1 2 3; do
actions/download-artifact@v4 --name coverage-${i} --path coverage/lcov || exit 1
done
- name: Combine Coverage Files
run: |
gem install coveralls-lcov --user-install
export PATH="$HOME/.gem/ruby/$(ruby -e 'puts RUBY_VERSION')/bin:$PATH"
lcov --add-tracefile=coverage/lcov/coverage-0.info \
--add-tracefile=coverage/lcov/coverage-1.info \
--add-tracefile=coverage/lcov/coverage-2.info \
--add-tracefile=coverage/lcov/coverage-3.info \
--output-file=coverage/lcov/combined.info
- name: Upload Combined Coverage to Coveralls
run: coveralls-lcov -v -n coverage/lcov/combined.info
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}