WIP Libaaec 38 migrate from circle ci to GitHub actions to handle ci #32
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 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 |