Skip to content

Commit c8255f7

Browse files
Merge pull request #2500 from craigcomstock/macos-pkg
ent-9880: package cfengine client for macos
2 parents cf7ae53 + 56fb586 commit c8255f7

48 files changed

Lines changed: 1671 additions & 24 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build MacOS community client pkg files
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: read
9+
10+
jobs:
11+
macos_package:
12+
name: Build a CFEngine community agent pkg file for MacOS
13+
strategy:
14+
matrix:
15+
os: [macos-26-intel, macos-latest]
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- name: Checkout Together Action
19+
uses: actions/checkout@v3
20+
with:
21+
repository: cfengine/together-javascript-action
22+
ref: main
23+
ssh-key: ${{ secrets.GH_ACTIONS_SSH_DEPLOY_KEY_TOGETHER_REPO }}
24+
ssh-known-hosts: github.com
25+
26+
- name: Action step
27+
uses: ./
28+
id: together
29+
with:
30+
myToken: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Checkout Core
33+
uses: actions/checkout@v3
34+
with:
35+
repository: cfengine/core
36+
path: core
37+
ref: ${{steps.together.outputs.core || github.base_ref}}
38+
submodules: recursive
39+
40+
- name: Checkout Masterfiles
41+
uses: actions/checkout@v3
42+
with:
43+
repository: cfengine/masterfiles
44+
path: masterfiles
45+
ref: ${{steps.together.outputs.masterfiles || github.base_ref}}
46+
47+
- name: Checkout Buildscripts
48+
uses: actions/checkout@v3
49+
with:
50+
path: buildscripts
51+
52+
- name: Build package natively
53+
id: build_package
54+
run: |
55+
./buildscripts/ci/build-macos.sh
56+
57+
- name: Save artifacts
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: macos-package-artifact
61+
path: /Users/runner/work/buildscripts/buildscripts/cfengine-community

‎build-scripts/compile-options‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ solaris)
7474
export CFLAGS
7575
fi
7676
;;
77+
darwin)
78+
# Apple's linker (ld64) doesn't understand the GNU/Solaris "-R" rpath
79+
# spelling used in the default case below, it needs "-rpath" instead.
80+
LDFLAGS="-L$BUILDPREFIX/lib -Wl,-rpath,$BUILDPREFIX/lib"
81+
;;
7782
*)
7883
LDFLAGS="-L$BUILDPREFIX/lib -Wl,-R$BUILDPREFIX/lib"
7984
;;
@@ -144,7 +149,7 @@ var_append DEPS "librsync" # Library for synchronization of file
144149

145150
# coreutils is only built for redhat/debian/windows for now
146151
case "$OS_FAMILY" in
147-
hpux | aix | solaris | freebsd) ;;
152+
hpux | aix | solaris | freebsd | darwin) ;;
148153
*)
149154
var_append DEPS "coreutils" # Provides a standalone 'date' binary
150155
;;
@@ -167,7 +172,7 @@ esac
167172

168173
# Non-exotics dependencies
169174
case "$OS_FAMILY" in
170-
hpux | aix | solaris | freebsd | mingw) ;;
175+
hpux | aix | solaris | freebsd | mingw | darwin) ;;
171176
*)
172177
# Library for managing Extended Attributes (xattrs) on filesystems
173178
var_append DEPS "libattr"
@@ -257,7 +262,9 @@ esac
257262

258263
# Determine whether or not to run tests
259264
case "$OS_FAMILY" in
260-
mingw | freebsd) TESTS=no ;;
265+
# Test suites for the bundled dependencies aren't yet verified to pass on
266+
# macOS, so play it safe like the other newer/less-trodden platforms.
267+
mingw | freebsd | darwin) TESTS=no ;;
261268
*) TESTS=all ;;
262269
esac
263270
export TESTS

‎build-scripts/detect-environment‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ detect_os() {
7070
Darwin)
7171
OS_FAMILY=darwin
7272
OS=darwin
73+
OS_VERSION=$(sw_vers -productVersion)
7374
;;
7475
FreeBSD)
7576
OS_FAMILY=freebsd
@@ -236,7 +237,15 @@ detect_distribution() {
236237
# detected, then the "pkg-build-rpm" script will be called from the
237238
# "install-dependencies" script.
238239
detect_packaging() {
239-
if [ -f /bin/rpm ]; then
240+
if [ "$UNAME_S" = Darwin ]; then
241+
# macOS has no package manager suitable for the iterative
242+
# build-then-install-locally workflow the other DEP_PACKAGING values
243+
# use (rpm/dpkg/pkg_add/etc all maintain a real system package
244+
# database). pkg-build-macos/pkg-find-macos/pkg-install-macos use a
245+
# plain tarball format with their own lightweight file-registry
246+
# instead, see deps-packaging/pkg-install-macos.
247+
DEP_PACKAGING=macos
248+
elif [ -f /bin/rpm ]; then
240249
DEP_PACKAGING=rpm
241250
elif [ -f /usr/bin/dpkg ]; then
242251
DEP_PACKAGING=deb
@@ -262,6 +271,9 @@ detect_packaging() {
262271
mingw)
263272
PACKAGING=msi
264273
;;
274+
darwin)
275+
PACKAGING=macos
276+
;;
265277
*)
266278
PACKAGING=$DEP_PACKAGING
267279
;;
@@ -302,6 +314,10 @@ detect_arch() {
302314
hpux)
303315
ARCH=$UNAME_M
304316
;;
317+
macos)
318+
# arm64 on Apple Silicon, x86_64 on Intel Macs.
319+
ARCH=$UNAME_M
320+
;;
305321
*)
306322
log_error "Unknown packaging system"
307323
exit 42
@@ -373,6 +389,9 @@ detect_cores() {
373389
hpux)
374390
NUM_CORES="$(ioscan -k -C processor | grep -c processor)"
375391
;;
392+
darwin)
393+
NUM_CORES="$(sysctl -n hw.ncpu)"
394+
;;
376395
*)
377396
log_debug "Detected OS family is UNKNOWN, defaulting amount of CPU cores to 1"
378397
NUM_CORES=1

‎build-scripts/functions‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ uninstall_freebsd_pkgs() {
221221
fi
222222
}
223223

224+
# uninstall_macos_pkgs: Remove macOS build-dependency packages matching a
225+
# pattern. There's no system package manager suitable for our iterative
226+
# build/install-locally workflow on macOS, so pkg-build-macos/pkg-install-macos
227+
# track installed files themselves in a flat-file registry (see
228+
# deps-packaging/pkg-install-macos) instead of using a real package database.
229+
# Args:
230+
# $1 - Package name pattern (regex)
231+
uninstall_macos_pkgs() {
232+
REGISTRY="$BASEDIR/.cfbuild-macos-db"
233+
[ -d "$REGISTRY" ] || return 0
234+
for filelist in "$REGISTRY"/*.filelist; do
235+
[ -e "$filelist" ] || continue
236+
name=$(basename "$filelist" .filelist)
237+
echo "$name" | grep_q "^$1\$" || continue
238+
while IFS= read -r f; do
239+
rm -f "/$f"
240+
done <"$filelist"
241+
rm -f "$filelist"
242+
done
243+
}
244+
224245
# uninstall_cfbuild: Remove all cfbuild packages (runtime and devel)
225246
# Uses the appropriate uninstall function based on $DEP_PACKAGING
226247
uninstall_cfbuild() {
@@ -230,6 +251,7 @@ uninstall_cfbuild() {
230251
solaris) uninstall_solaris_pkgs 'cfbuild-.*' ;;
231252
freebsd) uninstall_freebsd_pkgs 'cfbuild-.*' ;;
232253
hpux) uninstall_hpux_pkgs 'cfbuild-.*' ;;
254+
macos) uninstall_macos_pkgs 'cfbuild-.*' ;;
233255
*)
234256
log_error "Unknown packaging system: $DEP_PACKAGING"
235257
exit 1
@@ -243,6 +265,7 @@ uninstall_cfbuild_devel() {
243265
case "$DEP_PACKAGING" in
244266
rpm) uninstall_rpms 'cfbuild-.*-devel' ;;
245267
deb) uninstall_debs 'cfbuild-.*-devel' ;;
268+
macos) uninstall_macos_pkgs 'cfbuild-.*-devel' ;;
246269
solaris) uninstall_solaris_pkgs 'cfbuild-.*-devel' ;;
247270
freebsd) uninstall_freebsd_pkgs 'cfbuild-.*-devel' ;;
248271
hpux) uninstall_hpux_pkgs 'cfbuild-.*-devel' ;;
@@ -651,6 +674,7 @@ func_sha256() {
651674
case "$UNAME_S" in
652675
SunOS) digest -a sha256 "$@" ;;
653676
AIX) openssl dgst -sha256 "$@" | cut -d ' ' -f 2 ;;
677+
Darwin) shasum -a 256 "$@" | cut -d ' ' -f 1 ;;
654678
*) fatal "Can't find command for computing SHA-256" ;;
655679
esac
656680
fi
@@ -700,8 +724,11 @@ retry_wrapper() {
700724
else
701725
err_ret=$?
702726
# in case say dpkg locks are held by automatic updates or something
727+
# -P is a GNU grep extension (missing on e.g. macOS' BSD grep), and
728+
# this is diagnostic-only, so use portable -E and never let it trip
729+
# "set -e" when nothing matches.
703730
# shellcheck disable=SC2009
704-
ps -efl | grep -P '(apt|dpkg|yum|dnf|zypper|rpm|pkg)'
731+
ps -ef | grep -E '(apt|dpkg|yum|dnf|zypper|rpm|pkg)' || true
705732
maxtries=$((maxtries - 1))
706733
echo "* FAILURE $err_ret"
707734
echo "* Sleeping for: $pause seconds"

0 commit comments

Comments
 (0)