-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
66 lines (66 loc) · 3.2 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
name: 'Create Mender deployment'
description: 'Create a deployment on a Mender server'
branding:
icon: "send"
color: "white"
inputs:
mender_pat:
description: 'personal access token for the Mender server account to be used'
required: true
mender_deployment_name:
description: 'deployment name to be created'
required: true
mender_release_name:
description: 'Mender Artifacts release name'
required: true
mender_devices_group:
description: 'the name of the devices group to which the release will be deployed'
required: false
mender_devices_list:
description: 'the list of device IDs to which the release will be deployed'
required: false
mender_uri:
description: 'URI for the Mender server to be used'
required: false
default: 'https://hosted.mender.io'
runs:
using: "composite"
steps:
- id: input_validation
shell: bash
run: |
if [[ -z "${{ inputs.mender_devices_group }}" && -z "${{ inputs.mender_devices_list }}" ]]; then
echo "ERROR: both mender_devices_group and mender_devices_list are empty, at least one is expected to be set"
exit 1
fi
if [ ! -f $(which curl) ]; then
echo "ERROR: 'curl' is missing"
exit 1
fi
- id: create_deployment
shell: bash
run: |
if [ ! -z ${{ inputs.mender_devices_group }} ]; then
# Makes management 'create deployment for group' API call to Mender server, using curl
# https://docs.mender.io/api/#management-api-deployments-create-deployment-for-a-group-of-devices
RESPONSE=$(curl -s -X POST https://hosted.mender.io/api/management/v1/deployments/deployments/group/${{ inputs.mender_devices_group }} \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${{ inputs.mender_pat }}" \
--data-raw "{\"name\": \"${{ inputs.mender_deployment_name }}\", \"artifact_name\": \"${{ inputs.mender_release_name }}\"}")
else
# Makes management 'create deployment' API call to Mender server, using curl
# https://docs.mender.io/api/#management-api-deployments-create-deployment
MENDER_DEVICES_LIST=${{ inputs.mender_devices_list }}
RESPONSE=$(curl -s -X POST ${{ inputs.mender_uri }}/api/management/v1/deployments/deployments \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${{ inputs.mender_pat }}" \
--data-raw "{\"name\": \"${{ inputs.mender_deployment_name }}\", \"artifact_name\": \"${{ inputs.mender_release_name }}\", \"devices\": ${MENDER_DEVICES_LIST}}")
fi
if [[ ! -z "${RESPONSE}" || "${RESPONSE}" != "" ]]; then
echo "ERROR: failed to create deployment '${{ inputs.mender_deployment_name }}', devices: ${MENDER_DEVICES_LIST}, server: ${{ inputs.mender_uri }}"
echo "Server's response: ${RESPONSE}"
exit 1
fi
echo "INFO: deployment '${{ inputs.mender_deployment_name }}' with release '${{ inputs.mender_release_name }}' for device group '${{ inputs.mender_devices_group }}${{ inputs.mender_devices_list }}' successfully created"