From 55868b5f5fd3c92553f30c22e526295e5fae83cf Mon Sep 17 00:00:00 2001 From: SonicGDX <114670430+SonicGDX@users.noreply.github.com> Date: Sat, 14 Dec 2024 22:35:37 +0000 Subject: [PATCH] Move build from workflow job to container action I've changed the setup of the natives-linux job to not require needing Node 20, so hopefully it will continue to work with newer versions of checkout and upload-artifact for the forseeable future. I've done this by moving the docker setup into its own action (which is local to the repo) that runs a script in the container that builds the natives and snapshots, but doesn't use any third party actions - meaning it should not be need node 20 to be used in the container. Other minor changes: - Used apt-get instead of apt because using apt in a script gives the warning message "apt does not have a stable interface". - Removed usages of sudo just to be consistent (I can't always use sudo because initially sudo isn't installed) - Added --no-daemon to gradle command because only one gradle command is being run so the daemon isn't necessary. - Added --quiet to apt-get usages to cut down unuseful lines in logs - Moved around arguments to apt-get so they're always at the front - removed setup-java and gradle-build-action usages in the natives-linux step because zulu installation is done in the container and gradle is downloaded when the wrapper is run. Having the action be in a separate actions folder may not be desirable, in which case I can probably move the action into the workflow folder somewhere but I'm not sure where. Copied docker action structure from my similar PR in Jamepad (https://github.com/libgdx/Jamepad/pull/34) --- .../actions/build-linux-natives/Dockerfile | 8 +++ .../actions/build-linux-natives/action.yml | 6 ++ .../actions/build-linux-natives/entrypoint.sh | 44 ++++++++++++++ .github/workflows/build-publish.yml | 59 +------------------ 4 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 .github/actions/build-linux-natives/Dockerfile create mode 100644 .github/actions/build-linux-natives/action.yml create mode 100755 .github/actions/build-linux-natives/entrypoint.sh diff --git a/.github/actions/build-linux-natives/Dockerfile b/.github/actions/build-linux-natives/Dockerfile new file mode 100644 index 00000000000..530506296c0 --- /dev/null +++ b/.github/actions/build-linux-natives/Dockerfile @@ -0,0 +1,8 @@ +# Container image that runs your code +FROM ubuntu:18.04 + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY entrypoint.sh /entrypoint.sh + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/.github/actions/build-linux-natives/action.yml b/.github/actions/build-linux-natives/action.yml new file mode 100644 index 00000000000..3db961c2c0a --- /dev/null +++ b/.github/actions/build-linux-natives/action.yml @@ -0,0 +1,6 @@ +# action.yml +name: 'Build Linux Natives in Docker Container' +description: 'Build Linux Natives in Ubuntu 18.04 docker container' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/actions/build-linux-natives/entrypoint.sh b/.github/actions/build-linux-natives/entrypoint.sh new file mode 100755 index 00000000000..4399a3b8fcb --- /dev/null +++ b/.github/actions/build-linux-natives/entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/sh -l + +# ubuntu dockerfile is very minimal (only 122 packages are installed) +# need to install updated git (from official git ppa) +apt-get -q update +apt-get -yq install software-properties-common +add-apt-repository ppa:git-core/ppa -y +# install dependencies expected by other steps +apt-get -q update +apt-get -yq install git \ +curl \ +ca-certificates \ +wget \ +bzip2 \ +zip \ +unzip \ +xz-utils \ +sudo locales + +# set Locale to en_US.UTF-8 (avoids hang during compilation) +locale-gen en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 + +# add zulu apt repository - https://docs.azul.com/core/install/debian +curl -s https://repos.azul.com/azul-repo.key | gpg --dearmor -o /usr/share/keyrings/azul.gpg +echo "deb [signed-by=/usr/share/keyrings/azul.gpg] https://repos.azul.com/zulu/deb stable main" | tee /etc/apt/sources.list.d/zulu.list +apt-get -q update +# install zulu JDK and Java build tools +apt-get -yq install zulu17-jdk-headless maven ant + +# Install cross-compilation toolchains +apt-get -yq --force-yes install gcc g++ +apt-get -yq --force-yes install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross +apt-get -yq --force-yes install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross +apt-get -yq --force-yes install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross + +# Build Linux natives +./gradlew jniGen jnigenBuildLinux64 jnigenBuildLinuxARM jnigenBuildLinuxARM64 jnigenBuildLinuxRISCV64 --no-daemon + +# Pack artifacts +find . -name "*.a" -o -name "*.dll" -o -name "*.dylib" -o -name "*.so" | grep "libs" > native-files-list +zip natives-linux -@ < native-files-list \ No newline at end of file diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index 6692a968dd4..617db78a0c8 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -8,9 +8,6 @@ on: release: types: [ published ] -env: - ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true - jobs: natives-ios: @@ -92,65 +89,15 @@ jobs: natives-linux: runs-on: ubuntu-20.04 - container: - image: ubuntu:18.04 steps: - - name: Install dependencies into minimal dockerfile - run: | - # ubuntu dockerfile is very minimal (only 122 packages are installed) - # need to install updated git (from official git ppa) - apt update - apt install -y software-properties-common - add-apt-repository ppa:git-core/ppa -y - # install dependencies expected by other steps - apt update - apt install -y git \ - curl \ - ca-certificates \ - wget \ - bzip2 \ - zip \ - unzip \ - xz-utils \ - maven \ - ant sudo locales - - # set Locale to en_US.UTF-8 (avoids hang during compilation) - locale-gen en_US.UTF-8 - echo "LANG=en_US.UTF-8" >> $GITHUB_ENV - echo "LANGUAGE=en_US.UTF-8" >> $GITHUB_ENV - echo "LC_ALL=en_US.UTF-8" >> $GITHUB_ENV - - uses: actions/checkout@v2 with: fetch-depth: 0 submodules: 'recursive' - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '17' - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - - - name: Install cross-compilation toolchains - run: | - sudo apt update - sudo apt install -y --force-yes gcc g++ - sudo apt install -y --force-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross - sudo apt install -y --force-yes gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross - sudo apt install -y --force-yes gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross - - - name: Build Linux natives - run: | - ./gradlew jniGen jnigenBuildLinux64 jnigenBuildLinuxARM jnigenBuildLinuxARM64 jnigenBuildLinuxRISCV64 - - - name: Pack artifacts - run: | - find . -name "*.a" -o -name "*.dll" -o -name "*.dylib" -o -name "*.so" | grep "libs" > native-files-list - zip natives-linux -@ < native-files-list + - name: Build Linux Natives in Docker Container + uses: ./.github/actions/build-linux-natives + id: docker - name: Upload artifacts uses: actions/upload-artifact@v3