Update app.test.js #28
This file contains hidden or 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: Test & Deploy Economatic to EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| name: Run HTML & Rails Tests | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: eco_frontend_local | |
| steps: | |
| # Step 1: Checkout the code | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Step 2: Set up Node.js | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '20' | |
| # Step 3: Install dependencies | |
| - name: Install dependencies | |
| run: npm install | |
| # Step 4: Run Tests | |
| - name: Run tests | |
| run: npm test | |
| deploy: | |
| name: Deploy Rails App to EC2 | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout the code | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Step 2: Set up Ruby environment | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: 3.3.5 | |
| bundler-cache: true | |
| # Step 3: Install dependencies in backend folder | |
| - name: Install dependencies | |
| working-directory: eco_backend | |
| run: | | |
| bundle install | |
| - name: Debug eco_backend contents | |
| working-directory: eco_backend | |
| run: ls -la | |
| # Step 4: Regenerate binstubs for Linux | |
| - name: BinStubs | |
| working-directory: eco_backend | |
| run: | | |
| rm -rf bin | |
| bundle install | |
| bundle binstubs bundler --force | |
| bundle exec rails app:update:bin RAILS_ENV=production | |
| # Step 5: Ensure Rails bin files have execution permissions | |
| - name: Fix Rails permissions | |
| working-directory: eco_backend | |
| run: | | |
| chmod +x bin/* | |
| # Step 6: Run database migrations | |
| - name: Set up database | |
| working-directory: eco_backend | |
| run: | | |
| bundle exec rails db:migrate RAILS_ENV=production | |
| # Step 7: Precompile assets | |
| - name: Precompile assets | |
| working-directory: eco_backend | |
| run: | | |
| bundle exec rails assets:precompile RAILS_ENV=production | |
| # Step 8: Deploy to EC2 | |
| - name: Deploy to EC2 | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }} | |
| EC2_HOST: ${{ secrets.EC2_HOST }} | |
| EC2_USER: ${{ secrets.EC2_USER }} | |
| run: | | |
| echo "$SSH_PRIVATE_KEY" > private_key.pem | |
| chmod 600 private_key.pem | |
| DEPLOY_DIR=/var/www/economatic | |
| # Transfer the application files to the EC2 instance | |
| scp -i private_key.pem -o StrictHostKeyChecking=no -r ./eco_backend $EC2_USER@$EC2_HOST:$DEPLOY_DIR | |
| # SSH into the EC2 instance and finalize the deployment | |
| ssh -i private_key.pem $EC2_USER@$EC2_HOST << 'EOF' | |
| cd $DEPLOY_DIR | |
| bundle install | |
| RAILS_ENV=production bin/rails db:migrate | |
| RAILS_ENV=production bin/rails assets:precompile | |
| sudo systemctl restart economatic | |
| EOF | |
| # Step 9: Clean up sensitive data | |
| - name: Clean up | |
| run: rm -f private_key.pem |