Skip to content

Commit

Permalink
Move build from workflow job to container action
Browse files Browse the repository at this point in the history
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 (libgdx/Jamepad#34)
  • Loading branch information
SonicGDX committed Dec 15, 2024
1 parent 9b704b8 commit 55868b5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
8 changes: 8 additions & 0 deletions .github/actions/build-linux-natives/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions .github/actions/build-linux-natives/action.yml
Original file line number Diff line number Diff line change
@@ -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'
44 changes: 44 additions & 0 deletions .github/actions/build-linux-natives/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
59 changes: 3 additions & 56 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ on:
release:
types: [ published ]

env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:

natives-ios:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55868b5

Please sign in to comment.