WIP Libaaec 38 migrate from circle ci to GitHub actions to handle ci #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Ensure RSpec Tests Pass | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
permissions: | |
contents: write | |
actions: read | |
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: Set Environment Variables | |
run: | | |
echo "COVERAGE=true" >> $GITHUB_ENV | |
echo "PARALLEL_TEST_GROUPS=true" >> $GITHUB_ENV | |
- name: Generate Runtime Log with Error Output | |
run: | | |
mkdir -p tmp | |
echo "Generating runtime log and capturing errors..." | |
set -o pipefail | |
bundle exec rspec --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log --pattern 'spec/**/*_spec.rb' --backtrace 2> tmp/rspec-errors.log || true | |
echo "Rspec error log (if any):" | |
cat tmp/rspec-errors.log || echo "No errors logged." | |
echo "Runtime log contents:" | |
cat tmp/parallel_runtime_rspec.log || echo "Runtime log is empty." | |
- name: Debug RSpec Execution | |
run: | | |
echo "Checking if RSpec ran any tests..." | |
bundle exec rspec --pattern 'spec/**/*_spec.rb' --dry-run || echo "RSpec dry-run failed. Check for issues." | |
echo "Runtime log contents:" | |
cat tmp/parallel_runtime_rspec.log || echo "Runtime log is empty." | |
- name: Debug RSpec Errors | |
run: | | |
echo "RSpec Errors:" | |
cat tmp/rspec-errors.log || echo "No errors logged." | |
- 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 "COVERAGE=true" >> $GITHUB_ENV | |
echo "PARALLEL_TEST_GROUPS=true" >> $GITHUB_ENV | |
- name: Download Runtime Log | |
uses: actions/download-artifact@v4 | |
with: | |
name: parallel-runtime-log | |
path: tmp | |
- name: Pre-create Test Results Directory | |
run: mkdir -p tmp/test_results | |
- name: Run Tests for Job Index ${{ matrix.job_index }} | |
run: | | |
if grep -q "filesize fallback" tmp/parallel_runtime_rspec.log; then | |
echo "Falling back to grouping by filesize..." | |
find spec -name '*_spec.rb' > tmp/test_files.txt | |
TEST_ENV_NUMBER=${{ matrix.job_index }} bundle exec parallel_rspec --group-by filesize --only-group ${{ matrix.job_index }} -- \ | |
--format RspecJunitFormatter --out tmp/test_results/result-${{ matrix.job_index }}.xml $(cat tmp/test_files.txt) | |
else | |
TEST_ENV_NUMBER=${{ matrix.job_index }} bundle exec parallel_rspec --group-by runtime --only-group ${{ matrix.job_index }} -- \ | |
--format RspecJunitFormatter --out tmp/test_results/result-${{ matrix.job_index }}.xml | |
fi | |
- name: Upload Test Results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ matrix.job_index }} | |
path: tmp/test_results/result-${{ matrix.job_index }}.xml | |
- name: Upload Coverage Results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-result-${{ matrix.job_index }} | |
path: coverage/.resultset.${{ matrix.job_index }}.json | |
combine-coverage: | |
needs: rspec | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Coverage Results | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage-result-* | |
path: coverage/ | |
- name: Combine Coverage | |
run: | | |
bundle exec ruby -e " | |
require 'simplecov'; | |
SimpleCov.collate Dir['coverage/.resultset.*.json'], 'rails' do | |
formatter SimpleCov::Formatter::MultiFormatter.new([ | |
SimpleCov::Formatter::HTMLFormatter, | |
Coveralls::SimpleCov::Formatter | |
]) | |
end" |