From 5b9931567c12dacd10819612f02dc6b8d03e925e Mon Sep 17 00:00:00 2001 From: Aaron Mauchley Date: Tue, 19 Sep 2023 08:48:14 -0600 Subject: [PATCH] Skms integration (#1288) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * Skms integration (#969) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * Skms integration (#972) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * Skms integration (#973) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * Skms integration (#974) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * Skms integration (#975) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * Skms integration (#976) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * Skms integration (#977) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * testing and debugging * Skms integration (#978) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * testing and debugging * testing new line removal testing new line removal * Skms integration (#980) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * testing and debugging * testing new line removal testing new line removal * gave back spacing gave back spacing * Skms integration (#981) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * testing and debugging * testing new line removal testing new line removal * gave back spacing gave back spacing * added comma delimited new lines added comma delimited new lines * Skms integration (#982) * SKMS CI integration start SKMS CI integration start * removed pull request flow removed pull request flow * changed branch for testing changed branch for testing * filled in the values for stage testing filled in the values for stage testing * temp stage pass temp stage pass * updated skms call updated skms call * Updated skms.yaml to pull request event changed event type to pull request, updated logic to only run when merged, added summary variable from github context. * cleaned up, formatted, updated condition cleaned up, formatted, updated condition so that if statement is not on shell but on github actions. * added missing curly brace added missing curly brace * fixing conflicts fixing conflicts * Fixing JSON Parsing Fixing JSON Parsing * fixing missing quotes, cleaned up summary fixing missing quotes, cleaned up summary * debugging JSON Parsing debugging JSON Parsing * debugging echos debugging echos * removing line breaks for JSON Parsing removing line breaks for JSON Parsing * testing and debugging * testing new line removal testing new line removal * gave back spacing gave back spacing * added comma delimited new lines added comma delimited new lines * adding spaces for new lines for JSON parser adding spaces for new lines for JSON parser * updated workflow name, branch list, api url updated workflow name, branch list, api url * Removed boiler plate comments Removed boiler plate comments * switched secrets to production ones switched secrets to production ones * testing int vs string testing int vs string since API requires int. * moved dependency check moved dependency check to separate job execution * moved curl call into a response wrapper moved curl call into a response wrapper * updated curl call wrapper updated curl call wrapper * small fix to wrapper again small fix to wrapper again * fixing failure for command fixing failure for command * testing curl write out * updating response output from curl updating response output from curl * more clear error messaging more clear error messaging * added exit status, fixed typo added exit status, fixed typo * added quote santization added quote sanitization * Fixing skms api call and removal of quotes Fixing skms api call and removal of quotes * parameter expansion pattern removal added parameter expansion pattern removal added * instead of removing we will be escaping quotes instead of removing we will be escaping quotes * remove quotes immediately remove quotes immediately * returned escaped quotes returned escaped quotes * added echo statements * updated url * added removal of single quote added removal of single quote * same * added sanitizeStr() added sanitizeStr() * added removal of tabs added removal of tabs * removed echo statements removed echo statements * added github action secret for two new variables added github action secret for change model id and change executor so those can be added dynamically for other teams and for changes in the future. * added back github.actor parameter added back github.actor parameter so that change executor is associated to workflow executors. * added single quotes around CL params added single quotes around CL params * removed accidental double single quotes removed accidental double single quotes * removed single quotes and escaped double quotes removed single quotes and escaped double quotes * second attempt second attempt * fixing quote escaping fixing quote escaping * switching to use jq switched to use jq to combine JSON for variables that require command line manipulation. * debug statements added for testing * added more debug statements * sending in workflow run values * concat release summary * updated separator for summary * added repo variable for change executor added repo variable for change executor * Using Github environment variables Using Github environment variables * created separate step for summary created separate step for summary * updated release parameter updated release parameter * attempting to fix multiline GitHub Env attempting to fix multiline GitHub Env * renamed delimiter renamed delimiter --- .github/workflows/skms.yaml | 127 ++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 .github/workflows/skms.yaml diff --git a/.github/workflows/skms.yaml b/.github/workflows/skms.yaml new file mode 100644 index 00000000000..d93e946eba3 --- /dev/null +++ b/.github/workflows/skms.yaml @@ -0,0 +1,127 @@ +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: 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=$(TZ=":America/Los_Angeles" date -d "+20 minutes" '+%Y-%m-%d %H:%M')" >> $GITHUB_ENV + echo "end_time=$(TZ=":America/Los_Angeles" date -d "+30 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//$'\r\n\t'/ }" + + 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<> "$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 + } + + echo "${{ env.release_summary }}" + + 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 }}"}'