Skip to content

zlib-ng crossbuild package release #1

zlib-ng crossbuild package release

zlib-ng crossbuild package release #1

name: zlib-ng crossbuild package release
on:
workflow_dispatch:
inputs:
skip_rerun:
description: "Skip rerun?"
required: true
default: true
type: boolean
retries:
description: "Number of rerun retries"
required: true
default: "1"
type: choice
options: ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
outputs:
zlib_ng_v1: ${{ steps.version_info.outputs.zlib_ng_v1 }}
zlib_ng_v2: ${{ steps.version_info.outputs.zlib_ng_v2 }}
strategy:
fail-fast: false
matrix:
name: [zlib-ng]
os_id: [debian, ubuntu]
os_codename: [bullseye, bookworm, focal, jammy, noble]
arch: [amd64, armhf, arm64]
zlib_compat: ["", "-D ZLIB_COMPAT=ON"]
include:
- zlib_compat: ""
pretty_name: v2
header_name: ZLIBNG_VERSION
- zlib_compat: "-D ZLIB_COMPAT=ON"
pretty_name: v1
header_name: ZLIB_VERSION
exclude:
- os_id: debian
os_codename: focal
- os_id: debian
os_codename: jammy
- os_id: debian
os_codename: noble
- os_id: ubuntu
os_codename: bullseye
- os_id: ubuntu
os_codename: bookworm
name: ${{ matrix.os_id }}:${{ matrix.os_codename }} ${{ matrix.name }}${{ matrix.pretty_name }} ${{ matrix.arch }}
env:
opt_dir_name: "opt/local"
github_branch: "develop"
cxx_standard: "17"
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- name: Host - Checkout action
uses: actions/checkout@v4
# Fix this bug https://github.com/actions/runner-images/issues/7192
- name: Host - phased updates
run: printf '%s\n' 'APT::Get::Always-Include-Phased-Updates "false";' | sudo tee /etc/apt/apt.conf.d/99-phased-updates
- name: Host - update
run: sudo apt-get update
- name: Host - upgrade
run: sudo apt-get -y upgrade
# No action or other method to bootstrap binfmt-support and qemu-user-static on the host runner
- name: Host - set up qemu-user-static binfmt-support
run: sudo apt install libpipeline1 qemu-user-static binfmt-support
# Why are we doing it like this and not using a container setup? That's how you're supposed to do it, right?
# qemu-user-static and binfmt-support are not part of the runner images https://github.com/actions/runner-images?tab=readme-ov-file#available-images
# We would need to modify the runner to install these before the container starts. Which you cannot do as there is no way to bootstrap the host.
# So we install them on the host then create/pull a custom docker image that we use to build the multiarch targets.
# We are always on the host runner but can use any docker image we need with the access the qemu emulation when required.
#
# We are using these pre configured toolchain images that allows me to remove 50% of the code/time from this action.
#
# https://github.com/userdocs/dcb/blob/main/Dockerfile
#
# The image does not run as root and has password-less sudo. There are two users username:1000 /home/username and github:1001 /home/github
# In the action it runs as 1001 /home/github and files should be available to the host. For local use, you might need -u 1000
- name: Host - Create docker multiarch ${{ matrix.arch }} container
run: docker run --name multiarch -it -d -u 1001 -v ${{ github.workspace }}:/home/github ghcr.io/userdocs/dcb:${{ matrix.os_id }}-${{ matrix.os_codename }}-${{ matrix.arch }}
- name: Docker - cmake and ninja download and install
run: |
docker exec multiarch curl -sNL "https://github.com/userdocs/cmake-crossbuild/releases/latest/download/${{ matrix.os_id }}-${{ matrix.os_codename }}-cmake-${{ matrix.arch }}.deb" -o ${{ matrix.os_id }}-${{ matrix.os_codename }}-cmake-${{ matrix.arch }}.deb
docker exec multiarch sudo dpkg -i ${{ matrix.os_id }}-${{ matrix.os_codename }}-cmake-${{ matrix.arch }}.deb
- name: Host - Git clone ${{ matrix.name }} ${{ env.github_branch }}
run: git clone --single-branch --branch "${{ env.github_branch }}" --shallow-submodules --recurse-submodules --depth 1 https://github.com/zlib-ng/zlib-ng.git ${{ matrix.name }}
- name: Host - Set ${{ matrix.name }} version to variable
id: version_info
run: |
zlib_ng_version="$(cat ${{ matrix.name }}/zlib.h.in | sed -rn 's|#define ${{ matrix.header_name }} "(.*)"|\1|p' | sed 's/\.[^.]*$//')"
printf '%s\n' "zlib_ng_version=${zlib_ng_version}" >> $GITHUB_ENV
printf '%s\n' "zlib_ng_${{ matrix.pretty_name }}=${zlib_ng_version}" >> $GITHUB_OUTPUT
- name: Docker - ${{ matrix.name }} configure
run: >
docker exec -w /home/github/${{ matrix.name }} multiarch cmake -Wno-dev -Wno-deprecated -G Ninja -B build
${{ matrix.zlib_compat }}
-D CMAKE_VERBOSE_MAKEFILE="ON"
-D CMAKE_CXX_STANDARD="${{ env.cxx_standard }}"
-D CMAKE_INSTALL_PREFIX="/home/github/build/${{ env.opt_dir_name }}"
- name: Docker - ${{ matrix.name }} - cmake build
run: docker exec -w /home/github/${{ matrix.name }} multiarch cmake --build build
- name: Docker - ${{ matrix.name }} - cmake install
run: docker exec -w /home/github/${{ matrix.name }} multiarch cmake --install build
- name: Docker - Set deb dependencies for ${{ matrix.name }}
run: printf '%s\n' "zlib-ng-deb-deps=none" >> $GITHUB_ENV
- name: Docker - ldconfig - create /etc/ld.so.conf.d/zlib-ng.conf
run: |
docker exec -w /home/github/build multiarch mkdir -p etc/ld.so.conf.d
docker exec -w /home/github/build/etc/ld.so.conf.d multiarch bash -c "printf '%s\n' '/${{ env.opt_dir_name }}/lib' > zlib-ng.conf"
- name: Host - Create deb packages
uses: jiro4989/build-deb-action@v3
with:
package: "${{ matrix.name }}"
package_root: build
maintainer: userdocs
compress_type: gzip
version: "${{ env.zlib_ng_version }}"
depends: "${{ env.zlib-ng-deb-deps }}"
arch: "${{ matrix.arch }}"
desc: "${{ matrix.name }}-${{ env.zlib_ng_version }}-${{ matrix.arch }} for ${{ matrix.os_id }}-${{ matrix.os_codename }}"
- name: Host - Remove version from release name and use hyphens
run: mv -f "${{ matrix.name }}_${{ env.zlib_ng_version }}_${{ matrix.arch }}.deb" "${{ matrix.os_id }}-${{ matrix.os_codename }}-${{ matrix.name }}-${{ matrix.arch }}.deb"
- name: Host - upload artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.pretty_name }}-${{ matrix.os_id }}-${{ matrix.os_codename }}-${{ matrix.name }}-${{ matrix.arch }}-deb"
path: "${{ matrix.os_id }}-${{ matrix.os_codename }}-${{ matrix.name }}-${{ matrix.arch }}.deb"
release:
name: Upload artifacts to release
runs-on: ubuntu-latest
needs: build
if: always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
strategy:
fail-fast: false
matrix:
name: [zlib-ng]
zlib_ng_version: ["v1", "v2"]
include:
- zlib_ng_version: "v1"
prerelease: false
- zlib_ng_version: "v2"
prerelease: true
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
zlib_ng_v1: "${{ needs.build.outputs.zlib_ng_v1 }}"
zlib_ng_v2: "${{ needs.build.outputs.zlib_ng_v2 }}"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Host - Download artifacts
uses: actions/download-artifact@v4
- name: Host - v1 artifacts organise for release
if: matrix.zlib_ng_version == 'v1'
run: |
mkdir -p "releases"
for files in v1-*-deb; do
cp -rf ${files}/* "releases/"
done
printf '%s\n' "zlib_ng_version=${{ env.zlib_ng_v1 }}" >> $GITHUB_ENV
- name: Host - v2 artifacts organise for release
if: matrix.zlib_ng_version == 'v2'
run: |
mkdir -p "releases"
for files in v2-*-deb; do
cp -rf ${files}/* "releases/"
done
printf '%s\n' "zlib_ng_version=${{ env.zlib_ng_v2 }}" >> $GITHUB_ENV
- name: Host - "Create release - tag - assets"
uses: ncipollo/release-action@v1
with:
prerelease: ${{ matrix.prerelease }}
artifacts: releases/*.deb
replacesArtifacts: true
tag: "${{ env.zlib_ng_version }}"
name: "${{ matrix.name }} ${{ env.zlib_ng_version }}"
body: "${{ matrix.name }} built from github master on amd64 arm64 armhf for Debian Bullseye Bookworm and Ubuntu Focal Jammy Noble"
allowUpdates: true
rerun-on-failure:
if: failure() && inputs.skip_rerun == '0'
name: rerun-on-failure
needs: release
permissions:
actions: write
runs-on: ubuntu-latest
env:
GH_TOKEN: "${{ github.TOKEN }}"
steps:
- uses: actions/checkout@v4
- name: Trigger rerun workflow on job failures
run: |
inputs_retries="${{ inputs.retries }}"
gh workflow run rerun.yml -f run_id=${{ github.run_id }} -f attempts=${{ github.run_attempt }} -f retries=${inputs_retries:-1}