WIP Libaaec 38 migrate from circle ci to GitHub actions to handle ci #18
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 | |
# Install Ruby and Cache Gems | |
- name: Set up Ruby and Cache Gems | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true # Automatically caches gems based on Gemfile.lock | |
# Job 2: Install Node Modules | |
install-node-modules: | |
runs-on: ubuntu-latest | |
needs: [install-gems] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
# Install Node Modules | |
- name: Install Node Modules | |
run: npm install | |
# Job 3: Precompile Assets | |
precompile-assets: | |
runs-on: ubuntu-latest | |
needs: [install-node-modules] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Restore Ruby and Node.js environments | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
# Restore Precompiled Assets Cache | |
- 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- | |
# Ensure Public Directory Exists | |
- name: Ensure Assets Directory Exists | |
run: mkdir -p public/packs-test | |
# Precompile Assets | |
- name: Precompile Assets | |
run: RAILS_ENV=test bundle exec rails assets:precompile --trace | |
# Save Precompiled Assets Cache | |
- 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: Checkout code | |
uses: actions/checkout@v3 | |
# Set up Ruby and Cache Gems | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
# Set up Environment Variables | |
- name: Set Environment Variables | |
run: | | |
echo "DATABASE_USERNAME=apache" >> $GITHUB_ENV | |
echo "DATABASE_PASSWORD=" >> $GITHUB_ENV | |
# Run Database Migrations | |
- name: Run Database Migrations | |
env: | |
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }} | |
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
run: RAILS_ENV=test bundle exec rails db:migrate | |
# Verify App Initialization | |
- name: Verify App Initialization | |
env: | |
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }} | |
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
run: RAILS_ENV=test bundle exec rails runner "puts 'App initialized successfully'" |