-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
93 lines (83 loc) · 3.6 KB
/
action.yml
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
name: "Automate Heroku Review Apps"
description: Use Heroku API to replicate the review app integration
inputs:
api-key:
description: "Your Heroku API key"
required: true
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 }}
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.label.name != 'delete-review-app' }}
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.label.name != 'delete-review-app' }}
shell: bash
run: |
tar -czvf source.tar.gz *
- name: Upload Source Code
if: ${{ github.event.label.name != 'delete-review-app' }}
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.label.name == 'create-review-app' }}
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.label.name == 'update-review-app' }}
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.label.name == 'delete-review-app' }}
shell: bash
run: |
curl -X DELETE https://api.heroku.com/apps/$APP_NAME \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${{ inputs.api-key }}"