forked from adobecom/milo
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (104 loc) · 4.41 KB
/
skms.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Create CMR in SKMS
on:
pull_request:
types:
- closed
branches:
- main
jobs:
create-cmr:
# Only run this workflow on pull requests that have merged and not manually closed by user
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Runs a single command using the runners shell for shell validation
- name: Validate Shell
run: echo Starting CMR Action...
- name: Check Dependencies
run: |
if ! type "jq" >/dev/null; then
echo "jq is required but not installed"
exit 1
fi
if ! type "curl" >/dev/null; then
echo "curl is required but not installed"
exit 1
fi
echo "Dependencies check was successful"
- name: Set Maintenance Time Windows for CMR
run: |
echo "start_time=$(date -d "+60 minutes" '+%Y-%m-%d %H:%M')" >> $GITHUB_ENV
echo "end_time=$(date -d "+90 minutes" '+%Y-%m-%d %H:%M')" >> $GITHUB_ENV
- name: Set Release Summary for CMR
run: |
function sanitizeStr() {
local str=$1
if [ -z "$str" ]; then
echo "First parameter missing, must be a valid string"
return 1
fi
str="${str//\"/""}"
str="${str//\'/""}"
str="${str//(/"["}"
str="${str//)/"]"}"
str="${str//$'\r'/"\r"}"
str="${str//$'\n'/"\n"}"
str="${str//$'\t'/"\t"}"
str="${str//\\//}"
str="${str////"\/"}"
echo "$str"
}
release_title=$(sanitizeStr "${{ github.event.pull_request.title }}")
release_details=$(sanitizeStr "${{ github.event.pull_request.body }}")
release=Release_Title--"${release_title}"--Release_Details--"${release_details}"--Pull_Request_Number--"${{ github.event.pull_request.number }}"--Pull_Request_Created_At--"${{ github.event.pull_request.created_at }}"--Pull_Request_Merged_At--"${{ github.event.pull_request.merged_at }}"
echo "release_summary<<RS_EOF" >> $GITHUB_ENV
echo "$release" >> $GITHUB_ENV
echo "RS_EOF" >> $GITHUB_ENV
- name: Create CMR in SKMS
run: |
DEFAULT_SKMS_URL='api.skms.adobe.com'
function skms_request() {
local username=$1
local passkey=$2
local object=$3
local method=$4
local method_params=$5
local url=$6
if [ -z "$username" ]; then
echo "First parameter missing, must be SKMS username"
return 1
fi
if [ -z "$passkey" ]; then
echo "Second parameter missing, must be SKMS passkey"
return 1
fi
if [ -z "$object" ]; then
echo "Third parameter missing, must be an SKMS dao object"
return 1
fi
if [ -z "$method" ]; then
echo "Fourth parameter missing, must be SKMS dao method"
return 1
fi
if [ -z "$method_params" ]; then
method_params='{}'
fi
if [ -z "$url" ]; then
url=$DEFAULT_SKMS_URL
fi
local params="{\"_username\":\"${username}\",\"_passkey\":\"${passkey}\",\"_object\":\"${object}\",\"_method\": \"${method}\"}"
params=$(echo "$params $method_params" | jq -s add)
local response=$(curl --write-out "%{http_code}" --silent --output response.txt https://${url}/web_api --data-urlencode "_parameters=${params}")
if [ $response != "200" ]; then
echo "CURL call returned HTTP status code: $response"
exit 1
elif grep -q "\"status\":\"error\"" response.txt; then
echo "CMR creation failed with response: "
cat response.txt
exit 1
else
echo "CMR creation was successful"
fi
}
skms_request '${{ secrets.SKMS_USER }}' '${{ secrets.SKMS_PASS }}' CmrDao createCmrFromPreapprovedChangeModel '{"change_executor":"${{ secrets.SKMS_CHANGE_EXECUTOR }}","maintenance_window_end_time":"${{ env.end_time }}","maintenance_window_start_time":"${{ env.start_time }}","preapproved_change_model_id":"${{ secrets.SKMS_CHANGE_MODEL_ID }}","summary":"${{ env.release_summary }}"}'