Skip
Arish's avatar

13. Deploying to Heroku


Heroku Deploy Action

yaml
1jobs:
2  deploy:
3    runs-on: ubuntu-latest
4    needs: test
5    if: github.ref == 'refs/heads/main'
6    
7    steps:
8      - uses: actions/checkout@v4
9      
10      - name: Deploy to Heroku
11        uses: akhileshns/heroku-deploy@v3.12.14
12        with:
13          heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
14          heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
15          heroku_email: ${{ secrets.HEROKU_EMAIL }}

With Docker

yaml
1- name: Deploy to Heroku
2  uses: akhileshns/heroku-deploy@v3.12.14
3  with:
4    heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
5    heroku_app_name: myapp
6    heroku_email: dev@example.com
7    usedocker: true

Run Migrations

yaml
1- name: Deploy and migrate
2  uses: akhileshns/heroku-deploy@v3.12.14
3  with:
4    heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
5    heroku_app_name: myapp
6    heroku_email: dev@example.com
7    healthcheck: https://myapp.herokuapp.com/health
8    rollbackonhealthcheckfailed: true
9
10- name: Run migrations
11  run: heroku run rails db:migrate -a myapp
12  env:
13    HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}

Review Apps

yaml
1# Deploy PR to review app
2- name: Create Review App
3  if: github.event_name == 'pull_request'
4  run: |
5    heroku apps:create myapp-pr-${{ github.event.number }} --remote pr
6    git push pr HEAD:main