From 42535b3dcbf5aacaf7e64d43338f4749a4fdd899 Mon Sep 17 00:00:00 2001 From: Peter Mbanugo Date: Wed, 4 May 2022 22:23:34 +0200 Subject: [PATCH] fix: use specify team when creating app with app.json --- README.md | 1 + action.yaml | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 679f39d..8205799 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ The action expects a few input parameters which are defined below. - region (optional): The region to deploy to. For example `eu` or `us`. Default: `eu` - stack (optional): The Heroku stack to deploy and build with e.g heroku-18. Default: `heroku-20`. If the input `use-app-json` is `true`, the stack will be determined by what's in `app.json`, and if not present, the default on Heroku will be used. - use-app-json (optional): Set up the initial build using the `app.json` in the root directory. Default: `false`. +- team (optional): The Heroku team the app belongs to. ## What's next? diff --git a/action.yaml b/action.yaml index 6da1546..98ca17e 100644 --- a/action.yaml +++ b/action.yaml @@ -20,6 +20,9 @@ inputs: description: "Heroku stack to deploy to e.g heroku-18. Default: heroku-20" default: "heroku-20" required: false + team: + description: "The Heroku team the app belongs to." + 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 @@ -85,7 +88,7 @@ runs: -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' }} + if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') && inputs.use-app-json == 'true' && inputs.team == '' }} shell: bash run: | export SOURCE_GET_URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.get') @@ -100,6 +103,23 @@ runs: -H "Content-Type: application/json" \ -H "Accept: application/vnd.heroku+json; version=3" \ -H "Authorization: Bearer ${{ inputs.api-key }}" + - name: "Create Team App (Setup with app.json)" + if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened') && inputs.use-app-json == 'true' && inputs.team != '' }} + 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 }}", + "organization": "${{ inputs.team }}" + } + }' \ + -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 == 'opened' || github.event.action == 'reopened') }} shell: bash