-
Notifications
You must be signed in to change notification settings - Fork 14
129 lines (106 loc) · 5.36 KB
/
heroku-pull-request.yml
File metadata and controls
129 lines (106 loc) · 5.36 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Heroku Pull Request
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
heroku-pull-request:
runs-on: ubuntu-latest
env:
HEROKU_APP_NAME: gyr-review-app-${{ 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: Install Heroku CLI
run: |
curl https://cli-assets.heroku.com/install.sh | sh
- name: Login to Heroku
uses: akhileshns/heroku-deploy@v3.12.13
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_email: jheath@codeforamerica.org
heroku_app_name: ${{ env.HEROKU_APP_NAME }}
justlogin: true
- name: Do we need to create the app?
run: >
if heroku apps:info -a ${{ env.HEROKU_APP_NAME }} > /dev/null 2>&1; then
echo "App exists; skipping setup";
echo "RUN_APP_SETUP=false" >> $GITHUB_ENV;
else
echo "No app found; running app creation and setup";
echo "RUN_APP_SETUP=true" >> $GITHUB_ENV;
fi
- name: Create Heroku app
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku apps:create ${{ env.HEROKU_APP_NAME }} --team getyourrefund --stack heroku-22
- name: Save app name and PR number as heroku environment variable
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku config:set HEROKU_APP_NAME=${{ env.HEROKU_APP_NAME }} HEROKU_PR_NUMBER=${{ github.event.number }} -a ${{ env.HEROKU_APP_NAME }}
- name: Add nodejs buildpack
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku buildpacks:set --app ${{ env.HEROKU_APP_NAME }} --index 1 heroku/nodejs
- name: Add ruby buildpack
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku buildpacks:set --app ${{ env.HEROKU_APP_NAME }} --index 2 heroku/ruby
- name: Add activestorage-preview buildpack
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku buildpacks:set --app ${{ env.HEROKU_APP_NAME }} --index 3 https://github.com/heroku/heroku-buildpack-activestorage-preview
- name: Add jvm buildpack
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku buildpacks:set --app ${{ env.HEROKU_APP_NAME }} --index 4 heroku/jvm
- name: Add heroku-buildpack-run buildpack
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku buildpacks:set --app ${{ env.HEROKU_APP_NAME }} --index 5 https://github.com/weibeld/heroku-buildpack-run.git
- name: Copy environment variables to Heroku app
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: |
heroku config:set -a ${{ env.HEROKU_APP_NAME }} \
RAILS_ENV=heroku \
RACK_ENV=production \
LOG_LEVEL=info \
RAILS_SERVE_STATIC_FILES=enabled \
RAILS_MASTER_KEY=${{ secrets.HEROKU_RAILS_MASTER_KEY }} \
BUNDLE_GITHUB__COM=${{ secrets.BUNDLE_GITHUB__COM }} \
FRAUD_INDICATORS_KEY=${{ secrets.FRAUD_INDICATORS_KEY }} \
HEROKU_DNS_AWS_ACCESS_KEY_ID=${{ secrets.HEROKU_DNS_AWS_ACCESS_KEY_ID }} \
HEROKU_DNS_SECRET_ACCESS_KEY=${{ secrets.HEROKU_DNS_SECRET_ACCESS_KEY }} \
HEROKU_PLATFORM_KEY=${{ secrets.HEROKU_PLATFORM_KEY }} \
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Create database
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku addons:create heroku-postgresql:essential-0 --app ${{ env.HEROKU_APP_NAME }}
- name: Add Heroku remote
run: heroku git:remote --app=${{ env.HEROKU_APP_NAME }}
- name: Disable Reline autocomplete
run: |
echo "IRB.conf[:USE_AUTOCOMPLETE] = false" > .irbrc && \
git add .irbrc && \
git config user.name "GitHub Actions" && \
git config user.email "nobody@example.com" && \
git commit -m "Disable Reline autocomplete"
- name: Push to Heroku
run: git push heroku ${{ github.head_ref }}:main --force
- name: Wait for deploy to finish
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku pg:wait --app=${{ env.HEROKU_APP_NAME }}
- name: Setup database
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku run rails heroku:postdeploy
- name: Setup hostnames (GYR, CTC and StateFile)
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku run rails heroku:review_app_setup
- name: Start the worker process
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: heroku ps:scale worker=1 --app=${{ env.HEROKU_APP_NAME }}
- name: Get heroku generated url
if: ${{ env.RUN_APP_SETUP == 'true' }}
run: echo "HEROKU_URL=$(heroku apps:info -s --app ${{ env.HEROKU_APP_NAME }} | grep web_url | cut -d= -f2)" >> $GITHUB_ENV
- name: Add comment to PR
if: ${{ env.RUN_APP_SETUP == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.number }} --body '[Heroku app](https://dashboard.heroku.com/apps/${{ env.HEROKU_APP_NAME }}): ${{ env.HEROKU_URL }}<br/>View logs: `heroku logs --app ${{ env.HEROKU_APP_NAME }}` (optionally add `--tail`)'