-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathaction.yml
More file actions
108 lines (92 loc) · 3.73 KB
/
action.yml
File metadata and controls
108 lines (92 loc) · 3.73 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: create_mrt_target
description: Create MRT Environment
inputs:
project_id:
description: "MRT Project ID"
target_id:
description: "MRT Target ID"
proxy_configs:
description: "Proxy Configs"
mobify_api_key:
description: "Mobify user API key"
runs:
using: composite
steps:
- name: Initialize
id: initialize
shell: bash
run: |
set -e
echo "TARGET_API_BASE_URL=https://cloud.mobify.com/api/projects/${{ inputs.project_id }}/target" >> $GITHUB_ENV
- name: Get target
id: get_target
shell: bash
run: |-
set -e
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/${{ inputs.target_id }}" \
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}")
http_status=$(echo $response | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
echo "status=$http_status" >> $GITHUB_OUTPUT
if [ "$http_status" -eq 404 ]; then
echo "MRT environment not found, it will be created in the next step."
elif [ "$http_status" -eq 200 ]; then
echo "MRT environment already exists."
else
echo "Error: Unexpected HTTP status: $http_status"
exit 1
fi
- name: Create target
id: create_target
if: ${{ steps.get_target.outputs.status == '404' }}
shell: bash
run: |-
set -e
proxy_config_json=$(echo ${{ inputs.proxy_configs }} | jq -r .)
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/" \
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}" \
--header "Content-Type: application/json" \
--data "$(jq -n \
--arg name "${{ inputs.target_id }}" \
--arg slug "${{ inputs.target_id }}" \
--argjson ssr_proxy_configs "$proxy_config_json" \
'{name: $name, slug: $slug, ssr_proxy_configs: $ssr_proxy_configs}')")
http_status=$(echo "$response" | sed -n 's/.*HTTPSTATUS://p')
response_body=$(echo "$response" | sed -e 's/HTTPSTATUS:.*//g')
echo "status=$http_status" >> $GITHUB_OUTPUT
if [ "$http_status" -ne 201 ]; then
echo "Request failed with status code $http_status"
echo "Response Body: $response_body"
exit 1
fi
- name: Wait for target to be active
id: wait_for_target
if: ${{ steps.create_target.outputs.status == '201' }}
shell: bash
run: |-
set -e
max_attempts=30
sleep_duration=30
attempts=0
while [ $attempts -lt $max_attempts ]; do
response=$(curl --location --silent --show-error --write-out "HTTPSTATUS:%{http_code}" "$TARGET_API_BASE_URL/${{ inputs.target_id }}" \
--header "Authorization: Bearer ${{ inputs.mobify_api_key }}")
http_status=$(echo $response | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
response_body=$(echo $response | sed -e 's/HTTPSTATUS\:.*//g')
if [ "$http_status" -ne 200 ]; then
echo "Request failed with status code $http_status"
exit 1
fi
current_state=$(echo $response_body | jq -r '.state')
if [ "$current_state" == "ACTIVE" ]; then
echo "Target is now ACTIVE."
exit 0
elif [ "$current_state" != "CREATE_IN_PROGRESS" ]; then
echo "Unexpected target state: $current_state."
exit 1
fi
attempts=$((attempts + 1))
echo "Waiting for target to be ACTIVE. Attempt $attempts/$max_attempts."
sleep $sleep_duration
done
echo "Target did not become active within the expected time."
exit 1