Skip to content

Commit

Permalink
Merge pull request protocolbuffers#10830 from zhangskz:release-php
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 485357156
  • Loading branch information
copybara-github committed Nov 1, 2022
2 parents 0ff2656 + 71a069e commit 6c78c66
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 1,484 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/php-ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,32 @@ jobs:
- php:7.4-cli
- php:8.1-cli
steps:
- name: Install git
- name: Install python3
run: |
apt-get update -q
apt-get install -qy python3
- name: Install bazel
run: |
apt-get install -qy wget
mkdir $HOME/bin
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/5.3.2/bazel-5.3.2-linux-x86_64
chmod a+x $HOME/bin/bazel
- name: Install git
run: |
apt-get install -qy --no-install-recommends git
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Prepare source code
run: |
rm -rf "$GITHUB_WORKSPACE/php/ext/google/protobuf/third_party"
cp -r "$GITHUB_WORKSPACE/third_party" "$GITHUB_WORKSPACE/php/ext/google/protobuf"
cp "$GITHUB_WORKSPACE/LICENSE" "$GITHUB_WORKSPACE/php/ext/google/protobuf"
- name: Create package
run: |
cd /tmp
rm -rf protobuf-*.tgz
pecl package "$GITHUB_WORKSPACE/php/ext/google/protobuf/package.xml"
cd $GITHUB_WORKSPACE
rm -rf bazel-bin/php/protobuf-*.tgz
$HOME/bin/bazel build php:release
- name: Compile extension
run: |
cd /tmp
MAKE="make -j$(nproc)" pecl install protobuf-*.tgz
MAKE="make -j$(nproc)" pecl install $GITHUB_WORKSPACE/bazel-bin/php/protobuf-*.tgz
- name: Enable extension
run: docker-php-ext-enable protobuf
- name: Inspect extension
Expand Down
82 changes: 76 additions & 6 deletions php/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#
# See also code generation logic under /src/google/protobuf/compiler/php.

load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION")

filegroup(
name = "source_files",
Expand All @@ -14,15 +16,11 @@ filegroup(
"//php:__pkg__",
],
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
"src/GPBMetadata/Google/Protobuf/**/*.php",
"src/Google/Protobuf/**/*.php",
]) + [
"composer.json",
"ext/google/protobuf/wkt.inc",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/package.xml",
":php_ext_source_files",
],
)

Expand Down Expand Up @@ -137,3 +135,75 @@ pkg_files(
strip_prefix = strip_prefix.from_pkg(""),
visibility = ["//pkg:__pkg__"],
)

################################################################################
# PECL .tgz Release
################################################################################

pkg_files(
name = "php_ext_source_files",
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
]) + [
"//:LICENSE",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/wkt.inc",
],
)

pkg_files(
name = "utf8_range_files",
srcs = [
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
],
prefix = "third_party/utf8_range",
)

pkg_filegroup(
name = "pecl_release_files",
srcs = [
":php_ext_source_files",
":utf8_range_files",
],
prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION,
)

# PECL .tgz without package.xml
pkg_tar(
name = "release_without_package",
extension = "tgz",
srcs = [
":pecl_release_files",
],
out = "release_without_package.tgz",
)

# Generate PECL package.xml
genrule(
name = "generate_package_xml",
srcs = [
":release_without_package",
"ext/google/protobuf/template_package.xml",
],
outs = ["package.xml"],
cmd = " ".join([
"$(location ext/google/protobuf/generate_package_xml.sh)",
"$(location ext/google/protobuf/template_package.xml)",
PROTOBUF_PHP_VERSION,
"$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')",
"$(location package.xml)"
]),
tools = ["ext/google/protobuf/generate_package_xml.sh"],
)

pkg_tar(
name = "release",
extension = "tgz",
srcs = [
":pecl_release_files",
":generate_package_xml",
],
out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION,
)
39 changes: 39 additions & 0 deletions php/ext/google/protobuf/generate_package_xml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

template_package_xml=$1
release_version=$2
release_files=$3
out=$4

date=$(date +%Y-%m-%d)
time=$(date +%H:%M:%S)

php_version_array=(${release_version//RC/ })
api_version=${php_version_array[0]}
if [ ${#php_version_array[@]} -eq 2 ]; then
rc=${php_version_array[1]}
stability='beta'
else
stability='stable'
fi

files="\\n"
for file in ${release_files//,/ }; do
name=$(echo $file | grep .*[^/]\$ | sed -e "s;protobuf-${release_version}/;;")
if [ ! -z $name ]; then
if [[ $name =~ LICENSE$ ]]; then
role='doc'
else
role='src'
fi
files+=" <file baseinstalldir=\"/\" name=\"${name}\" role=\"${role}\"/>\\n"
fi
done

cat $template_package_xml |
sed -e "s;TEMPLATE_DATE;${date};" |
sed -e "s;TEMPLATE_TIME;${time};" |
sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" |
sed -e "s;TEMPLATE_PHP_API;${api_version};" |
sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" |
sed -e "s;TEMPLATE_FILES;${files};" > $out
Loading

0 comments on commit 6c78c66

Please sign in to comment.