Skip to content

feat: add test for get_nfpm_arch() #4194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ci/build/arch-override.json

This file was deleted.

28 changes: 28 additions & 0 deletions ci/build/build-lib.sh
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 3 additions & 14 deletions ci/build/build-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,33 +44,21 @@ 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

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
Expand Down
21 changes: 21 additions & 0 deletions test/scripts/build-lib.bats
Original file line number Diff line number Diff line change
@@ -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" ]
}