github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/infrastructure/scripts/create-testdata/create-release.sh (about)

     1  #!/bin/bash
     2  set -eu
     3  set -o pipefail
     4  
     5  # usage
     6  # ./create-release.sh my-service-name [my-team-name]
     7  # Note that this just creates files, it doesn't push in git
     8  
     9  name=${1}
    10  applicationOwnerTeam=${2:-sreteam}
    11  prev=${3:-""}
    12  
    13  # 40 is the length of a full git commit hash.
    14  commit_id=$(LC_CTYPE=C tr -dc a-f0-9 </dev/urandom | head -c 40 ; echo '')
    15  authors[0]="urbansky"
    16  authors[1]="Medo"
    17  authors[2]="Hannes"
    18  authors[3]="Mouhsen"
    19  authors[4]="Tamer"
    20  authors[5]="Ahmed"
    21  authors[6]="João"
    22  authors[7]="Leandro"
    23  sizeAuthors=${#authors[@]}
    24  index=$(($RANDOM % $sizeAuthors))
    25  echo ${authors[$index]}
    26  author="${authors[$index]}"
    27  commit_message_file="$(mktemp "${TMPDIR:-/tmp}/publish.XXXXXX")"
    28  trap "rm -f ""$commit_message_file" INT TERM HUP EXIT
    29  displayVersion=
    30  if ((RANDOM % 2)); then
    31    displayVersion=$(( $RANDOM % 100)).$(( $RANDOM % 100)).$(( $RANDOM % 100))
    32  fi
    33  
    34  msgs[0]="Added new eslint rule"
    35  msgs[1]="Fix annotations in helm templates"
    36  msgs[2]="Improve performance with gitLib2"
    37  msgs[3]="Add colors to new UI"
    38  msgs[4]="Release trains for env groups"
    39  msgs[5]="Fix whitespace in ReleaseDialog"
    40  msgs[6]="Add Snackbar Notifications"
    41  msgs[7]="Rephrase ReleaseDialog text"
    42  msgs[8]="Change renovate schedule"
    43  msgs[9]="Fix bug in distanceToUpstream calculation"
    44  msgs[10]="Allow deleting locks on locks page"
    45  sizeMsgs=${#msgs[@]}
    46  index=$(($RANDOM % $sizeMsgs))
    47  echo $index
    48  echo -e "${msgs[$index]}\n" > "${commit_message_file}"
    49  echo "1: ${msgs[$index]}" >> "${commit_message_file}"
    50  echo "2: ${msgs[$index]}" >> "${commit_message_file}"
    51  
    52  ls "${commit_message_file}"
    53  
    54  release_version=''
    55  case "${RELEASE_VERSION:-}" in
    56  	'') echo "No RELEASE_VERSION set. Using non-idempotent versioning scheme";;
    57  	*[!0-9]*) echo "Please set the env variable RELEASE_VERSION to a number"; exit 1;;
    58  	*) release_version='--form-string '"version=${RELEASE_VERSION:-}";;
    59  esac
    60  
    61  echo "release version:" "${release_version}"
    62  
    63  configuration=()
    64  configuration+=("--form" "team=${applicationOwnerTeam}")
    65  
    66  manifests=()
    67  for env in development development2 staging fakeprod-de fakeprod-ca
    68  do
    69    file=$(mktemp "${TMPDIR:-/tmp}/$env.XXXXXX")
    70    signatureFile=$(mktemp "${TMPDIR:-/tmp}/$env.XXXXXX")
    71    randomValue=$(LC_CTYPE=C tr -dc a-f0-9 </dev/urandom | head -c 12 ; echo '')
    72  cat <<EOF > "${file}"
    73  ---
    74  apiVersion: v1
    75  kind: ConfigMap
    76  metadata:
    77    name: $name-dummy-config-map
    78    namespace: "$env"
    79  data:
    80    key: value
    81    random: "${randomValue}"
    82  ---
    83  EOF
    84    echo "wrote file ${file}"
    85    manifests+=("--form" "manifests[${env}]=@${file}")
    86    gpg  --keyring trustedkeys-kuberpult.gpg --local-user kuberpult-kind@example.com --detach --sign --armor < "${file}" > "${signatureFile}"
    87    manifests+=("--form" "signatures[${env}]=@${signatureFile}")
    88  done
    89  echo commit id: "${commit_id}"
    90  
    91  FRONTEND_PORT=8081 # see docker-compose.yml
    92  
    93  if [[ $(uname -o) == Darwin ]];
    94  then
    95    EMAIL=$(echo -n "script-user@example.com" | base64 -b 0)
    96    AUTHOR=$(echo -n "script-user" | base64 -b 0)
    97  else
    98    EMAIL=$(echo -n "script-user@example.com" | base64 -w 0)
    99    AUTHOR=$(echo -n "script-user" | base64 -w 0)
   100  fi
   101  
   102  inputs=()
   103  inputs+=(--form-string "application=$name")
   104  inputs+=(--form-string "source_commit_id=$commit_id")
   105  inputs+=(--form-string "source_author=$author")
   106  
   107  if [ "$prev" != "" ];
   108  then
   109    inputs+=(--form-string "previous_commit_id=${prev}")
   110  fi
   111  
   112  curl http://localhost:${FRONTEND_PORT}/release \
   113    -H "author-email:${EMAIL}" \
   114    -H "author-name:${AUTHOR}=" \
   115    "${inputs[@]}" \
   116    ${release_version} \
   117    --form-string "display_version=${displayVersion}" \
   118    --form "source_message=<${commit_message_file}" \
   119    "${configuration[@]}" \
   120    "${manifests[@]}" -v
   121  
   122  echo # curl sometimes does not print a trailing \n