Skip to content

Commit 4f3c8a5

Browse files
authored
Merge pull request #4194 from cdr/jsjoeio-add-sh-test
feat: add test for get_nfpm_arch()
2 parents 0609a1b + 6a69248 commit 4f3c8a5

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

ci/build/arch-override.json

-8
This file was deleted.

ci/build/build-lib.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
local PKG_FORMAT="${1:-}"
14+
local ARCH="${2:-}"
15+
16+
case "$ARCH" in
17+
armv7l)
18+
if [ "$PKG_FORMAT" = "deb" ]; then
19+
echo armhf
20+
elif [ "$PKG_FORMAT" = "rpm" ]; then
21+
echo armhfp
22+
fi
23+
;;
24+
*)
25+
echo "$ARCH"
26+
;;
27+
esac
28+
}

ci/build/build-packages.sh

+3-14
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,33 +44,21 @@ 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
6150

6251
export NFPM_ARCH
6352

6453
PKG_FORMAT="deb"
65-
NFPM_ARCH="$(get_nfpm_arch)"
54+
NFPM_ARCH="$(get_nfpm_arch $PKG_FORMAT "$ARCH")"
6655
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
6756
echo "Building deb"
6857
echo "$nfpm_config" | head --lines=4
6958
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server_${VERSION}_${NFPM_ARCH}.deb"
7059

7160
PKG_FORMAT="rpm"
72-
NFPM_ARCH="$(get_nfpm_arch)"
61+
NFPM_ARCH="$(get_nfpm_arch $PKG_FORMAT "$ARCH")"
7362
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
7463
echo "Building rpm"
7564
echo "$nfpm_config" | head --lines=4

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+
run get_nfpm_arch rpm armv7l
10+
[ "$output" = "armhfp" ]
11+
}
12+
13+
@test "get_nfpm_arch should return armhf for deb on armv7l" {
14+
run get_nfpm_arch deb armv7l
15+
[ "$output" = "armhf" ]
16+
}
17+
18+
@test "get_nfpm_arch should return arch if no arch override exists " {
19+
run get_nfpm_arch deb i386
20+
[ "$output" = "i386" ]
21+
}

0 commit comments

Comments
 (0)