generated from DSCKGEC/project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
47 lines (39 loc) · 1.55 KB
/
heroku-pull-request.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# .github/workflows/heroku-pull-request.yml
name: Heroku Pull Request
on:
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
heroku-pull-request:
runs-on: ubuntu-latest
env:
HEROKU_APP_NAME: codeaon-app-pr-${{ github.event.number }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: ${{ github.event.action == 'closed' && 1 || 0 }}
ref: ${{ github.event.action != 'closed' && github.head_ref || '' }}
- name: Login to Heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
heroku_app_name: ${{ env.HEROKU_APP_NAME }}
justlogin: true
- name: Create Heroku app
if: github.event.action == 'opened'
run: heroku apps:create ${{ env.HEROKU_APP_NAME }}
- name: Add Heroku remote
run: heroku git:remote --app=${{ env.HEROKU_APP_NAME }}
- name: Push to Heroku
run: git push heroku ${{ github.head_ref }}:master --force
- name: Add comment to PR
if: github.event.action == 'opened'
run: |
gh pr comment ${{ github.event.number }} --body 'Deploy Preview: https://${{ env.HEROKU_APP_NAME }}.herokuapp.com'
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
- name: Destroy Heroku app
if: github.event.action == 'closed'
run: heroku apps:destroy --app=${{ env.HEROKU_APP_NAME }} --confirm=${{ env.HEROKU_APP_NAME }}