Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
feat: set up app with app.json
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbanugo committed Apr 29, 2022
1 parent c4c955f commit 026ec70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
75 changes: 48 additions & 27 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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')
Expand Down

0 comments on commit 026ec70

Please sign in to comment.