This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
action.yaml
96 lines (96 loc) · 4.3 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: "Manage Heroku Review Apps"
description: Use Heroku API to replicate the review app integration
author: Peter Mbanugo (@pmbanugo - GitHub)
inputs:
api-key:
description: "Your Heroku API key"
required: true
files-glob:
default: "*"
description: "The glob pattern for files to include in the deployment"
required: false
pipeline-id:
description: "The id of the pipeline to deploy review app for"
required: true
base-name:
description: "The prefix used to generate review app name. This should be the same as what you specified for the review app URL pattern in Heroku Dashboard"
required: true
outputs:
url:
description: "The URL for the app"
value: ${{ steps.output-url.outputs.url }}
branding:
icon: "play-circle"
color: "purple"
runs:
using: "composite"
steps:
- name: Generate app name
shell: bash
run: |
echo "APP_NAME=${{ inputs.base-name }}-pr-${{ github.event.number }}" >> $GITHUB_ENV
- name: Create Source Endpoint
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
id: source_endpoint
shell: bash
run: |
export RESPONSE=$(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 }}")
echo ::set-output name=SOURCE_ENDPOINT::$(echo $RESPONSE | 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 ${{ inputs.files-glob }}
- name: Upload Source Code
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
shell: bash
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') }}
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/review-apps \
-d '{
"source_blob": {"url": "'"$SOURCE_GET_URL"'", "version": "'"${{ github.event.pull_request.head.sha }}"'"},
"branch": "${{ github.head_ref }}",
"pipeline": "${{ inputs.pipeline-id }}",
"pr_number": ${{ github.event.number }}
}' \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${{ inputs.api-key }}"
- name: Create Build
if: ${{ github.event_name == 'pull_request' && github.event.action == 'synchronize' }}
shell: bash
run: |
export SOURCE_GET_URL=$(echo ${{ toJSON(steps.source_endpoint.outputs.SOURCE_ENDPOINT) }} | jq -r '.get')
export OUTPUT_STREAM_URL=$(curl -X POST https://api.heroku.com/apps/$APP_NAME/builds \
-d '{"source_blob":{"url":"'"$SOURCE_GET_URL"'", "version": "${{ github.event.pull_request.head.sha }}"}}' \
-H 'Accept: application/vnd.heroku+json; version=3' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ inputs.api-key }}" | \
jq -r '.output_stream_url')
curl $OUTPUT_STREAM_URL
- name: Set Output:url
id: output-url
shell: bash
run: echo "::set-output name=url::$(echo https://$APP_NAME.herokuapp.com)"
- name: Delete Review App
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
shell: bash
run: |
export REVIEW_APP_ID=$(curl -X GET https://api.heroku.com/apps/$APP_NAME/review-app \
-H 'Accept: application/vnd.heroku+json; version=3' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ inputs.api-key }}" | \
jq -r '.id')
curl -X DELETE https://api.heroku.com/review-apps/$REVIEW_APP_ID \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${{ inputs.api-key }}"