From 026ec70f0dd1830a2a05047a5638f61b2de2b485 Mon Sep 17 00:00:00 2001
From: Peter Mbanugo
Date: Fri, 29 Apr 2022 16:34:31 +0200
Subject: [PATCH] feat: set up app with app.json
---
README.md | 2 +-
action.yaml | 75 ++++++++++++++++++++++++++++++++++-------------------
2 files changed, 49 insertions(+), 28 deletions(-)
diff --git a/README.md b/README.md
index 9f3b9f5..d3cb9e8 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy Heroku app
- uses: pmbanugo/heroku-review-app-actions@v1.0.1 # Uses the action
+ uses: pmbanugo/heroku-review-app-actions@v1.2.0-dev # Uses the action
id: deploy
with:
api-key: ${{ secrets.HEROKU_API_KEY }}
diff --git a/action.yaml b/action.yaml
index 8495e51..d60260b 100644
--- a/action.yaml
+++ b/action.yaml
@@ -20,6 +20,10 @@ inputs:
description: "Heroku stack to deploy to e.g heroku-18. Default: heroku-20"
default: "heroku-20"
required: false
+ use-app-json:
+ description: "Set up the initial build using app.json. For more info: https://devcenter.heroku.com/articles/setting-up-apps-using-the-heroku-platform-api"
+ default: false
+ required: false
outputs:
url:
description: "The URL for the app"
@@ -39,13 +43,36 @@ runs:
if [[ $APP_PREFIX == '' ]]; then
echo "using default prefix"
- echo "APP_NAME=heroku-review-app-actions-pr-${{ github.event.number }}" >> $GITHUB_ENV
+ echo "APP_NAME=review-actions-pr-${{ github.event.number }}" >> $GITHUB_ENV
else
echo "using app prefix"
echo "APP_NAME=${{ inputs.app-name-prefix }}-pr-${{ github.event.number }}" >> $GITHUB_ENV
fi
- - name: Create App
+ - name: Create Source Endpoint
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
+ id: source_endpoint
+ shell: bash
+ run: |
+ echo ::set-output name=SOURCE_ENDPOINT::$(curl -X POST https://api.heroku.com/sources \
+ -H "Content-Type: application/json" \
+ -H "Accept: application/vnd.heroku+json; version=3" \
+ -H "Authorization: Bearer ${{ inputs.api-key }}" | \
+ jq -r '{get: .source_blob.get_url, put: .source_blob.put_url}')
+ - name: Compress Source Code
+ if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
+ shell: bash
+ run: |
+ tar -czvf source.tar.gz *
+ - name: Upload Source Code
+ if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
+ shell: bash
+ env:
+ SOURCE_ENDPOINT_GET: ${{ steps.source_endpoint_env.outputs.SOURCE_ENDPOINT_GET }}
+ run: |
+ export URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.put')
+ curl $URL -X PUT -H 'Content-Type:' --data-binary @source.tar.gz
+ - name: Create App
+ if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') && inputs.use-app-json == 'false' }}
shell: bash
run: |
curl -X POST https://api.heroku.com/apps \
@@ -57,8 +84,25 @@ runs:
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${{ inputs.api-key }}"
+ - name: "Create App (Setup with app.json)"
+ if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') && inputs.use-app-json == 'true' }}
+ shell: bash
+ run: |
+ export SOURCE_GET_URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.get')
+ curl -X POST https://api.heroku.com/app-setups \
+ -d '{
+ "source_blob": {"url": "'"$SOURCE_GET_URL"'", "version": "'"${{ github.event.pull_request.head.sha }}"'"},
+ "app": {
+ "name": "'"$APP_NAME"'",
+ "region": "${{ inputs.region }}",
+ "stack": "${{ inputs.stack }}"
+ }
+ }' \
+ -H "Content-Type: application/json" \
+ -H "Accept: application/vnd.heroku+json; version=3" \
+ -H "Authorization: Bearer ${{ inputs.api-key }}"
- name: Update Pipeline
- if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
+ if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
shell: bash
run: |
curl -X POST https://api.heroku.com/pipeline-couplings \
@@ -70,31 +114,8 @@ runs:
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${{ inputs.api-key }}"
- - name: Create Source Endpoint
- if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
- id: source_endpoint
- shell: bash
- run: |
- echo ::set-output name=SOURCE_ENDPOINT::$(curl -X POST https://api.heroku.com/sources \
- -H "Content-Type: application/json" \
- -H "Accept: application/vnd.heroku+json; version=3" \
- -H "Authorization: Bearer ${{ inputs.api-key }}" | \
- jq -r '{get: .source_blob.get_url, put: .source_blob.put_url}')
- - name: Compress Source Code
- if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
- shell: bash
- run: |
- tar -czvf source.tar.gz *
- - name: Upload Source Code
- if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
- shell: bash
- env:
- SOURCE_ENDPOINT_GET: ${{ steps.source_endpoint_env.outputs.SOURCE_ENDPOINT_GET }}
- run: |
- export URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.put')
- curl $URL -X PUT -H 'Content-Type:' --data-binary @source.tar.gz
- name: Create Build
- if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
+ if: ${{ github.event_name == 'pull_request' && (github.event.action == 'synchronize' || ((github.event.action == 'opened' || github.event.action == 'reopened') && inputs.use-app-json == 'false')) }}
shell: bash
run: |
export SOURCE_GET_URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.get')