mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-10-31 15:26:23 +07:00 
			
		
		
		
	Add support for protoc and grpc_php_plugin
This commit is contained in:
		
							
								
								
									
										20
									
								
								src/scripts/tools/grpc_php_plugin.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/scripts/tools/grpc_php_plugin.ps1
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| Function Add-Msys2() { | ||||
|   $msys_location = 'C:\msys64' | ||||
|   if (-not(Test-Path $msys_location)) { | ||||
|     choco install msys2 -y >$null 2>&1 | ||||
|     $msys_location = 'C:\tools\msys64' | ||||
|   } | ||||
|   return $msys_location | ||||
| } | ||||
|  | ||||
| Function Add-Grpc_php_plugin() { | ||||
|   $msys_location = Add-Msys2 | ||||
|   . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1 | ||||
|   Write-Output "::add-path::$msys_location\mingw64\bin" | ||||
|   Write-Output "::set-output name=grpc_php_plugin_path::$msys_location\mingw64\bin\grpc_php_plugin.exe" | ||||
|   Add-ToProfile $current_profile 'grpc_php_plugin' "New-Alias grpc_php_plugin $msys_location\mingw64\bin\grpc_php_plugin.exe" | ||||
|   Add-Log $tick "grpc_php_plugin" "Added" | ||||
|   printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information" | ||||
|   Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/grpc/grpc/master/LICENSE).Content | ||||
|   Write-Output "::endgroup::" | ||||
| } | ||||
							
								
								
									
										51
									
								
								src/scripts/tools/grpc_php_plugin.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/scripts/tools/grpc_php_plugin.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | ||||
| add_bazel() { | ||||
|   if [ ! "$(command -v bazel)" ]; then | ||||
|     os=$(uname -s) | ||||
|     if [ "$os" = "Linux" ]; then | ||||
|       ${apt_install:?} curl gnupg | ||||
|       curl "${curl_opts[@]:?}" https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - | ||||
|       echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list | ||||
|       sudo "${debconf_fix:?}" apt-get update -y | ||||
|       ${apt_install:?} bazel | ||||
|     elif [ "$os" = "Darwin" ]; then | ||||
|       brew install bazel | ||||
|     fi | ||||
|   fi | ||||
| } | ||||
|  | ||||
| get_grpc_tag() { | ||||
|   if [ "$grpc_tag" = "latest" ]; then | ||||
|     grpc_tag=$(curl "${curl_opts[@]:?}" https://grpc.io/release) | ||||
|   else | ||||
|     status_code=$(sudo curl -s -w "%{http_code}" -o /tmp/grpc.tmp "${curl_opts[@]:?}" "https://github.com/grpc/grpc/releases/tag/v$grpc_tag") | ||||
|     if [ "$status_code" = "200" ]; then | ||||
|       grpc_tag="v$grpc_tag" | ||||
|     else | ||||
|       grpc_tag=$(curl "${curl_opts[@]:?}" https://grpc.io/release) | ||||
|     fi | ||||
|   fi | ||||
| } | ||||
|  | ||||
| add_grpc_php_plugin() { | ||||
|   grpc_tag=$1 | ||||
|   get_grpc_tag | ||||
|   ( | ||||
|     curl "${curl_opts[@]:?}" "https://github.com/grpc/grpc/archive/$grpc_tag.tar.gz" | tar -xz -C /tmp | ||||
|     cd "/tmp/grpc-${grpc_tag:1}" || exit | ||||
|     add_bazel | ||||
|     echo "os: $os" | ||||
|     echo "release: $DISTRIB_RELEASE" | ||||
|     if [ "$DISTRIB_RELEASE" = "16.04" ]; then | ||||
|       CC="$(command -v gcc)" CXX="$(command -v g++)" ./tools/bazel build src/compiler:grpc_php_plugin | ||||
|     else | ||||
|       ./tools/bazel build src/compiler:grpc_php_plugin | ||||
|     fi | ||||
|     sudo mv ./bazel-bin/src/compiler/grpc_php_plugin /usr/local/bin/grpc_php_plugin | ||||
|     sudo chmod a+x /usr/local/bin/grpc_php_plugin | ||||
|   ) >/dev/null 2>&1 | ||||
|   echo "::set-output name=grpc_php_plugin_path::/usr/local/bin/grpc_php_plugin" | ||||
|   add_log "${tick:?}" "grpc_php_plugin" "Added" | ||||
|   printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information" | ||||
|   cat "/tmp/grpc-${grpc_tag:1}/LICENSE" | ||||
|   echo "::endgroup::" | ||||
| } | ||||
							
								
								
									
										38
									
								
								src/scripts/tools/protoc.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/scripts/tools/protoc.ps1
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | ||||
| Function Get-ProtobufTag() { | ||||
|   if("$protobuf_tag" -eq "latest") { | ||||
|     $protobuf_tag = (Invoke-RestMethod https://api.github.com/repos/protocolbuffers/protobuf/tags).Name | Where-Object { $_ -match "v\d+.\d+.\d+$" } | Select-Object -First 1 | ||||
|   } else { | ||||
|     try { | ||||
|       [net.httpWebRequest] $request = [net.webRequest]::create("https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag") | ||||
|       $req.Method = "HEAD" | ||||
|       [net.httpWebResponse] $response = $request.getResponse() | ||||
|       $response.Close() | ||||
|       $protobuf_tag = "v$protobuf_tag" | ||||
|     } catch { | ||||
|       $protobuf_tag = (Invoke-RestMethod https://api.github.com/repos/protocolbuffers/protobuf/tags).Name | Where-Object { $_ -match "v\d+.\d+.\d+$" } | Select-Object -First 1 | ||||
|     } | ||||
|   } | ||||
|   return $protobuf_tag | ||||
| } | ||||
|  | ||||
| Function Add-Protoc() { | ||||
|   param( | ||||
|     [Parameter(Mandatory = $true, Position = 0, HelpMessage = 'The PHP version to be installed')] | ||||
|     [ValidatePattern('^latest$|^(v?)\d+\.\d+\.\d+$')] | ||||
|     [string] $protobuf_tag | ||||
|   ) | ||||
|   $protobuf_tag = Get-ProtobufTag | ||||
|   $arch_num = '64' | ||||
|   if(-not([Environment]::Is64BitOperatingSystem)) { | ||||
|     $arch_num = '32' | ||||
|   } | ||||
|   $url = "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-$($protobuf_tag -replace 'v', '')-win$arch_num.zip" | ||||
|   Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $bin_dir\protoc.zip >$null 2>&1 | ||||
|   Expand-Archive -Path $bin_dir\protoc.zip -DestinationPath $bin_dir\protoc -Force >$null 2>&1 | ||||
|   Move-Item -Path $bin_dir\protoc\bin\protoc.exe -Destination $bin_dir\protoc.exe | ||||
|   Add-ToProfile $current_profile 'protoc' "New-Alias protoc $bin_dir\protoc.exe" | ||||
|   Add-Log $tick "protoc" "Added" | ||||
|   printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information" | ||||
|   Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE).Content | ||||
|   Write-Output "::endgroup::" | ||||
| } | ||||
							
								
								
									
										28
									
								
								src/scripts/tools/protoc.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/scripts/tools/protoc.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| get_protobuf_tag() { | ||||
|   if [ "$protobuf_tag" = "latest" ]; then | ||||
|     protobuf_tag=$(curl "${curl_opts[@]:?}" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+.[0-9]+.[0-9]+)" | head -n 1) | ||||
|   else | ||||
|     status_code=$(sudo curl -s -w "%{http_code}" -o /tmp/protobuf.tmp "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag") | ||||
|     if [ "$status_code" = "200" ]; then | ||||
|       protobuf_tag="v$protobuf_tag" | ||||
|     else | ||||
|       protobuf_tag=$(curl "${curl_opts[@]:?}" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+.[0-9]+.[0-9]+)" | head -n 1) | ||||
|     fi | ||||
|   fi | ||||
| } | ||||
|  | ||||
| add_protoc() { | ||||
|   protobuf_tag=$1 | ||||
|   get_protobuf_tag | ||||
|   ( | ||||
|     platform='linux' | ||||
|     [ "$(uname -s)" = "Darwin" ] && platform='osx' | ||||
|     curl -o /tmp/protobuf.zip "${curl_opts[@]:?}" "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip" | ||||
|     sudo unzip /tmp/protobuf.zip -d /usr/local/ | ||||
|     sudo chmod a+x /usr/local/bin/protoc | ||||
|   ) >/dev/null 2>&1 | ||||
|   add_log "${tick:?}" "protoc" "Added" | ||||
|   printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information" | ||||
|   curl "${curl_opts[@]:?}" https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE | ||||
|   echo "::endgroup::" | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Mathur
					Shivam Mathur