-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
65 lines (61 loc) · 2.07 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
name: "Upload Event Types to Svix"
description: "Upload Event Types from an OpenAPI spec to Svix"
branding:
icon: 'copy'
color: 'blue'
inputs:
openapi-file:
description: "Location of the OpenAPI spec file (JSON or YAML)"
required: true
svix-api-key:
description: "Svix API key"
required: true
svix-api-url:
description: "Override Svix API URL"
required: false
replace-all:
description: "Archive all existing event types that are not in the OpenAPI spec"
required: false
default: "false"
runs:
using: "composite"
steps:
- name: Check input variables
run: |
if [ ! -f ${{inputs.openapi-file}} ]; then
echo "OpenAPI spec file not found"
exit 1
fi
shell: bash
- name: Determine Svix API URL
run: |
if [ "${{ inputs.svix-api-url }}" != '' ]; then
echo "SVIX_API_URL=${{ inputs.svix-api-url }}" >> $GITHUB_ENV
exit 0
fi
REGION_CODE=$(echo ${{ inputs.svix-api-key }} | cut -d '.' -f 2)
case $REGION_CODE in
us)
SVIX_API_URL="api.us.svix.com"
;;
eu)
SVIX_API_URL="api.eu.svix.com"
;;
*)
SVIX_API_URL="api.svix.com"
;;
esac
echo "SVIX_API_URL=$SVIX_API_URL" >> $GITHUB_ENV
shell: bash
- name: Upload OpenAPI spec to Svix
run: |
TMP_PAYLOAD=$(mktemp)
python3 -c "import json; print(json.dumps({'specRaw': open('./${{inputs.openapi-file}}','r').read(), 'replaceAll': 'true' == '${{inputs.replace-all == 'true' || inputs.replace-all == true}}' }))" > $TMP_PAYLOAD
echo "Uploading OpenAPI spec to https://$SVIX_API_URL/api/v1/event-type/import/openapi/"
curl --fail-with-body -X 'POST' "https://$SVIX_API_URL/api/v1/event-type/import/openapi/" \
-H 'Authorization: Bearer ${{ inputs.svix-api-key }}' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data-binary "@$TMP_PAYLOAD" | jq
rm $TMP_PAYLOAD
shell: bash