FYST-792: ID Grocery Credit #10656
This file contains 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: 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: Login to Heroku | |
uses: akhileshns/[email protected] | |
with: | |
heroku_api_key: ${{ secrets.HEROKU_API_KEY }} | |
heroku_email: [email protected] | |
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_NEW=${{ secrets.RAILS_MASTER_KEY_NEW }} \ | |
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 }} | |
- 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 "[email protected]" && \ | |
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`)' |