Skip to content

Commit 99c7645

Browse files
authored
Adding pipelines scripts for setup & generation (#833)
* Adding pipeline setup scripts to SDKGenerator
1 parent acd0e1b commit 99c7645

File tree

11 files changed

+664
-3
lines changed

11 files changed

+664
-3
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# PlayFab files
2-
**/*[Tt]estTitleData.json*
32
**/beta_*.bat
43
**/beta_*.sh
54

JenkinsConsoleUtility/JenkinsScripts/gitFinalize.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
. "$WORKSPACE/JenkinsSdkSetupScripts/JenkinsScripts/Pipeline/util.sh" 2> /dev/null
4-
. "$WORKSPACE/JenkinsSdkSetupScripts/JenkinsScripts/Pipeline/sdkUtil.sh" 2> /dev/null
3+
. "$WORKSPACE/SdkGenerator/SetupScripts/util.sh" 2> /dev/null
4+
. "$WORKSPACE/SdkGenerator/SetupScripts/sdkUtil.sh" 2> /dev/null
55

66
CheckDefault PublishToS3 false
77

SetupScripts/SyncSdkRepoSubmodules.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# ----- git submodules check begin -----
5+
pushd "$WORKSPACE/sdks/$SdkName"
6+
if [ -f "set-gitmodules.bat" ]; then
7+
echo set-gitmodules.bat file detected, running it...
8+
cmd <<< "set-gitmodules.bat || exit 1"
9+
fi
10+
popd
11+
# ----- git submodules check end -----

SetupScripts/sdkUtil.sh

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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

SetupScripts/testInit.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# USAGE: testInit.sh
5+
6+
if [ -f "util.sh" ]; then
7+
. "./util.sh" 2> /dev/null
8+
. "./sdkUtil.sh" 2> /dev/null
9+
elif [ ! -z "$WORKSPACE" ]; then
10+
. "$WORKSPACE/SdkGenerator/SetupScripts/util.sh" 2> /dev/null
11+
. "$WORKSPACE/SdkGenerator/SetupScripts/sdkUtil.sh" 2> /dev/null
12+
fi
13+
14+
CheckVerticalizedParameters
15+
16+
DoJcuNugetUpdate () {
17+
DoesCommandExist nuget || return 1
18+
19+
pushd "$WORKSPACE/SDKGenerator/JenkinsConsoleUtility"
20+
nuget restore JenkinsConsoleUtility.sln
21+
popd
22+
}
23+
24+
# USAGE: ResetRepo
25+
ResetRepo () {
26+
echo === ResetRepo $PWD, $@ ===
27+
28+
# Assumes the current directory is set to the repo to be reset
29+
CheckCreds
30+
git fetch --progress origin
31+
git checkout master || git checkout -b master || CleanCurrentRepo
32+
git pull origin master
33+
34+
# Delete $GitDestBranch, reset it to master, prep for next build and fresh write
35+
if [ "$GitDestBranch"!="master" ]; then
36+
git branch -D $GitDestBranch || true
37+
git checkout -b $GitDestBranch || true
38+
git checkout $GitDestBranch
39+
fi
40+
}
41+
42+
# USAGE: DoWork
43+
DoWork () {
44+
echo == DoWork $PWD, $@ ==
45+
46+
SyncGitHubRepo "$WORKSPACE" "SDKGenerator" "SDKGenerator" "$GitSdkGenBranch"
47+
DoJcuNugetUpdate || echo "Failed to Nuget restore JenkinsConsoleUtility"
48+
49+
SyncGitHubRepo "$WORKSPACE/sdks" "$SdkName" "$SdkName" "$GitSdkDestBranch"
50+
SyncGitHubRepo "$WORKSPACE" "API_Specs"
51+
52+
if [ ! -z "$SdkGenPrvTmplRepo" ]; then
53+
SyncGitHubRepo "$WORKSPACE/SDKGenerator/privateTemplates" "$SdkGenPrvTmplRepo" "$SdkGenPrvTmplRepo" "$GitPrvTmplBranch"
54+
fi
55+
56+
ForcePushD "$WORKSPACE/sdks/$SdkName"
57+
#ResetRepo
58+
}
59+
60+
echo === Beginning testInit ===
61+
DoWork "$@"

SetupScripts/testTitleData.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"titleId": "6195",
3+
"developerSecretKey": "",
4+
"aliasId": "",
5+
"userEmail": "[email protected]",
6+
"connectionString": "https://6195.playfabapi.com"
7+
}

SetupScripts/unityTestTitleData.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"titleId": "18C0",
3+
"developerSecretKey": "",
4+
"userEmail": "[email protected]",
5+
"pubSubTitleId": "36C8",
6+
"matchmakingPubSubTitleId": "F1005285",
7+
"matchmakingPubSubVerticalName": "matchmaking.matchmaking"
8+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ -f "util.sh" ]; then
5+
. "./sdkUtil.sh" 2> /dev/null
6+
elif [ ! -z "$WORKSPACE" ]; then
7+
. "$WORKSPACE/SdkGenerator/SetupScripts/sdkUtil.sh" 2> /dev/null
8+
fi
9+
10+
CopyTestTitleDataToUnity() {
11+
CheckDefaultTitleDataLocation Unity
12+
echo === CopyTestTitleDataToUnity ===
13+
# If not defined, grab the default PF_TEST_TITLE_DATA_JSON file (for Unity)
14+
targetPathMain="${WORKSPACE}/sdks/${SdkName}/ExampleTestProject/Assets/Testing/Resources"
15+
targetPathMac="${WORKSPACE}/sdks/${SdkName}/ExampleMacProject/Assets/Testing/Resources"
16+
if [ ! -d "$targetPathMain" ]; then
17+
mkdir -p "$targetPathMain"
18+
fi
19+
if [ ! -d "$targetPathMac" ]; then
20+
mkdir -p "$targetPathMac"
21+
fi
22+
cp -T "$PF_TEST_TITLE_DATA_JSON" "$targetPathMain/testTitleData.json" || cp "$PF_TEST_TITLE_DATA_JSON" "$targetPathMain/testTitleData.json"
23+
cp -T "$PF_TEST_TITLE_DATA_JSON" "$targetPathMac/testTitleData.json" || cp "$PF_TEST_TITLE_DATA_JSON" "$targetPathMac/testTitleData.json"
24+
}
25+
26+
DeleteTestTitleDataFromUnity() {
27+
CheckDefaultTitleDataLocation Unity
28+
echo === DeleteTestTitleDataFromUnity ===
29+
targetPathMain="${WORKSPACE}/sdks/${SdkName}/ExampleTestProject/Assets/Testing/Resources"
30+
targetPathMac="${WORKSPACE}/sdks/${SdkName}/ExampleMacProject/Assets/Testing/Resources"
31+
rm "$targetPathMain/testTitleData.json"
32+
rm "$targetPathMac/testTitleData.json"
33+
}

0 commit comments

Comments
 (0)