Skip to content

Commit 24708b3

Browse files
committed
feat: add test for get_nfpm_arch
1 parent 0609a1b commit 24708b3

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

ci/build/arch-override.json

-8
This file was deleted.

ci/build/build-lib.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a library which contains functions used inside ci/build
4+
#
5+
# We separated it into it's own file so that we could easily unit test
6+
# these functions and helpers.
7+
8+
# On some CPU architectures (notably node/uname "armv7l", default on Raspberry Pis),
9+
# different package managers have different labels for the same CPU (deb=armhf, rpm=armhfp).
10+
# This function returns the overriden arch on platforms
11+
# with alternate labels, or the same arch otherwise.
12+
get_nfpm_arch() {
13+
case "$ARCH" in
14+
armv7l)
15+
if [ "$PKG_FORMAT" = "deb" ]; then
16+
echo armhf
17+
elif [ "$PKG_FORMAT" = "rpm" ]; then
18+
echo armhfp
19+
fi
20+
;;
21+
*)
22+
echo "$ARCH"
23+
;;
24+
esac
25+
}

ci/build/build-packages.sh

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -euo pipefail
77
main() {
88
cd "$(dirname "${0}")/../.."
99
source ./ci/lib.sh
10+
source ./ci/build/build-lib.sh
1011

1112
# Allow us to override architecture
1213
# we use this for our Linux ARM64 cross compile builds
@@ -43,18 +44,6 @@ release_gcp() {
4344
cp "./release-packages/$release_name.tar.gz" "./release-gcp/latest/$OS-$ARCH.tar.gz"
4445
}
4546

46-
# On some CPU architectures (notably node/uname "armv7l", default on Raspberry Pis),
47-
# different package managers have different labels for the same CPU (deb=armhf, rpm=armhfp).
48-
# This function parses arch-override.json and returns the overriden arch on platforms
49-
# with alternate labels, or the same arch otherwise.
50-
get_nfpm_arch() {
51-
if jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json > /dev/null; then
52-
jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json
53-
else
54-
echo "$ARCH"
55-
fi
56-
}
57-
5847
# Generates deb and rpm packages.
5948
release_nfpm() {
6049
local nfpm_config

test/scripts/build-lib.bats

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bats
2+
3+
SCRIPT_NAME="build-lib.sh"
4+
SCRIPT="$BATS_TEST_DIRNAME/../../ci/build/$SCRIPT_NAME"
5+
6+
source "$SCRIPT"
7+
8+
@test "get_nfpm_arch should return armhfp for rpm on armv7l" {
9+
PKG_FORMAT="rpm" ARCH="armv7l" run get_nfpm_arch
10+
[ "$output" = "armhfp" ]
11+
}
12+
13+
@test "get_nfpm_arch should return armhf for deb on armv7l" {
14+
PKG_FORMAT="deb" ARCH="armv7l" run get_nfpm_arch
15+
[ "$output" = "armhf" ]
16+
}
17+
18+
@test "get_nfpm_arch should return arch if no arch override exists " {
19+
PKG_FORMAT="deb" ARCH="i386" run get_nfpm_arch
20+
[ "$output" = "i386" ]
21+
}

0 commit comments

Comments
 (0)