Skip to content

Commit 819503e

Browse files
author
Duco van Amstel
authored
Consolidate scripts (#31)
1 parent c350a99 commit 819503e

File tree

11 files changed

+266
-68
lines changed

11 files changed

+266
-68
lines changed

.buildkite/nightly.steps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ common: &common
1616
- "environment=production"
1717
- "permission_set=builder"
1818
- "platform=linux"
19-
- "queue=${CI_BUILDER_QUEUE:-v2-1553093147-c5086c3db10e3761-------z}"
19+
- "queue=${CI_BUILDER_QUEUE:-v3-1558960120-4a170e85e982b36f-------z}"
2020
timeout_in_minutes: 60 # TODO(ENG-548): reduce timeout once agent-cold-start is optimised.
2121
retry:
2222
automatic:

.buildkite/premerge.definition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
agent_queue_id: trigger-pipelines
2-
description: Add a description...
2+
description: The premerge steps to run for Platform SDK pull-requests.
33
github:
44
branch_configuration: []
55
default_branch: master

.buildkite/premerge.steps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ common: &common
1616
- "environment=production"
1717
- "permission_set=builder"
1818
- "platform=linux"
19-
- "queue=${CI_BUILDER_QUEUE:-v2-1553093147-c5086c3db10e3761-------z}"
19+
- "queue=${CI_BUILDER_QUEUE:-v3-1558960120-4a170e85e982b36f-------z}"
2020
timeout_in_minutes: 60 # TODO(ENG-548): reduce timeout once agent-cold-start is optimised.
2121
retry:
2222
automatic:

scripts/generateapis.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -e -u -x -o pipefail
44

5-
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
5+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6+
cd "${REPO_ROOT}"
7+
8+
source scripts/includes/bazel.sh
69

710
generate_api() {
8-
NAME=$1
9-
VERSION=$2
10-
PACKAGE=apis/${NAME}_${VERSION}
11+
NAME="$1"
12+
VERSION="$2"
13+
PACKAGE="apis/${NAME}_${VERSION}"
1114

12-
bazel build //$PACKAGE:gapic
13-
bazel build //$PACKAGE:grpc
14-
rm -rf $PACKAGE/*.cs
15-
cp -R $REPO_ROOT/bazel-genfiles/$PACKAGE/${NAME}_gapicout/*/*/*.cs $REPO_ROOT/$PACKAGE
16-
cp -R $REPO_ROOT/bazel-genfiles/$PACKAGE/*.cs $REPO_ROOT/$PACKAGE
15+
runBazel build "//${PACKAGE}:gapic"
16+
runBazel build "//${PACKAGE}:grpc"
17+
rm -rf ${PACKAGE}/*.cs
18+
copyBazelOutput "bazel-genfiles/${PACKAGE}/${NAME}_gapicout/*/*/*.cs" "${REPO_ROOT}/${PACKAGE}"
19+
copyBazelOutput "bazel-genfiles/${PACKAGE}/*.cs" "${REPO_ROOT}/${PACKAGE}"
1720
}
1821

19-
generate_api 'deployment' 'v1alpha1'
20-
generate_api 'snapshot' 'v1alpha1'
21-
generate_api 'serviceaccount' 'v1alpha1'
22-
generate_api 'playerauth' 'v2alpha1'
22+
generate_api "deployment" "v1alpha1"
23+
generate_api "snapshot" "v1alpha1"
24+
generate_api "serviceaccount" "v1alpha1"
25+
generate_api "playerauth" "v2alpha1"

scripts/includes/bazel.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
source scripts/includes/os.sh
4+
5+
if isLinux; then
6+
DEFAULT_BAZEL_CONFIG="k8-gcc-opt"
7+
elif isMacOS; then
8+
DEFAULT_BAZEL_CONFIG="darwin-opt-clang"
9+
else
10+
DEFAULT_BAZEL_CONFIG="x64_windows-opt-msvc_md"
11+
fi
12+
13+
# By convention bazel config's names are identical to their output folder names.
14+
DEFAULT_BAZEL_OUT="bazel-out/${DEFAULT_BAZEL_CONFIG}"
15+
DEFAULT_BAZEL_BIN="${DEFAULT_BAZEL_OUT}/bin"
16+
17+
# Main function that should be used by scripts sourcing this file.
18+
function runBazel() {
19+
"$(pwd)/tools/bazel" "$@"
20+
}
21+
22+
function copyBazelOutput() {
23+
cp -Rf "$1" "$2"
24+
chmod +w "$2"
25+
}

scripts/includes/os.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
function isLinux() {
4+
[[ "$(uname -s)" == "Linux" ]];
5+
}
6+
7+
function isMacOS() {
8+
[[ "$(uname -s)" == "Darwin" ]];
9+
}
10+
11+
function isWindows() {
12+
! ( isLinux || isMacOS );
13+
}
14+
15+
# Return the target platform used by worker package names built for this OS.
16+
function getPlatformName() {
17+
if isLinux; then
18+
echo "linux"
19+
elif isMacOS; then
20+
echo "macos"
21+
elif isWindows; then
22+
echo "win32"
23+
else
24+
echo "ERROR: Unknown platform." >&2
25+
exit 1
26+
fi
27+
}

scripts/nightly.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
3+
set -e -u -o pipefail
44

5-
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
6-
SDK_VERSION_NIGHTLY=999.9.9-NIGHTLY
7-
DOCKER_IMAGE=platform-sdk/csharp:$SDK_VERSION_NIGHTLY
5+
REPO_ROOT="$(dirname "$0")/.."
6+
cd "${REPO_ROOT}"
87

9-
if [[ -z ${IMPROBABLE_REFRESH_TOKEN+x} ]];
10-
then
8+
SDK_VERSION_NIGHTLY="999.9.9-NIGHTLY"
9+
DOCKER_IMAGE="platform-sdk/csharp:${SDK_VERSION_NIGHTLY}"
10+
11+
if [[ -z "${IMPROBABLE_REFRESH_TOKEN+x}" ]];
12+
then
1113
echo "IMPROBABLE_REFRESH_TOKEN is unset."
1214
echo "Trying to retrieve from vaults."
13-
IMPROBABLE_REFRESH_TOKEN="$(imp-ci secrets read --environment=production --buildkite-org=improbable --secret-type=spatialos-service-account --secret-name=platform-sdk --field=token)"
15+
IMPROBABLE_REFRESH_TOKEN="$(imp-ci secrets read \
16+
--environment=production \
17+
--buildkite-org=improbable \
18+
--secret-type=spatialos-sevice-account \
19+
--secret-name=platform-sdk \
20+
--field=token
21+
)"
1422
fi
1523

16-
echo "--- regenerating APIs"
17-
echo "skipping until bazel is available on the agent"
18-
# $REPO_ROOT/scripts/generateapis.sh
24+
echo "--- Regenerating APIs"
25+
echo "Skipping until bazel is available on the agent"
26+
# scripts/generateapis.sh
1927

2028
echo "--- Preparing docker image for nightly"
21-
docker build --build-arg IMPROBABLE_REFRESH_TOKEN=$IMPROBABLE_REFRESH_TOKEN --build-arg SDK_VERSION=$SDK_VERSION_NIGHTLY -t $DOCKER_IMAGE $REPO_ROOT
29+
docker build \
30+
--build-arg "IMPROBABLE_REFRESH_TOKEN=${IMPROBABLE_REFRESH_TOKEN}" \
31+
--build-arg "SDK_VERSION=${SDK_VERSION_NIGHTLY}" \
32+
--tag "${DOCKER_IMAGE}" \
33+
"${REPO_ROOT}"
2234

2335
echo "--- Running scenarios in docker"
24-
$REPO_ROOT/scripts/runtests.sh $DOCKER_IMAGE
36+
scripts/runtests.sh "${DOCKER_IMAGE}"
37+

scripts/premerge.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
3+
set -e -u -o pipefail
44

5-
if [[ -z ${IMPROBABLE_REFRESH_TOKEN+x} ]];
5+
REPO_ROOT="$(dirname "$0")/.."
6+
cd "${REPO_ROOT}"
7+
8+
SDK_VERSION_PREMERGE="888.8.8-PREMERGE"
9+
DOCKER_IMAGE="platform-sdk/csharp:${SDK_VERSION_PREMERGE}"
10+
11+
if [[ -z "${IMPROBABLE_REFRESH_TOKEN+x}" ]];
612
then
713
echo "IMPROBABLE_REFRESH_TOKEN is unset."
814
echo "Trying to retrieve from vaults."
9-
IMPROBABLE_REFRESH_TOKEN="$(imp-ci secrets read --environment=production --buildkite-org=improbable --secret-type=spatialos-service-account --secret-name=platform-sdk --field=token)"
15+
IMPROBABLE_REFRESH_TOKEN="$(imp-ci secrets read \
16+
--environment=production \
17+
--buildkite-org=improbable \
18+
--secret-type=spatialos-service-account \
19+
--secret-name=platform-sdk \
20+
--field=token
21+
)"
1022
fi
1123

12-
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
13-
SDK_VERSION_PREMERGE=888.8.8-PREMERGE
14-
DOCKER_IMAGE=platform-sdk/csharp:$SDK_VERSION_PREMERGE
15-
16-
echo "--- regenerating APIs"
17-
echo "skipping until bazel is available on the agent"
18-
# $REPO_ROOT/scripts/generateapis.sh
24+
echo "--- Regenerating APIs"
25+
echo "Skipping until bazel is available on the agent"
26+
# scripts/generateapis.sh
1927

2028
echo "--- Preparing docker image for premerge"
21-
docker build --build-arg IMPROBABLE_REFRESH_TOKEN=$IMPROBABLE_REFRESH_TOKEN --build-arg SDK_VERSION=$SDK_VERSION_PREMERGE -t $DOCKER_IMAGE $REPO_ROOT
29+
docker build \
30+
--build-arg "IMPROBABLE_REFRESH_TOKEN=${IMPROBABLE_REFRESH_TOKEN}" \
31+
--build-arg "SDK_VERSION=${SDK_VERSION_PREMERGE}" \
32+
--tag "${DOCKER_IMAGE}" \
33+
"${REPO_ROOT}"
2234

2335
echo "--- Running scenarios in docker"
24-
$REPO_ROOT/scripts/runtests.sh $DOCKER_IMAGE
36+
scripts/runtests.sh "${DOCKER_IMAGE}"
37+

scripts/release.sh

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
3+
set -e -u -o pipefail
44

5-
if [[ -z ${SDK_VERSION+x} ]]; then
6-
echo "Pls provide SDK_VERSION."
5+
REPO_ROOT="$(dirname "$0")/.."
6+
cd "${REPO_ROOT}"
7+
8+
DOCKER_IMAGE="platform-sdk/csharp"
9+
ARTEFACT_DIR="${REPO_ROOT}/artefacts"
10+
OUTPUT_DIR="${REPO_ROOT}/apis/bin/Release"
11+
12+
if [[ -z "${SDK_VERSION+x}" ]]; then
13+
echo "Please set the SDK_VERSION environment variable to the correct version."
714
exit 1
815
fi
916

10-
if [[ -z ${NUGET_API_KEY+x} ]]; then
11-
echo "NUGET_API_KEY is unset."
17+
if [[ -z "${NUGET_API_KEY+x}" ]]; then
18+
echo "Please set the NUGET_API_KEY environment variable."
1219
# echo "Trying to retrieve from vaults."
1320
# IMPROBABLE_REFRESH_TOKEN="$(imp-ci secrets read --environment=production --buildkite-org=improbable --secret-type=spatialos-service-account --secret-name=platform-sdk)"
1421
fi
1522

16-
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
17-
DOCKER_IMAGE=platform-sdk/csharp
18-
ARTEFACT_DIR=$REPO_ROOT/artefacts
19-
OUTPUT_DIR=$REPO_ROOT/apis/bin/Release
20-
2123
echo "--- Clearing artefacts from previous runs"
22-
mkdir -p $ARTEFACT_DIR
23-
rm -rf $ARTEFACT_DIR/*
24+
rm -rf "${ARTEFACT_DIR}"
25+
mkdir -p "${ARTEFACT_DIR}"
2426

2527
echo "--- Preparing artefacts for release"
26-
msbuild $REPO_ROOT/apis/apis.csproj /p:Configuration=Release /p:Version=${SDK_VERSION} /t:Clean,Build -verbosity:minimal
27-
pushd ${OUTPUT_DIR}/net451
28-
zip -r ${ARTEFACT_DIR}/${SDK_VERSION}-net451.zip *
28+
msbuild "${REPO_ROOT}/apis/apis.csproj" \
29+
/p:Configuration=Release \
30+
/p:Version="${SDK_VERSION}" \
31+
/t:Clean,Build \
32+
-verbosity:minimal
33+
34+
pushd "${OUTPUT_DIR}/net451"
35+
zip -r "${ARTEFACT_DIR}/${SDK_VERSION}-net451.zip" *
2936
popd
30-
cp ${OUTPUT_DIR}/Improbable.SpatialOS.Platform.${SDK_VERSION}.nupkg ${ARTEFACT_DIR}
37+
38+
cp "${OUTPUT_DIR}/Improbable.SpatialOS.Platform.${SDK_VERSION}.nupkg" "${ARTEFACT_DIR}"
3139

3240
echo "--- Publishing to NuGet"
33-
nuget setApiKey ${NUGET_API_KEY}
34-
nuget push ${ARTEFACT_DIR}/Improbable.SpatialOS.Platform.${SDK_VERSION}.nupkg -Source https://api.nuget.org/v3/index.json
41+
nuget setApiKey "${NUGET_API_KEY}"
42+
nuget push "${ARTEFACT_DIR}/Improbable.SpatialOS.Platform.${SDK_VERSION}.nupkg" -Source https://api.nuget.org/v3/index.json
3543

3644
echo "--- Publishing to SpatialOS Package service"
37-
package_client publish platform_sdk csharp $SDK_VERSION ${ARTEFACT_DIR}/${SDK_VERSION}-net451.zip
45+
package_client publish platform_sdk csharp "${SDK_VERSION}" "${ARTEFACT_DIR}/${SDK_VERSION}-net451.zip"
46+

scripts/runtests.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -e -u -o pipefail
44

5-
if [[ $# -ne 1 ]]; then
5+
if [[ "$#" -ne 1 ]]; then
66
echo "Supply the docker image name as the first argument."
77
exit 1
88
fi
99

10-
DOCKER_IMAGE=$1
10+
DOCKER_IMAGE="$1"
1111

1212
echo "--- Running Game Maintenance Scenario"
13-
docker run $DOCKER_IMAGE /bin/bash -c "cd examples/GameMaintenance && dotnet run --no-build --configuration Release"
13+
docker run \
14+
--workdir="/workspace/examples/GameMaintenance" \
15+
"${DOCKER_IMAGE}" \
16+
/bin/bash -c "dotnet run --no-build --configuration Release"
1417

1518
echo "--- Running Service Account Maintenance Scenario"
16-
docker run $DOCKER_IMAGE /bin/bash -c "cd examples/ServiceAccountMaintenance && dotnet run --no-build --configuration Release"
19+
docker run \
20+
--workdir="/workspace/examples/ServiceAccountMaintenance" \
21+
"${DOCKER_IMAGE}" \
22+
/bin/bash -c "dotnet run --no-build --configuration Release"
1723

1824
echo "--- Running Replicate State Scenario"
19-
docker run $DOCKER_IMAGE /bin/bash -c "cd examples && spatial service start --main_config=blank_project/spatialos.json && cd ReplicateState && dotnet run --no-build --configuration Release"
25+
docker run \
26+
--workdir="/workspace/examples" \
27+
"${DOCKER_IMAGE}" \
28+
/bin/bash -c "spatial service start --main_config=blank_project/spatialos.json && cd ReplicateState && dotnet run --no-build --configuration Release"
2029

2130
echo "--- Running BYO Auth Scenario"
22-
docker run $DOCKER_IMAGE /bin/bash -c "cd examples && cd BYOAuthFlow && dotnet run --no-build --configuration Release"
31+
docker run \
32+
--workdir="/workspace/examples/BYOAuthFlow" \
33+
"${DOCKER_IMAGE}" \
34+
/bin/bash -c "dotnet run --no-build --configuration Release"
2335

2436
echo "--- Running Capacity Limit Scenario"
25-
docker run $DOCKER_IMAGE /bin/bash -c "cd examples/CapacityLimit && dotnet run --no-build --configuration Release"
37+
docker run \
38+
--workdir="/workspace/examples/CapacityLimit" \
39+
"${DOCKER_IMAGE}" \
40+
/bin/bash -c "dotnet run --no-build --configuration Release"
41+

0 commit comments

Comments
 (0)