Skip to content

Commit ecaa930

Browse files
authored
Merge pull request #5919 from craigcomstock/ENT-13016-install/master
Refactored github workflows to use a shared dependencies script to ease maintenance of workflows
2 parents 1a1348e + 081fef1 commit ecaa930

File tree

10 files changed

+56
-25
lines changed

10 files changed

+56
-25
lines changed

.github/workflows/acceptance_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
with:
1212
submodules: recursive
1313
- name: Install dependencies
14-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl libyaml-dev librsync-dev
14+
run: ./ci/dependencies.sh
1515
- name: Run autotools / configure
1616
run: ./autogen.sh --enable-debug
1717
- name: Compile and link (make)

.github/workflows/asan_unit_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
with:
1212
submodules: recursive
1313
- name: Install dependencies
14-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl librsync-dev
14+
run: ./ci/dependencies.sh
1515
- name: Run autotools / configure
1616
run: ./autogen.sh --enable-debug
1717
- name: Compile and link (make)

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Install dependencies (C)
4343
if: ${{ matrix.language == 'cpp' }}
44-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl librsync-dev
44+
run: ./ci/dependencies.sh
4545

4646
- name: Build (C)
4747
if: ${{ matrix.language == 'cpp' }}

.github/workflows/shellcheck.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
with:
1313
submodules: recursive
1414
- name: Install dependencies
15-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl shellcheck librsync-dev
15+
run: |
16+
./ci/dependencies.sh
17+
sudo apt install -y shellcheck
1618
- name: Run autotools / configure
1719
run: ./autogen.sh --enable-debug
1820
- name: Run shellcheck

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
with:
1313
submodules: recursive
1414
- name: Install dependencies
15-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl librsync-dev
15+
run: ./ci/dependencies.sh
1616
- name: Run autotools / configure
1717
run: ./autogen.sh --enable-debug
1818
- name: Compile and link (make)

.github/workflows/valgrind.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
path: masterfiles
2828
submodules: recursive
2929
- name: Install dependencies
30-
run: sudo apt-get update -y && sudo apt-get install -y libssl-dev libpam0g-dev liblmdb-dev byacc curl libyaml-dev valgrind librsync-dev
30+
run: |
31+
./ci/dependencies.sh
32+
sudo apt install -y valgrind
3133
- name: Run autotools / configure
3234
run: ./autogen.sh --enable-debug --with-systemd-service
3335
- name: Compile and link (make)

ci/build.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
#!/usr/bin/env bash
2-
# build.sh runs autogen/configure and then builds CFEngine core
2+
# build.sh runs after dependencies and configure scripts and builds CFEngine core
33
# the script should take into account the operating system environment and adjust, such as --without-pam on termux, BSDs and such
44
set -ex
55
thisdir="$(dirname "$0")"
66
cd "$thisdir"/..
7-
OPTS="--enable-debug"
87

9-
if [ -n "$TERMUX_VERSION" ]; then
10-
OPTS="$OPTS --without-pam"
11-
fi
12-
13-
./autogen.sh $OPTS
14-
make
8+
make -j8 CFLAGS="-Werror -Wall"

ci/configure.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# configure.sh runs autotools/configure as appropriate for the current environment
3+
# the script should take into account the operating system environment and adjust, such as --without-pam on termux, BSDs and such
4+
set -ex
5+
thisdir="$(dirname "$0")"
6+
cd "$thisdir"/..
7+
OPTS="--enable-debug"
8+
9+
if [ -n "$TERMUX_VERSION" ]; then
10+
OPTS="$OPTS --without-pam"
11+
fi
12+
13+
./autogen.sh $OPTS

ci/dependencies.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/usr/bin/env bash
22
# dependencies.sh is called by install.sh to install libraries and packages needed to build and install CFEngine from source.
33
set -ex
4+
5+
GAINROOT=""
6+
if [ "$(id -u)" != "0" ]; then
7+
GAINROOT="sudo"
8+
if ! command -v sudo >/dev/null; then
9+
echo "Sorry, either run $0 as root or install sudo."
10+
exit 1
11+
fi
12+
fi
13+
414
# limited support here, focused on rhel-like on aarch64 which has no previous CFEngine version to leverage: ENT-13016
515
if [ -f /etc/os-release ]; then
616
source /etc/os-release
@@ -9,38 +19,41 @@ if [ -f /etc/os-release ]; then
919
if [ "$VERSION_MAJOR" -ge "10" ]; then
1020
# note that having a redhat subscription makes things easier: lmdb-devel and librsync-devel are available from codeready-builder repo
1121
if subscription-manager status; then
12-
sudo subscription-manager config --rhsm.manage_repos=1
13-
sudo subscription-manager repos --enable codeready-builder-for-rhel-"$VERSION_MAJOR"-"$(uname -m)"-rpms
14-
sudo dnf install --assumeyes https://dl.fedoraproject.org/pub/epel/epel-release-latest-"$VERSION_MAJOR".noarch.rpm
15-
sudo dnf install --assumeyes flex-devel lmdb-devel librsync-devel fakeroot # only available via subscription with codeready-builder installed
22+
$GAINROOT subscription-manager config --rhsm.manage_repos=1
23+
$GAINROOT subscription-manager repos --enable codeready-builder-for-rhel-"$VERSION_MAJOR"-"$(uname -m)"-rpms
24+
$GAINROOT dnf install --assumeyes https://dl.fedoraproject.org/pub/epel/epel-release-latest-"$VERSION_MAJOR".noarch.rpm
25+
$GAINROOT dnf install --assumeyes flex-devel lmdb-devel librsync-devel fakeroot # only available via subscription with codeready-builder installed
1626
# flex-devel, libyaml-devel and fakeroot are also only available easily from codeready-builder but are not critical to building CFEngine usable enough to configure a build host.
1727
# fakeroot is only needed for running tests but can be worked around by using GAINROOT=env with tests/acceptance/testall script
1828
else
1929
# here we assume no subscription and so must build those two dependencies from source :)
20-
sudo yum groups install -y 'Development Tools'
21-
sudo yum update --assumeyes
22-
sudo yum install -y gcc gdb make git libtool autoconf automake byacc flex openssl-devel pcre2-devel pam-devel libxml2-devel
30+
$GAINROOT yum groups install -y 'Development Tools'
31+
$GAINROOT yum update --assumeyes
32+
$GAINROOT yum install -y gcc gdb make git libtool autoconf automake byacc flex openssl-devel pcre2-devel pam-devel libxml2-devel
2333
tmpdir="$(mktemp -d)"
2434
echo "Building lmdb and librsync in $tmpdir"
2535
(
2636
cd "$tmpdir"
2737
git clone --recursive --depth 1 https://github.com/LMDB/lmdb
2838
cd lmdb/libraries/liblmdb
2939
make
30-
sudo make install prefix=/usr
40+
$GAINROOT make install prefix=/usr
3141
cd -
32-
sudo dnf install -y cmake
42+
$GAINROOT dnf install -y cmake
3343
git clone --recursive --depth 1 https://github.com/librsync/librsync
3444
cd librsync
3545
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release .
3646
make
37-
sudo make install
47+
$GAINROOT make install
3848
)
3949
fi
4050
else
4151
echo "Unsupported version of redhat for $0"
4252
exit 1
4353
fi
54+
elif [ "$ID" = "debian" ] || [[ "$ID_LIKE" =~ "debian" ]]; then
55+
$GAINROOT apt update -y
56+
$GAINROOT apt install -y build-essential git libtool autoconf automake bison flex libssl-dev libpcre2-dev libbison-dev libacl1 libacl1-dev lmdb-utils liblmdb-dev libpam0g-dev libtool libyaml-dev libxml2-dev librsync-dev
4457
else
4558
echo "Unsupported distribution based on /etc/os-release."
4659
fi

ci/install.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
set -ex
44
thisdir=$(dirname $0)
55
"$thisdir"/dependencies.sh
6+
"$thisdir"/configure.sh
67
"$thisdir"/build.sh
78
cd "$thisdir"/..
89
GAINROOT=""
910
if [ ! -n "$TERMUX_VERSION" ]; then
10-
GAINROOT="sudo"
11+
if [ "$(id -u)" != "0" ]; then
12+
if ! command -v sudo >/dev/null; then
13+
echo "Sorry, run $0 as root or install and configure sudo."
14+
exit 1
15+
fi
16+
GAINROOT="sudo"
17+
fi
1118
fi
1219

1320
$GAINROOT make install

0 commit comments

Comments
 (0)