1ffe3c632Sopenharmony_ci#!/bin/bash
2ffe3c632Sopenharmony_ci
3ffe3c632Sopenharmony_ciset -ex
4ffe3c632Sopenharmony_ci
5ffe3c632Sopenharmony_ci# Change to repo root.
6ffe3c632Sopenharmony_cicd $(dirname $0)/../..
7ffe3c632Sopenharmony_ci
8ffe3c632Sopenharmony_ci# Initialize any submodules.
9ffe3c632Sopenharmony_cigit submodule update --init --recursive
10ffe3c632Sopenharmony_ci
11ffe3c632Sopenharmony_ci# The directory with all resulting artifacts
12ffe3c632Sopenharmony_cimkdir -p artifacts
13ffe3c632Sopenharmony_ci
14ffe3c632Sopenharmony_ci# Artifacts from all predecessor jobs get copied to this directory by kokoro
15ffe3c632Sopenharmony_ciINPUT_ARTIFACTS_DIR="${KOKORO_GFILE_DIR}/github/protobuf"
16ffe3c632Sopenharmony_ci
17ffe3c632Sopenharmony_ci# TODO(jtattermusch): remove listing the files, but for now it make it easier
18ffe3c632Sopenharmony_ci# to iterate on the script.
19ffe3c632Sopenharmony_cils -R ${INPUT_ARTIFACTS_DIR}
20ffe3c632Sopenharmony_ci
21ffe3c632Sopenharmony_ci# ====================================
22ffe3c632Sopenharmony_ci# Copy to expose all the artifacts from the predecessor jobs to the output
23ffe3c632Sopenharmony_ci# TODO(jtattermusch): the directory layout of the artifact builds is pretty messy,
24ffe3c632Sopenharmony_ci# so will be the output artifacts of this job.
25ffe3c632Sopenharmony_cicp -r ${INPUT_ARTIFACTS_DIR}/* artifacts
26ffe3c632Sopenharmony_ci
27ffe3c632Sopenharmony_ci# ====================================
28ffe3c632Sopenharmony_ci# Build Google.Protobuf.Tools C# nuget
29ffe3c632Sopenharmony_ci# The reason it's being done in this script is that we need access to protoc binaries
30ffe3c632Sopenharmony_ci# built on multiple platform (the build is performed by the "build artifact" step)
31ffe3c632Sopenharmony_ci# and adding and extra chained build just for building the Google.Protobuf.Tools
32ffe3c632Sopenharmony_ci# nuget seems like an overkill.
33ffe3c632Sopenharmony_cicd csharp
34ffe3c632Sopenharmony_cimkdir -p protoc/windows_x86
35ffe3c632Sopenharmony_cimkdir -p protoc/windows_x64
36ffe3c632Sopenharmony_cicp ${INPUT_ARTIFACTS_DIR}/build32/Release/protoc.exe protoc/windows_x86/protoc.exe
37ffe3c632Sopenharmony_cicp ${INPUT_ARTIFACTS_DIR}/build64/Release/protoc.exe protoc/windows_x64/protoc.exe
38ffe3c632Sopenharmony_ci
39ffe3c632Sopenharmony_cimkdir -p protoc/linux_x86
40ffe3c632Sopenharmony_cimkdir -p protoc/linux_x64
41ffe3c632Sopenharmony_ci# Because of maven unrelated reasonse the linux protoc binaries have a dummy .exe extension.
42ffe3c632Sopenharmony_ci# For the Google.Protobuf.Tools nuget, we don't want that expection, so we just remove it.
43ffe3c632Sopenharmony_cicp ${INPUT_ARTIFACTS_DIR}/protoc-artifacts/target/linux/x86_32/protoc.exe protoc/linux_x86/protoc
44ffe3c632Sopenharmony_cicp ${INPUT_ARTIFACTS_DIR}/protoc-artifacts/target/linux/x86_64/protoc.exe protoc/linux_x64/protoc
45ffe3c632Sopenharmony_ci
46ffe3c632Sopenharmony_cimkdir -p protoc/macosx_x64
47ffe3c632Sopenharmony_cicp ${INPUT_ARTIFACTS_DIR}/build64/src/protoc protoc/macosx_x64/protoc
48ffe3c632Sopenharmony_ci
49ffe3c632Sopenharmony_ci# Install nuget (will also install  mono)
50ffe3c632Sopenharmony_ci# TODO(jtattermusch): use "mono:5.14" docker image instead so we don't have to apt-get install
51ffe3c632Sopenharmony_cisudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
52ffe3c632Sopenharmony_cisudo apt install apt-transport-https
53ffe3c632Sopenharmony_ciecho "deb https://download.mono-project.com/repo/ubuntu stable-trusty main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
54ffe3c632Sopenharmony_cisudo apt update
55ffe3c632Sopenharmony_cisudo apt-get install -y nuget
56ffe3c632Sopenharmony_ci
57ffe3c632Sopenharmony_cinuget pack Google.Protobuf.Tools.nuspec
58ffe3c632Sopenharmony_ci
59ffe3c632Sopenharmony_ci# Copy the nupkg to the output artifacts
60ffe3c632Sopenharmony_cicp Google.Protobuf.Tools.*.nupkg ../artifacts
61