forked from expertiza/reimplementation-back-end
-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (96 loc) · 3.38 KB
/
TestPR.yml
File metadata and controls
111 lines (96 loc) · 3.38 KB
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
name: PR Test Workflow
on:
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]
jobs:
test:
runs-on: ubuntu-latest
env:
DATABASE_URL: mysql2://root:expertiza@127.0.0.1:3306/expertiza_test
RAILS_ENV: test
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: expertiza
MYSQL_DATABASE: expertiza_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v3
- name: Clear Ruby cache
run: |
rm -rf ~/.ruby-version
rm -rf ~/.rbenv
rm -rf ~/.rvm
rm -rf /usr/local/rvm
rm -rf /opt/ruby
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4.5
bundler-cache: false
- name: Check Ruby Version
run: |
ruby -v
which ruby
gem env
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y netcat-traditional
- name: Install Ruby dependencies
run: |
gem update --system
gem install bundler:2.4.7
bundle config set --local deployment 'false'
bundle config set --local without ''
bundle config set --local force_ruby_platform true
bundle install --verbose
- name: Setup database
run: |
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test
- name: Run Tests
id: run_tests
continue-on-error: true # Allow failure capturing
run: |
bundle exec rspec spec/models --format documentation > rspec_results.txt || true
bundle exec rspec spec/requests --format documentation >> rspec_results.txt || true
- name: Save PR number
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
- name: Extract Failed Tests
if: always() # Ensures this step runs regardless of test outcome
run: |
MODEL_FAILURES=$(grep -E "^rspec ./spec/models/" rspec_results.txt || true)
REQUEST_FAILURES=$(grep -E "^rspec ./spec/requests/" rspec_results.txt || true)
if [ -z "$MODEL_FAILURES" ] && [ -z "$REQUEST_FAILURES" ]; then
echo "All tests passed." > failed_tests.txt
else
> failed_tests.txt # Clear the file first
if [ -n "$MODEL_FAILURES" ]; then
echo "Failing Model Test Cases:" >> failed_tests.txt
echo "$MODEL_FAILURES" >> failed_tests.txt
echo "" >> failed_tests.txt
fi
if [ -n "$REQUEST_FAILURES" ]; then
echo "Failing Controller Test Cases:" >> failed_tests.txt
echo "$REQUEST_FAILURES" >> failed_tests.txt
echo "" >> failed_tests.txt
fi
fi
echo "FAILED_TESTS<<EOF" >> $GITHUB_ENV
cat failed_tests.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
with:
name: failed-tests
path: |
failed_tests.txt
pr_number.txt