Created
May 3, 2022 09:49
-
-
Save defkode/6a9505130d6694a9d84abc4c5987f4db to your computer and use it in GitHub Desktop.
Github Actions for Automatic Creation/Update Heroku review apps without connecting Github to Heroku and without app.json configuration
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
# please set up following github secrets in your repo: | |
# HEROKU_PIPELINE_NAME (https://devcenter.heroku.com/articles/pipelines#creating-pipelines) | |
# HEROKU_USER (your heroku username/email) | |
# HEROKU_API_KEY (use: 'heroku authorizations:create' for creating separate api_key for this purpose) | |
name: Heroku Review App Create | |
on: | |
pull_request: | |
types: opened | |
branches: | |
- 'main' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
env: | |
HEROKU_PIPELINE_NAME: ${{secrets.HEROKU_PIPELINE_NAME}} # i.e: your-pipeline | |
# here you can configure your desired app name format: https://your-pipeline-pr-1001.herokuapp.com | |
HEROKU_APP_NAME: ${{secrets.HEROKU_PIPELINE_NAME}}-pr-${{ github.event.number }} | |
HEROKU_REGION: eu # set your desired region here | |
steps: | |
- uses: actions/checkout@v2 | |
- name: "[Heroku] Setup credentials" | |
env: | |
HEROKU_USER: ${{ secrets.HEROKU_USER }} | |
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} | |
run: envsubst < ./config/heroku/netrc > ~/.netrc | |
- name: "[Heroku] Create review app" | |
env: | |
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} | |
run: | | |
heroku apps:create ${HEROKU_APP_NAME} --region ${HEROKU_REGION} | |
heroku config:add HEROKU_DEBUG_RAILS_RUNNER=1 RAILS_STAGE=staging RAILS_MASTER_KEY=${RAILS_MASTER_KEY} -a ${HEROKU_APP_NAME} | |
heroku git:remote -a ${HEROKU_APP_NAME} | |
- name: "[Heroku] Setup Addons" | |
# set your addons here | |
run: heroku addons:create heroku-postgresql:hobby-dev | |
- name: "[Heroku] Add to pipeline" | |
run: heroku pipelines:add ${HEROKU_PIPELINE_NAME} -a ${HEROKU_APP_NAME} -s staging | |
- name: "[Heroku] Deploy" | |
run: | | |
git fetch origin ${{ github.head_ref }}:head | |
git push heroku head:main | |
- name: "[Heroku] Postdeploy" | |
# Good place for one time setup i.e: loading schema and seeding db with test data | |
run: heroku run rails db:setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment