1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 20:55:25 +00:00

feat: add test for get_nfpm_arch

This commit is contained in:
Joe Previte 2021-09-16 16:19:10 -07:00
parent 0609a1b2bd
commit 6a692487c8
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24
4 changed files with 52 additions and 22 deletions

View File

@ -1,8 +0,0 @@
{
"rpm": {
"armv7l": "armhfp"
},
"deb": {
"armv7l": "armhf"
}
}

28
ci/build/build-lib.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
# This is a library which contains functions used inside ci/build
#
# We separated it into it's own file so that we could easily unit test
# these functions and helpers.
# On some CPU architectures (notably node/uname "armv7l", default on Raspberry Pis),
# different package managers have different labels for the same CPU (deb=armhf, rpm=armhfp).
# This function returns the overriden arch on platforms
# with alternate labels, or the same arch otherwise.
get_nfpm_arch() {
local PKG_FORMAT="${1:-}"
local ARCH="${2:-}"
case "$ARCH" in
armv7l)
if [ "$PKG_FORMAT" = "deb" ]; then
echo armhf
elif [ "$PKG_FORMAT" = "rpm" ]; then
echo armhfp
fi
;;
*)
echo "$ARCH"
;;
esac
}

View File

@ -7,6 +7,7 @@ set -euo pipefail
main() {
cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
source ./ci/build/build-lib.sh
# Allow us to override architecture
# we use this for our Linux ARM64 cross compile builds
@ -43,18 +44,6 @@ release_gcp() {
cp "./release-packages/$release_name.tar.gz" "./release-gcp/latest/$OS-$ARCH.tar.gz"
}
# On some CPU architectures (notably node/uname "armv7l", default on Raspberry Pis),
# different package managers have different labels for the same CPU (deb=armhf, rpm=armhfp).
# This function parses arch-override.json and returns the overriden arch on platforms
# with alternate labels, or the same arch otherwise.
get_nfpm_arch() {
if jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json > /dev/null; then
jq -re ".${PKG_FORMAT}.${ARCH}" ./ci/build/arch-override.json
else
echo "$ARCH"
fi
}
# Generates deb and rpm packages.
release_nfpm() {
local nfpm_config
@ -62,14 +51,14 @@ release_nfpm() {
export NFPM_ARCH
PKG_FORMAT="deb"
NFPM_ARCH="$(get_nfpm_arch)"
NFPM_ARCH="$(get_nfpm_arch $PKG_FORMAT "$ARCH")"
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
echo "Building deb"
echo "$nfpm_config" | head --lines=4
nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server_${VERSION}_${NFPM_ARCH}.deb"
PKG_FORMAT="rpm"
NFPM_ARCH="$(get_nfpm_arch)"
NFPM_ARCH="$(get_nfpm_arch $PKG_FORMAT "$ARCH")"
nfpm_config="$(envsubst < ./ci/build/nfpm.yaml)"
echo "Building rpm"
echo "$nfpm_config" | head --lines=4

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bats
SCRIPT_NAME="build-lib.sh"
SCRIPT="$BATS_TEST_DIRNAME/../../ci/build/$SCRIPT_NAME"
source "$SCRIPT"
@test "get_nfpm_arch should return armhfp for rpm on armv7l" {
run get_nfpm_arch rpm armv7l
[ "$output" = "armhfp" ]
}
@test "get_nfpm_arch should return armhf for deb on armv7l" {
run get_nfpm_arch deb armv7l
[ "$output" = "armhf" ]
}
@test "get_nfpm_arch should return arch if no arch override exists " {
run get_nfpm_arch deb i386
[ "$output" = "i386" ]
}