From 52bdf6c3842e957f53fc2b68354c3d031f05acfc Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Thu, 2 Mar 2023 19:44:02 +0200 Subject: [PATCH] Append version to RID only with valid characters (#81497) This is the `init-distro-rid.sh` counterpart of 31e4f404c218eae7ba999c4df5346d30f971451c. In `amd64/archlinux` docker container, the non-portable RID auto-detection (without explicit `-p:TargetRid=arch-x64` arg or `__DistroRid=arch-x64` env var) looks like this: Before: `__DistroRid: arch.TEMPLATE_VERSION_ID-x64` After: `__DistroRid: arch-x64` --- eng/native/init-distro-rid.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index a380367e60e6c..3f22de10061fa 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -46,12 +46,13 @@ initNonPortableDistroRid() VERSION_ID="${VERSION_ID%.*}" fi - if [ -z "${VERSION_ID+x}" ]; then - # Rolling release distros do not set VERSION_ID, so omit - # it here to be consistent with everything else. - nonPortableBuildID="${ID}-${buildArch}" + if [[ "${VERSION_ID}" =~ ^([[:digit:]]|\.)+$ ]]; then + nonPortableBuildID="${ID}.${VERSION_ID}-${buildArch}" else - nonPortableBuildID="${ID}.${VERSION_ID}-${buildArch}" + # Rolling release distros either do not set VERSION_ID, set it as blank or + # set it to non-version looking string (such as TEMPLATE_VERSION_ID on ArchLinux); + # so omit it here to be consistent with everything else. + nonPortableBuildID="${ID}-${buildArch}" fi fi