forked from zingdevlimited/actions-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
75 lines (69 loc) · 3.01 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
name: "Get Twilio Resource SID"
description: Fetch the SID of an existing Twilio resource from a Twilio account. [Documentation](https://github.com/zingdevlimited/actions-helpers/blob/v3/docs/usage/composite-actions-general.md#get-twilio-resource-sid)
inputs:
TWILIO_AREA:
required: true
description: "The API subdomain. e.g.: `sync`, `studio`, `taskrouter`"
API_TYPE:
required: true
description: "The type of resource in the format used in the API call URL path. e.g.: `Services`, `Flows`, `TaskQueues`"
SEARCH_BY:
required: true
description: "The name of the field on a resource object that you want to match in search. e.g.: `friendly_name`, `unique_name`"
SEARCH_VALUE:
required: true
description: "Used to select your resource by ensuring `resource.<SEARCH_BY> == <SEARCH_VALUE>`"
VERSION:
required: false
default: v1
description: "The API version. If omitted it defaults to `v1`. For some twilio areas (e.g. studio) it should be set to `v2`."
TWILIO_API_KEY:
required: true
description: Twilio API Key
TWILIO_API_SECRET:
required: true
description: Twilio API Secret
ALLOW_NO_RESULTS:
required: false
description: |
(Optional) set to `true` to not throw an error if the resource could not be found.
Instead, the `SID` output will return an empty string.
# Obsolete Inputs
JSON_TYPE:
required: false
description: (OBSOLETE) No longer has an effect
outputs:
SID:
description: The resulting SID
value: ${{ steps.get.outputs.SID }}
runs:
using: composite
steps:
- name: Validate Inputs
shell: bash
run: |
fail=""
[[ -z "${{ inputs.TWILIO_AREA }}" ]] && echo "::error::Missing TWILIO_AREA in inputs" && fail=1
[[ -z "${{ inputs.API_TYPE }}" ]] && echo "::error::Missing API_TYPE in inputs" && fail=1
if [ "${{ inputs.TWILIO_AREA }}" != "taskrouter" ] || [ "${{ inputs.API_TYPE }}" != "Workspaces" ]; then
[[ -z "${{ inputs.SEARCH_BY }}" ]] && echo "::error::Missing SEARCH_BY in inputs" && fail=1
[[ -z "${{ inputs.SEARCH_VALUE }}" ]] && echo "::error::Missing SEARCH_VALUE in inputs" && fail=1
fi
[[ -z "${{ inputs.TWILIO_API_KEY }}" ]] && echo "::error::Missing TWILIO_API_KEY in inputs" && fail=1
[[ -z "${{ inputs.TWILIO_API_SECRET }}" ]] && echo "::error::Missing TWILIO_API_SECRET in inputs" && fail=1
[[ -n "$fail" ]] && exit 1 || exit 0
- name: Get ${{ inputs.TWILIO_AREA }}:${{ inputs.VERSION }}:${{ inputs.API_TYPE }}
id: get
shell: bash
run: |
result=$(${{ github.action_path }}/get-twilio-resource-sid.sh \
"${{ inputs.TWILIO_AREA }}" \
"${{ inputs.API_TYPE }}" \
"${{ inputs.SEARCH_BY }}" \
"${{ inputs.SEARCH_VALUE }}" \
"${{ inputs.VERSION }}" \
"${{ inputs.ALLOW_NO_RESULTS }}")
echo "SID=$result" >> "$GITHUB_OUTPUT"
env:
TWILIO_API_KEY: ${{ inputs.TWILIO_API_KEY }}
TWILIO_API_SECRET: ${{ inputs.TWILIO_API_SECRET }}