|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# USAGE: . ./sdkUtil.sh |
| 5 | +# Includes a bunch of sdk-specific functions shared by other scripts |
| 6 | + |
| 7 | +if [ -f "util.sh" ]; then |
| 8 | + . "./util.sh" 2> /dev/null |
| 9 | +elif [ ! -z "$WORKSPACE" ]; then |
| 10 | + . "$WORKSPACE/SdkGenerator/SetupScripts/util.sh" 2> /dev/null |
| 11 | +fi |
| 12 | + |
| 13 | +FailIfPublishing() { |
| 14 | + echo $1 |
| 15 | + if [ "$GitDestBranch" != "doNotCommit" ]; then |
| 16 | + return 1 # We cannot commit to this branch name |
| 17 | + else |
| 18 | + echo " .. but it is ok, because we will not commit to that branch" |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +# Invalid branch names and reasonings: |
| 23 | +# "invalid": a default-placeholder so that people do not do builds without making a choice |
| 24 | +# "automated": the old branch name, and we want to make a clean break from it (and debug any leftover problems) |
| 25 | +# "master": we never want to commit directly to master, ever, for any reason |
| 26 | +# "versioned": we never want to commit directly to versioned, ever, for any reason |
| 27 | +# |
| 28 | +# $GitDestBranch == "doNotCommit" ignores restrictions, because it will still use "doNotCommit" for the local machine build, but will not commit to it, so it is safe |
| 29 | +# Verticalized builds prepend with "vertical-", so edge-case vertical names cannot clobber a branch we want to protect |
| 30 | +CheckVerticalizedParameters() { |
| 31 | + # Typical builds will meet none of these conditions, and this function will have no effect |
| 32 | + if [ -z "$GitDestBranch" ] || [ "$GitDestBranch" = "invalid" ] || [ "$GitDestBranch" = "master" ] || [ "$GitDestBranch" = "versioned" ] || [ "$GitDestBranch" = "automated" ]; then |
| 33 | + FailIfPublishing "INVALID GitDestBranch: ($GitDestBranch, $VerticalName)" |
| 34 | + elif [ "$GitDestBranch" = "verticalName" ]; then |
| 35 | + if [ -z "$VerticalName" ]; then |
| 36 | + FailIfPublishing "INVALID GitDestBranch, cannot be assigned to VerticalName: ($GitDestBranch, $VerticalName)" |
| 37 | + else |
| 38 | + # This is the expected-correct path for verticalized-builds |
| 39 | + GitDestBranch="vertical-$VerticalName" |
| 40 | + fi |
| 41 | + fi |
| 42 | + if [ "$VerticalName" = "master" ]; then |
| 43 | + echo "VerticalName = master, should not be manually specified, it's implied. (A lot of stuff will break if master is explicit)" |
| 44 | + return 1 # We want to fail this case, regardless of publish state |
| 45 | + elif [ ! -z "$VerticalName" ]; then |
| 46 | + if [ "$GitDestBranch" != "vertical-$VerticalName" ]; then |
| 47 | + FailIfPublishing "Output branch must be verticalName when building a vertical" |
| 48 | + elif [ "$ApiSpecSource" != "-apiSpecPfUrl" ] && [ "$ApiSpecSource" != "-apiSpecPfUrl https://${VerticalName}.playfabapi.com/apispec" ]; then |
| 49 | + echo "ApiSpecSource must be -apiSpecPfUrl when building a vertical, or else it won't build what you expect" |
| 50 | + return 1 |
| 51 | + fi |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +CheckApiSpecSourceDefault() { |
| 56 | + if [ -z "$ApiSpecSource" ]; then |
| 57 | + ApiSpecSource="-apiSpecGitUrl" |
| 58 | + fi |
| 59 | + # TODO: Update with ClusterName |
| 60 | + # if [ "$ApiSpecSource" = "-apiSpecPfUrl" ] && [ ! -z "$VerticalName" ]; then |
| 61 | + # ApiSpecSource="-apiSpecPfUrl https://${VerticalName}.playfabapi.com/apispec" |
| 62 | + # fi |
| 63 | +} |
| 64 | + |
| 65 | +CheckBuildIdentifierDefault() { |
| 66 | + echo CheckBuildIdentifierDefault $NODE_NAME $EXECUTOR_NUMBER $AGENT_ID |
| 67 | + if [ -z "$buildIdentifier" ] && [ ! -z "$SdkName" ] && [ ! -z "$NODE_NAME" ] && [ ! -z "$EXECUTOR_NUMBER" ]; then |
| 68 | + buildIdentifier="JBuild_${SdkName}_${NODE_NAME}_${EXECUTOR_NUMBER}" |
| 69 | + elif [ -z "$buildIdentifier" ] && [ ! -z "$SdkName" ] && [ ! -z "$AdoBuildId" ]; then |
| 70 | + # When we manually define AdoBuildId, this is the more reliable way to determine a unique build (Multi-machine builds) |
| 71 | + buildIdentifier="AdoBuild_${SdkName}_${AdoBuildId}" |
| 72 | + elif [ -z "$buildIdentifier" ] && [ ! -z "$SdkName" ] && [ ! -z "$AGENT_ID" ]; then |
| 73 | + # When we do not have AdoBuildId, we use the machine ID in order to determine uniqueness (Single-machine builds) |
| 74 | + buildIdentifier="AdoBuild_${SdkName}_${AGENT_ID}" |
| 75 | + elif [ -z "$buildIdentifier" ]; then |
| 76 | + buildIdentifier="Custom_${SdkName}" |
| 77 | + fi |
| 78 | +} |
| 79 | + |
| 80 | +BuildJCU() { |
| 81 | + Find2019MsBuild || Find2017MsBuild |
| 82 | + |
| 83 | + pushd "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility" |
| 84 | + nuget restore JenkinsConsoleUtility.sln |
| 85 | + # Escape windows style "slash commands" so bash doesn't try to convert them to paths |
| 86 | + # Mac needs "msbuild" without the .exe |
| 87 | + "$MSBUILD_EXE" JenkinsConsoleUtility.csproj //p:configuration="Debug" //p:platform="AnyCPU" || \ |
| 88 | + cmd <<< "\"$MSBUILD_EXE\" JenkinsConsoleUtility.csproj /p:configuration=\"Debug\" /p:platform=\"AnyCPU\" || exit 1" |
| 89 | + popd |
| 90 | +} |
| 91 | +
|
| 92 | +# USAGE: _CallJcuBash <JenkinsConsoleUtility arguments> |
| 93 | +_CallJcuBash() { |
| 94 | + pushd "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility/bin/Debug" |
| 95 | + # KNOWN: Execute "permission denied" on a Mac gives error code 1 |
| 96 | + # KNOWN: "cannot execute binary file" on a Mac gives error code 126 |
| 97 | + chmod +x JenkinsConsoleUtility.exe |
| 98 | + ./JenkinsConsoleUtility.exe ${@:1} |
| 99 | + tempErr=$? |
| 100 | + if [ "$tempErr" -ne "0" ]; then |
| 101 | + echo "Bash JenkinsConsoleUtility exec failed with error: $tempErr" |
| 102 | + fi |
| 103 | + popd |
| 104 | + return $tempErr |
| 105 | +} |
| 106 | +
|
| 107 | +# USAGE: _CallJcuMono <JenkinsConsoleUtility arguments> |
| 108 | +_CallJcuMono() { |
| 109 | + pushd "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility/bin/Debug" |
| 110 | + # KNOWN: if "mono" command doesn't exist, then the error code is 127 |
| 111 | + mono JenkinsConsoleUtility.exe ${@:1} |
| 112 | + tempErr=$? |
| 113 | + if [ "$tempErr" -ne "0" ]; then |
| 114 | + echo "Bash JenkinsConsoleUtility exec failed with error: $tempErr" |
| 115 | + fi |
| 116 | + popd |
| 117 | + return $tempErr |
| 118 | +} |
| 119 | +
|
| 120 | +# USAGE: _CallJcuCmd <JenkinsConsoleUtility arguments> |
| 121 | +_CallJcuCmd() { |
| 122 | + pushd "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility/bin/Debug" |
| 123 | + cmd <<< "JenkinsConsoleUtility.exe ${@:1} || exit 1" |
| 124 | + tempErr=$? |
| 125 | + if [ "$tempErr" -ne "0" ]; then |
| 126 | + echo "Cmd JenkinsConsoleUtility exec failed with error: $tempErr" |
| 127 | + fi |
| 128 | + popd |
| 129 | + return $tempErr |
| 130 | +} |
| 131 | +
|
| 132 | +# USAGE: CallJCU <JenkinsConsoleUtility arguments> |
| 133 | +CallJCU() { |
| 134 | + echo === Call JCU: ${@:1} === |
| 135 | + |
| 136 | + if [ ! -d "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility/bin/Debug" ]; then |
| 137 | + BuildJCU |
| 138 | + fi |
| 139 | +
|
| 140 | + _CallJcuBash ${@:1} || tempErr=$? |
| 141 | + # An error code of 1 probably means it actually called JCU and could not get results |
| 142 | + if [ "$tempErr" -eq "0" ] || [ "$tempErr" -eq "1" ]; then |
| 143 | + return $tempErr |
| 144 | + fi |
| 145 | + _CallJcuMono ${@:1} || tempErr=$? |
| 146 | + # An error code of 1 probably means it actually called JCU and could not get results |
| 147 | + if [ "$tempErr" -eq "0" ] || [ "$tempErr" -eq "1" ]; then |
| 148 | + return $tempErr |
| 149 | + fi |
| 150 | + _CallJcuCmd ${@:1} |
| 151 | +} |
| 152 | +
|
| 153 | +CheckDefaultTitleDataLocation() { |
| 154 | + if [ -z "$PF_TEST_TITLE_DATA_JSON" ]; then |
| 155 | + if [ "$1" == "Unity" ]; then |
| 156 | + PF_TEST_TITLE_DATA_JSON="$WORKSPACE/SdkGenerator/SetupScripts/unityTestTitleData.json" |
| 157 | + else |
| 158 | + PF_TEST_TITLE_DATA_JSON="$WORKSPACE/SdkGenerator/SetupScripts/testTitleData.json" |
| 159 | + fi |
| 160 | + fi |
| 161 | + if [ ! -f "$PF_TEST_TITLE_DATA_JSON" ]; then |
| 162 | + echo === PF_TEST_TITLE_DATA_JSON is not a valid file location: $PF_TEST_TITLE_DATA_JSON |
| 163 | + return 1 |
| 164 | + fi |
| 165 | + export PF_TEST_TITLE_DATA_JSON=$PF_TEST_TITLE_DATA_JSON |
| 166 | +} |
| 167 | +
|
| 168 | +ListenCsJCU() { |
| 169 | + echo === Retrieve $SdkName UnitTest results === |
| 170 | + CheckBuildIdentifierDefault |
| 171 | + CheckDefaultTitleDataLocation |
| 172 | + CallJCU --listencs -buildIdentifier $buildIdentifier -workspacePath "$WORKSPACE" -timeout 60 -verbose true |
| 173 | + if [ ! -z "$killTaskName" ]; then |
| 174 | + CallJCU --kill -taskname $killTaskName |
| 175 | + fi |
| 176 | +} |
| 177 | +
|
| 178 | +SyncSdkRepoSubmodules() { |
| 179 | + # ----- git submodules check begin ----- |
| 180 | + pushd "$WORKSPACE/sdks/$SdkName" |
| 181 | + if [ -f "set-gitmodules.sh" ]; then |
| 182 | + echo set-gitmodules.sh file detected, running it... |
| 183 | + . ./set-gitmodules.sh |
| 184 | + elif [ -f "set-gitmodules.bat" ]; then |
| 185 | + echo set-gitmodules.bat file detected, running it... |
| 186 | + cmd <<< "set-gitmodules.bat || return 1" |
| 187 | + fi |
| 188 | + popd |
| 189 | + # ----- git submodules check end ----- |
| 190 | +} |
| 191 | +
|
| 192 | +echo sdkUtil.sh loaded |
0 commit comments