-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (104 loc) · 3.53 KB
/
run-build.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
name: Ensure App Builds Successfully
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
# Job 1: Install Gems
install-gems:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Ruby and Cache Gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # Automatically caches gems based on Gemfile.lock
- name: Debug Bundler Environment
run: |
echo "Ruby version:"
ruby -v
echo "Bundle version:"
bundle --version
echo "Gemfile.lock:"
cat Gemfile.lock || echo "Gemfile.lock is missing!"
echo "Bundler-specific environment variables:"
env | grep -i bundler || echo "No bundler-specific environment variables detected."
# Job 2: Install Node Modules
install-node-modules:
runs-on: ubuntu-latest
needs: install-gems
steps:
- name: Restore Workspace
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node Modules
run: npm install
# Job 3: Precompile Assets
precompile-assets:
runs-on: ubuntu-latest
needs: install-node-modules
steps:
- name: Restore Workspace
uses: actions/checkout@v3
- name: Set up Ruby and Node.js
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Verify Bundler and Gems
run: |
bundle check || bundle install
- name: Debug Installed Gems
run: ls -la $(bundle show rails)
- name: Restore Precompiled Assets Cache
uses: actions/cache@v3
with:
path: public/packs-test
key: ${{ runner.os }}-packs-test-${{ hashFiles('app/assets/**/*', 'package-lock.json', 'Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-packs-test-
- name: Precompile Assets
run: RAILS_ENV=test bundle exec rails assets:precompile --trace
env:
RAILS_ENV: test
- name: Save Precompiled Assets Cache
uses: actions/cache@v3
with:
path: public/packs-test
key: ${{ runner.os }}-packs-test-${{ hashFiles('app/assets/**/*', 'package-lock.json', 'Gemfile.lock') }}
# Job 4: Run Database Migrations and Verify Initialization
migrations-and-init:
runs-on: ubuntu-latest
needs: precompile-assets
steps:
- name: Restore Workspace
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=${{ secrets.DATABASE_USERNAME }}" >> $GITHUB_ENV
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> $GITHUB_ENV
- name: Run Database Migrations
run: |
RAILS_ENV=test bundle exec rails db:migrate
env:
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
RAILS_ENV: test
- name: Verify App Initialization
run: |
RAILS_ENV=test bundle exec rails runner "puts 'App initialized successfully'"
env:
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
RAILS_ENV: test