tdlight-java-natives/.github/workflows/platform_natives.yaml
2021-09-14 01:55:55 +02:00

230 lines
9.6 KiB
YAML

name: Docker multi-arch build
on:
push:
pull_request:
jobs:
build:
name: Build (${{ matrix.implementation }}-${{ matrix.os }}-${{ matrix.arch }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/386", implementation: "tdlight"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/386", implementation: "tdlib"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/amd64", implementation: "tdlight"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/amd64", implementation: "tdlib"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm/v6", implementation: "tdlight"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm/v6", implementation: "tdlib"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm/v7", implementation: "tdlight"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm/v7", implementation: "tdlib"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm64", implementation: "tdlight"}
- {os: ubuntu-18.04, usedocker: "false", arch: "linux/arm64", implementation: "tdlib"}
- {os: windows-2019, usedocker: "false", arch: "amd64", implementation: "tdlight", triplet: "x64-windows-static"}
- {os: windows-2019, usedocker: "false", arch: "amd64", implementation: "tdlib", triplet: "x64-windows-static"}
- {os: macos-10.15, usedocker: "false", arch: "amd64", implementation: "tdlight"}
- {os: macos-10.15, usedocker: "false", arch: "amd64", implementation: "tdlib"}
steps:
- name: Checkout current repo
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Get version
if: matrix.usedocker == 'true'
run: |
# Get latest commit short hash
HASH_VERSION=$(git rev-parse --short HEAD)
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
ARCH=${{ matrix.arch }}
SAFE_ARCH=${ARCH///} # linux/amd64 -> linuxamd64
# Store variable for future use
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "SAFE_ARCH=$SAFE_ARCH" >> $GITHUB_ENV
# Print debug info
echo "hash version: $HASH_VERSION"
echo "version: $VERSION"
echo "safe arch: $SAFE_ARCH"
# Save env to file
cat $GITHUB_ENV > github.env
- name: Set up QEMU
if: matrix.usedocker == 'true'
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
if: matrix.usedocker == 'true'
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
if: matrix.usedocker == 'true'
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.SAFE_ARCH }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.SAFE_ARCH }}-
- name: Build image
if: matrix.usedocker == 'true'
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
platforms: ${{ matrix.arch }}
push: false
load: true
tags: |
tdlight-java-natives:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}
build-args: |
REVISION=${{ github.run_number }}
GH_MATRIX_OS=${{ matrix.os }}
GH_MATRIX_ARCH=${{ matrix.arch }}
IMPLEMENTATION_NAME=${{ matrix.implementation }}
- name: Extract jni from docker image
if: matrix.usedocker == 'true'
run: |
mkdir generated
docker cp $(docker create tdlight-java-natives:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}):/usr/src/tdlight-java-natives/generated/. ./generated/.
- name: Setup Java (Snapshot)
if: github.ref == 'refs/heads/develop'
uses: actions/setup-java@v1
with:
java-version: 11
server-id: mchv-snapshot-distribution
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Setup Java (Release)
if: github.ref == 'refs/heads/master'
uses: actions/setup-java@v1
with:
java-version: 11
server-id: mchv-release-distribution
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Setup variables
shell: bash
run: |
# ====== Variables
export REVISION=${{ github.run_number }}
export GH_MATRIX_OS=${{ matrix.os }}
export GH_MATRIX_ARCH=${{ matrix.arch }}
export IMPLEMENTATION_NAME=${{ matrix.implementation }}
source ./scripts/continuous-integration/github-workflows/setup-variables.sh
echo "Variables:"
echo "REVISION=$REVISION" >> $GITHUB_ENV
echo "BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV
echo "IMPLEMENTATION_NAME=$IMPLEMENTATION_NAME" >> $GITHUB_ENV
echo "TD_SRC_DIR=$TD_SRC_DIR" >> $GITHUB_ENV
echo "TD_BIN_DIR=$TD_BIN_DIR" >> $GITHUB_ENV
echo "TDNATIVES_BIN_DIR=$TDNATIVES_BIN_DIR" >> $GITHUB_ENV
echo "TDNATIVES_CPP_SRC_DIR=$TDNATIVES_CPP_SRC_DIR" >> $GITHUB_ENV
echo "TDNATIVES_DOCS_BIN_DIR=$TDNATIVES_DOCS_BIN_DIR" >> $GITHUB_ENV
echo "TD_BUILD_DIR=$TD_BUILD_DIR" >> $GITHUB_ENV
echo "TDNATIVES_CPP_BUILD_DIR=$TDNATIVES_CPP_BUILD_DIR" >> $GITHUB_ENV
echo "JAVA_SRC_DIR=$JAVA_SRC_DIR" >> $GITHUB_ENV
echo "TDLIB_SERIALIZER_DIR=$TDLIB_SERIALIZER_DIR" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
echo "JAVA_INCLUDE_PATH=$JAVA_INCLUDE_PATH" >> $GITHUB_ENV
echo "CMAKE_EXTRA_ARGUMENTS=$CMAKE_EXTRA_ARGUMENTS" >> $GITHUB_ENV
echo "VCPKG_DIR=$VCPKG_DIR" >> $GITHUB_ENV
echo "MAVEN_OPTS=$MAVEN_OPTS" >> $GITHUB_ENV
echo "GH_CPU_ARCH=$GH_CPU_ARCH" >> $GITHUB_ENV
echo "CPU_ARCH_JAVA=$CPU_ARCH_JAVA" >> $GITHUB_ENV
echo "CPU_ARCHITECTURE_NAME=$CPU_ARCHITECTURE_NAME" >> $GITHUB_ENV
echo "CPU_CORES_NUM=$CPU_CORES_NUM" >> $GITHUB_ENV
echo "CPU_CORES=$CPU_CORES" >> $GITHUB_ENV
echo "OPERATING_SYSTEM_NAME=$OPERATING_SYSTEM_NAME" >> $GITHUB_ENV
echo "OPERATING_SYSTEM_NAME_SHORT=$OPERATING_SYSTEM_NAME_SHORT" >> $GITHUB_ENV
echo "SRC_TDJNI_LIBNAME=$SRC_TDJNI_LIBNAME" >> $GITHUB_ENV
echo "DEST_TDJNI_LIBNAME=$DEST_TDJNI_LIBNAME" >> $GITHUB_ENV
- name: Install dependencies
if: matrix.usedocker == 'false'
shell: bash
run: |
echo "REVISION: $REVISION"
source ./scripts/continuous-integration/github-workflows/install-dependencies.sh
- name: Restore artifacts, or setup vcpkg (do not install any package)
if: matrix.os == 'windows-2019'
uses: lukka/run-vcpkg@v7
with:
# Just install vcpkg for now, do not install any ports in this step yet.
setupOnly: true
# Location of the vcpkg submodule in the Git repository.
vcpkgDirectory: '${{ env.VCPKG_DIR }}'
# Since the cache must be invalidated when content of the vcpkg.json file changes, let's
# compute its hash and append this to the computed cache's key.
appendedCacheKey: ${{ hashFiles( '**/vcpkg_manifest/vcpkg.json' ) }}
vcpkgTriplet: ${{ matrix.triplet }}
# Ensure the vcpkg artifacts are cached, they are generated in the 'CMAKE_BINARY_DIR/vcpkg_installed' directory.
- name: Install vcpkg deps
if: matrix.os == 'windows-2019'
run: |
$VCPKG_DIR/vcpkg install gperf openssl:x64-windows-static zlib:x64-windows-static
shell: bash
- name: Build
if: matrix.usedocker == 'false'
shell: bash
run: |
echo "REVISION: $REVISION"
source ./scripts/continuous-integration/github-workflows/build-natives.sh
- id: getfilename
shell: bash
run: echo "::set-output name=file::$(cd generated/target; ls tdli*-natives-*.jar)"
- id: getfilepath
shell: bash
run: echo "::set-output name=file::$(ls generated/target/tdli*-natives-*.jar)"
- uses: actions/upload-artifact@v2
with:
name: ${{ steps.getfilename.outputs.file }}
path: ${{ steps.getfilepath.outputs.file }}
- name: Deploy to Maven (Snapshot)
if: github.ref == 'refs/heads/develop'
shell: bash
run: |
echo "REVISION: $REVISION"
source ./scripts/continuous-integration/github-workflows/deploy-snapshot.sh
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}
- name: Deploy to Maven (Release)
if: github.ref == 'refs/heads/master'
shell: bash
run: |
echo "REVISION: $REVISION"
source ./scripts/continuous-integration/github-workflows/deploy-release.sh
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}