-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
60 lines (54 loc) · 1.8 KB
/
action.yml
File metadata and controls
60 lines (54 loc) · 1.8 KB
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
# This composite action is used to send JSON data to a specified URL using curl.
# It requires three input parameters:
# URL: The URL where the JSON will be sent
# TOKEN: The bearer authorization token for the API
# JSON: The JSON data that will be sent to the URL
#
# The action first validates the JSON input using the jq command to ensure it is in the proper format.
# If the JSON input is not valid, the action will exit with an error code and fail.
# If the JSON input is valid, the action will send the data to the specified URL using curl, and output the response.
name: Post JSON to URL
description: Send JSON data to a specified URL
runs:
using: 'composite'
steps:
- name: Install jq
shell: bash
run: |
which jq > /dev/null
if [ $? -ne 0 ]; then
sudo apt-get install jq
fi
- name: Validate JSON input
shell: bash
env:
JSON: ${{ inputs.JSON }}
run: |
echo $JSON | jq '.' > /dev/null
if [ $? -ne 0 ]; then
echo "Invalid JSON input"
exit 1
fi
- name: Post JSON to URL
shell: bash
env:
URL: ${{ inputs.URL }}
TOKEN: ${{ inputs.TOKEN }}
JSON: ${{ inputs.JSON }}
run: |
response=$(curl -X POST -H "Content-Type: application/json" -H "Authorization: $AUTHORIZATION" -d "$JSON" $URL)
echo "response=$response" >> $GITHUB_OUTPUT
inputs:
URL:
description: 'The URL where the JSON will be sent'
required: true
AUTHORIZATION:
description: 'The Authorization header content for the API'
required: true
JSON:
description: 'The JSON data that will be sent to the URL'
required: true
outputs:
response:
description: 'The response received from the API'
value: ${{ steps.Post_JSON_to_URL.outputs.response }}