Skip to content

Commit

Permalink
Merge pull request #11 from aceforeverd/ci/build-and-release
Browse files Browse the repository at this point in the history
ci: build and release
  • Loading branch information
jingchen2222 authored May 18, 2021
2 parents 3138164 + 03c35b6 commit 33bab5b
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 30 deletions.
85 changes: 55 additions & 30 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, feat/hyrbidse-zetasql]
tags:
- v*
pull_request:

# Allows you to run this workflow manually from the Actions tab
Expand All @@ -20,14 +22,8 @@ env:
jobs:
# This workflow contains a single job called "build"
linux-build:
strategy:
fail-fast: false
matrix:
container: ['debian:buster', 'ubuntu:bionic', 'ubuntu:focal', 'archlinux:latest', 'centos:8']

# The type of runner that the job will run on
runs-on: ubuntu-latest
container: ${{ matrix.container }}
container: 'debian:buster'
timeout-minutes: 120

# Steps represent a sequence of tasks that will be executed as part of the job
Expand All @@ -42,35 +38,15 @@ jobs:
java-version: '11'

- name: install deps (debian)
if: ${{ startsWith(matrix.container, 'debian') || startsWith(matrix.container, 'ubuntu') }}
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl build-essential unzip python3
update-alternatives --install /usr/bin/python python /usr/bin/python3 100
- name: choose python (ubuntu:bionic)
if: ${{ matrix.container == 'ubuntu:bionic' }}
run: |
apt-get install -y gcc-8 g++-8 python3.8
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 200
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8
- name: install deps (arch)
if: ${{ startsWith(matrix.container, 'archlinux') }}
run: |
pacman -Sy --noconfirm curl base-devel unzip python
- name: install deps (centos8)
if: ${{ startsWith(matrix.container, 'centos') }}
run: |
yum install -y curl unzip python38
yum group install -y 'Development Tools'
alternatives --set python /usr/bin/python3.8
# Runs a single command using the runners shell
- name: Install Bazelisk
run: |
curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-linux-amd64
curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.8.0/bazelisk-linux-amd64
chmod +x /usr/local/bin/bazel
- name: print toolchain info
Expand Down Expand Up @@ -100,7 +76,7 @@ jobs:

- name: update bazel version
run: echo ${{ env.bazel_version }} > .bazelversion

- name: install bazelisk
run: |
brew install bazelisk
Expand All @@ -124,7 +100,7 @@ jobs:
strategy:
fail-fast: false
matrix:
toolchain: ['devtoolset-7', 'devtoolset-8', 'devtoolset-9']
toolchain: ['devtoolset-8', 'devtoolset-9']
container: ['centos:7']

runs-on: ubuntu-latest
Expand Down Expand Up @@ -171,3 +147,52 @@ jobs:
bazel test ${{ env.build_argv }} --test_summary=detailed --test_output=errors ${{ env.target }}
release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
container:
image: ghcr.io/aceforeverd/hybridsql-base:0.0.8
env:
BAZEL_LINKOPTS: '-static-libstdc++:-lm'
BAZEL_LINKLIBS: '-l%:libstdc++.a'
target: '//zetasql/...'
build_argv: ''
steps:
- uses: actions/checkout@v2
- name: Setup Bazel
run: |
curl --create-dirs -SLo /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.8.0/bazelisk-linux-amd64
chmod +x /usr/local/bin/bazel
- name: Install Java
run: |
yum install -y java-1.8.0-openjdk-devel
- name: build zetasql
run: |
source /opt/rh/devtoolset-8/enable
source /opt/rh/rh-python38/enable
bazel build ${{ env.build_argv }} ${{ env.target }}
- name: Find Orphan Library
run: |
./find_orphan_so.sh
- name: Determine Version
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
VERSION=$(echo $VERSION | sed -e 's/^v//')
echo "TAG=$VERSION" >> $GITHUB_ENV
- name: pack libzetasql
run: |
./pack_zetasql.sh
env:
TAG: ${{ env.TAG }}

- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
libzetasql-*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 33 additions & 0 deletions find_orphan_so.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -eE

RED='\033[0;31m'
NC='\033[0m'

analyze_so() {
local so_file
so_file=$1
local archive_file
archive_file=$(echo "$so_file" | sed -e 's/\.so$/\.a/')
if [ ! -e "$archive_file" ]; then
echo -e "${RED}$so_file is orphan, no $archive_file found${NC}"
fi
}

analyze_archive() {
local archive_file
archive_file=$1
local so_file
so_file=$(echo "$archive_file" | sed -e 's/\.a$/\.so/')
if [ ! -e "$so_file" ]; then
echo -e "${RED}$archive_file is orphan, no $so_file found${NC}"
fi
}

export -f analyze_so analyze_archive

pushd bazel-bin/
find zetasql -maxdepth 4 -iname '*.so' -exec bash -c 'analyze_so $0' {} \;
find zetasql -iname '*.a' -exec bash -c 'analyze_archive $0' {} \;
popd
81 changes: 81 additions & 0 deletions pack_zetasql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# install zetasql compiled header files and libs

set -eE

cd "$(dirname "$0")"
VERSION=${TAG:-$(git rev-parse --short HEAD)}
export ROOT=$(pwd)
export PREFIX="$ROOT/libzetasql-$VERSION"

rm -rf tmp-lib libzetasql.mri
mkdir -p tmp-lib

install_lib() {
local file
file=$1
local libname
libname=lib$(echo "$file" | tr '/' '_' | sed -e 's/lib//')
install -D "$file" "$ROOT/tmp-lib/$libname"
}

install_gen_include_file() {
local file
file=$1
local outfile
outfile=$(echo "$file" | sed -e 's/^.*proto\///')
install -D "$file" "$PREFIX/include/$outfile"
}

install_external_lib() {
local file
file=$1
local libname
libname=$(basename "$file")
install -D "$file" "$PREFIX/lib/$libname"
}

export -f install_gen_include_file
export -f install_lib
export -f install_external_lib


pushd bazel-bin/
# exlucde test so
find zetasql -maxdepth 4 -type f -iname '*.so' -exec bash -c 'install_lib $0' {} \;
find zetasql -type f -iname '*.a' -exec bash -c 'install_lib $0' {} \;

# external lib headers
pushd "$(realpath .)/../../../../../external/com_googlesource_code_re2"
find re2 -iname "*.h" -exec install -D {} "$PREFIX"/include/{} \;
popd

# external lib
pushd external
find icu -type f -iregex ".*/.*\.\(so\|a\)\$" -exec bash -c 'install_external_lib $0' {} \;
find com_googlesource_code_re2 -type f -iregex ".*/.*\.\(so\|a\)\$" -exec bash -c 'install_external_lib $0' {} \;
find com_googleapis_googleapis -type f -iname '*.so' -exec bash -c 'install_external_lib $0' {} \;
popd

# zetasql generated files: protobuf & template generated files
find zetasql -type f -iname "*.h" -exec install -D {} "$PREFIX"/include/{} \;
find zetasql -iregex ".*/_virtual_includes/.*\.h\$" -exec bash -c 'install_gen_include_file $0' {} \;
popd # bazel-bin

# header files from source
find zetasql -type f -iname "*.h" -exec install -D {} "$PREFIX"/include/{} \;


echo 'create libzetasql.a' >> libzetasql.mri
find tmp-lib/ -iname "*.a" -type f -exec bash -c 'echo "addlib $0" >> libzetasql.mri' {} \;
echo "save" >> libzetasql.mri
echo "end" >> libzetasql.mri

ar -M <libzetasql.mri
ranlib libzetasql.a
mv libzetasql.a "$PREFIX/lib"
mv tmp-lib/*.so "$PREFIX/lib"


tar czf "libzetasql-$VERSION.tar.gz" "libzetasql-$VERSION"/

0 comments on commit 33bab5b

Please sign in to comment.