tdlight-java-natives/.github/workflows/natives_docker.yaml
2021-03-15 18:37:35 +01:00

115 lines
4.2 KiB
YAML

name: Docker multi-arch build
on:
push:
pull_request:
jobs:
build:
name: Build Docker image (${{ matrix.arch }})
runs-on: ubuntu-latest
env:
IMAGE_TAG: ghcr.io/${{ github.repository_owner }}/tdlight-java-natives
IMAGE_TAG_DH: ${{ secrets.DOCKERHUB_OWNER }}/tdlight-java-natives
strategy:
matrix:
include:
- {os: ubuntu-20.04, arch: "linux/386", implementation: "tdlight"}
- {os: ubuntu-20.04, arch: "linux/386", implementation: "tdlib"}
- {os: ubuntu-20.04, arch: "linux/amd64", implementation: "tdlight"}
- {os: ubuntu-20.04, arch: "linux/amd64", implementation: "tdlib"}
- {os: ubuntu-20.04, arch: "linux/arm/v6", implementation: "tdlight"}
- {os: ubuntu-20.04, arch: "linux/arm/v6", implementation: "tdlib"}
- {os: ubuntu-20.04, arch: "linux/arm/v7", implementation: "tdlight"}
- {os: ubuntu-20.04, arch: "linux/arm/v7", implementation: "tdlib"}
- {os: ubuntu-20.04, arch: "linux/arm64", implementation: "tdlight"}
- {os: ubuntu-20.04, arch: "linux/arm64", implementation: "tdlib"}
steps:
- name: Checkout current repo
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Get version
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
# Convert IMAGE_TAG, HASH_VERSION and VERSION to lowercase (repository name must be lowercase)
IMAGE_TAG=$(echo "$IMAGE_TAG" | awk '{print tolower($0)}')
IMAGE_TAG_DH=$(echo "$IMAGE_TAG_DH" | awk '{print tolower($0)}')
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 "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "IMAGE_TAG_DH=$IMAGE_TAG_DH" >> $GITHUB_ENV
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: Upload environment info as artifact
uses: actions/upload-artifact@v2
with:
name: github_env
path: github.env
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
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
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
run: |
mkdir generated
docker cp $(docker create tdlight-java-natives:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}):/usr/src/tdlight-java-natives/generated/. ./generated/.