From a379642f34a4a730993955b3cd608f5b2fa90a51 Mon Sep 17 00:00:00 2001 From: Matthias Frei Date: Tue, 14 May 2024 22:43:21 +0200 Subject: [PATCH] ci: fix build for openwrt package, enable setting version from env var Fix handling of release version (e.g. "0.11.0") in openwrt package build. Was only working for intermediate versions, like "0.10.0-32-asdlkjslka". Allow overwriting the version used for the builds consistently. Previously there was an envar GIT_VERSION that could do this partially. Renamed to SCION_VERSION and supported now also fully for the package builds. Setting this variable in buildkite pipelines should now allow, for example, building release builds before explicitly tagging the release. --- .buildkite/hooks/pre-command | 10 ++++++---- .buildkite/pipeline.yml | 2 +- dist/openwrt/ipk.bzl | 5 +++-- tools/bazel-build-env | 5 ++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 13ccb7e58a..77ca2546a6 100755 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -30,10 +30,12 @@ rm -f $HOME/.bazelrc # --nostamp is required for better caching (only on non-release jobs). if [ "$BUILDKITE_PIPELINE_SLUG" == "scion" ]; then echo "build --nostamp" > $HOME/.bazelrc - # Shorten the git version to omit commit information, improving cache reuse. - # The format of git-version is "--" - # This will be shortened to "-modified-ci" - export GIT_VERSION=$(tools/git-version | sed 's/-.*/-modified-ci/') + if [ -z ${SCION_VERSION+x} ]; then + # Shorten the git version to omit commit information, improving cache reuse. + # The format of git-version is "--" + # This will be shortened to "-modified-ci" + export SCION_VERSION=$(tools/git-version | sed 's/-.*/-modified-ci/') + fi else echo "build --stamp" > $HOME/.bazelrc fi diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index b2862ed65d..ef10701d48 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -25,7 +25,7 @@ steps: - wait - label: "Package :debian: :openwrt:" command: - - version="$(tools/git-version)" + - version=${SCION_VERSION:-$(tools/git-version)} - make dist-deb BFLAGS="--file_name_version=${version}" - make dist-openwrt BFLAGS="--file_name_version=${version}" - cd installables; diff --git a/dist/openwrt/ipk.bzl b/dist/openwrt/ipk.bzl index db298ad798..1469135215 100644 --- a/dist/openwrt/ipk.bzl +++ b/dist/openwrt/ipk.bzl @@ -92,10 +92,11 @@ def _ipk_impl(ctx): r"scripts/feeds install -a -p scion", r"make IB=1 defconfig", # IB=1 bypasses various unnecessary prerequisites r"IFS='-' read tag count commit dirty < ${execroot_abspath}/$5", + r"pkgver=${tag}", r'pkgrel=${count}${dirty:+".dirty$(date +%s)"}', r"make package/feeds/scion/${2}/compile EXECROOT=${execroot_abspath}" + - ' PKG_VERSION="${tag}" PKG_RELEASE="${pkgrel}"', - r"cp bin/packages/${6}/scion/${2}_${tag}-${pkgrel}_${6}.ipk ${execroot_abspath}/${4}", + ' PKG_VERSION="${pkgver}" PKG_RELEASE="${pkgrel}"', + r"cp bin/packages/${6}/scion/${2}_${pkgver}${pkgrel:+-}${pkgrel}_${6}.ipk ${execroot_abspath}/${4}", ]), ) diff --git a/tools/bazel-build-env b/tools/bazel-build-env index ba993c60a1..139b586b45 100755 --- a/tools/bazel-build-env +++ b/tools/bazel-build-env @@ -4,8 +4,7 @@ ROOTDIR=$(dirname "$0")/.. -# When building inside a docker container GIT_VERSION is set by the creator of the container. -# When building locally, use the version reported by git. -VERSION=${GIT_VERSION:-$($ROOTDIR/tools/git-version)} +# Use the version reported by git, unless SCION_VERSION is set to override this. +VERSION=${SCION_VERSION:-$($ROOTDIR/tools/git-version)} echo "STABLE_GIT_VERSION $VERSION"