Add deploy workflow and fix specs task #1
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: Rails CI/CD Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "config/specs/**" | |
| - "app/**" | |
| - "config/**" | |
| - "db/**" | |
| - "lib/**" | |
| - "Gemfile" | |
| - "Gemfile.lock" | |
| - "Dockerfile" | |
| - "config/deploy.yml" | |
| - ".github/workflows/deploy.yml" | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| name: Validate and Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| bundler-cache: true | |
| - name: Validate business spec | |
| run: bundle exec rake specs:validate | |
| - name: Run tests | |
| run: bundle exec rails test | |
| env: | |
| RAILS_ENV: test | |
| deploy: | |
| name: Deploy to Lightsail | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| environment: production | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| bundler-cache: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Set up SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.LIGHTSAIL_SSH_KEY }}" > ~/.ssh/lightsail_key | |
| chmod 600 ~/.ssh/lightsail_key | |
| ssh-keyscan -H ${{ vars.LIGHTSAIL_HOST }} >> ~/.ssh/known_hosts | |
| - name: Start ssh-agent | |
| run: | | |
| eval "$(ssh-agent -s)" | |
| ssh-add ~/.ssh/lightsail_key | |
| - name: Write Kamal secrets | |
| run: | | |
| mkdir -p .kamal | |
| cat > .kamal/secrets <<EOF | |
| RAILS_MASTER_KEY=${{ secrets.RAILS_MASTER_KEY }} | |
| KAMAL_REGISTRY_PASSWORD=${{ secrets.GHCR_TOKEN }} | |
| EOF | |
| - name: Run spec sync | |
| run: bundle exec rails specs:sync | |
| env: | |
| RAILS_ENV: production | |
| - name: Deploy with Kamal | |
| run: bundle exec kamal deploy |