Skms integration #49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create CMR in SKMS | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- skms-release-test | |
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@v3 | |
# Runs a single command using the runners shell for shell validation | |
- name: Run a one-line script | |
run: echo Starting CMR Action... | |
# Validate dependencies before continuing CMR creation | |
- 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" | |
# Run command for creating CMR in SKMS system | |
- run: | | |
start_date=$(TZ=":America/Los_Angeles" date -d "5 minutes ago" '+%Y-%m-%d %H:%M') | |
DEFAULT_SKMS_URL='api.skms.adobe.com' | |
function skms_request() { | |
local username=$1 | |
local passkey=$2 | |
local object=$3 | |
local method=$4 | |
local mw_start_time=$5 | |
local mw_end_time=$6 | |
local change_summary=$7 | |
local method_params=$8 | |
local url=$9 | |
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 "$mw_start_time" ]; then | |
echo "Fifth parameter missing, must be a formatted datetime" | |
return 1 | |
fi | |
if [ -z "$mw_end_time" ]; then | |
echo "Sixth parameter missing, must be a formatted datetime" | |
return 1 | |
fi | |
if [ -z "$change_summary" ]; then | |
echo "Seventh parameter missing, must be a SKMS summary text" | |
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}\",\"maintenance_window_start_time\":\"${mw_start_time}\",\"maintenance_window_end_time\":\"${mw_end_time}\",\"summary\":\"${change_summary}\"}" | |
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 | |
} | |
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//$'\r\n\t'/ }" | |
echo "$str" | |
} | |
end_date=$(TZ=":America/Los_Angeles" date '+%Y-%m-%d %H:%M') | |
release_title=$(sanitizeStr "${{ github.event.pull_request.title }}") | |
release_details=$(sanitizeStr "${{ github.event.pull_request.body }}") | |
summary=Release_Title-"$release_title"--"$release_details"--PR_Number-"${{ github.event.pull_request.number }}"--PR_Created_At-"${{ github.event.pull_request.created_at }}"--PR_Merged_At-"${{ github.event.pull_request.merged_at }}" | |
echo "$start_date" | |
echo "$end_date" | |
echo "$summary" | |
skms_request '${{ secrets.SKMS_USER }}' '${{ secrets.SKMS_PASS }}' CmrDao createCmrFromPreapprovedChangeModel '${start_date}' '${end_date}' '${summary}' '{"change_executor":"${{ github.actor }}","preapproved_change_model_id":"${{ secrets.SKMS_CHANGE_MODEL_ID }}"}' |