From bb568abdd49a886164b979496e1f35eb279ef82c Mon Sep 17 00:00:00 2001 From: John Date: Sun, 17 Jul 2022 11:14:46 +0200 Subject: [PATCH] pass git revision to build process (#617) --- .github/workflows/build.yml | 6 +++++- configure.ac | 8 ++++++-- contrib/docker/Dockerfile | 4 +++- contrib/docker/Dockerfile.release | 4 +++- contrib/docker/Dockerfile.template | 2 ++ contrib/docker/build.sh | 1 + contrib/docker/update.sh | 6 +++--- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4816644..b8396ff5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,10 @@ jobs: - name: checkout uses: actions/checkout@v2 + - + name: gh-describe + id: gittag + uses: proudust/gh-describe@v1.4.6 - name: set up QEMU uses: docker/setup-qemu-action@v1 @@ -46,4 +50,4 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: build - run: cd contrib/docker && LIMITARCH=${{ github.event.inputs.limitarch }} ./build.sh + run: cd contrib/docker && LIMITARCH=${{ github.event.inputs.limitarch }} GIT_REVISION=${{ steps.gittag.outputs.describe }} ./build.sh diff --git a/configure.ac b/configure.ac index fe9f68b6..3664ecc2 100755 --- a/configure.ac +++ b/configure.ac @@ -137,8 +137,12 @@ AC_DEFINE_UNQUOTED(PACKAGE_LOGFILE, LOCALSTATEDIR "/log/" PACKAGE ".log", [The p AC_DEFINE(SCAN_VERSION, "[m4_esyscmd_s([sed -e 's#^\([0-9]*\.[0-9]*\).*#\1#' -e 's#\.\([0-9]\)$#0\1#' -e 's#\.##' VERSION])]", [The version of the package formatted for the scan result.]) AC_DEFINE(PACKAGE_VERSION_MAJOR, "[m4_esyscmd_s([sed -e 's#^\([0-9]*\)\..*$#\1#' VERSION])]", [The major version of the package.]) AC_DEFINE(PACKAGE_VERSION_MINOR, "[m4_esyscmd_s([sed -e 's#^.*\.\([0-9]*\)$#\1#' VERSION])]", [The minor version of the package.]) -AC_DEFINE(REVISION, "[m4_esyscmd_s([git describe --always 2>/dev/null || (date +p%Y%m%d)])]", [The revision of the package.]) - +AC_ARG_VAR(GIT_REVISION, [Predefined value to use for revision instead of running git describe.]) +if test -n "$GIT_REVISION"; then + AC_DEFINE(REVISION, [m4_esyscmd_s([echo "$GIT_REVISION"])], [The revision of the package.]) +else + AC_DEFINE(REVISION, "[m4_esyscmd_s([git describe --always 2>/dev/null || (date +p%Y%m%d)])]", [The revision of the package.]) +fi AC_CHECK_PROGS([HAVE_DOXYGEN], [doxygen], []) if test -z "$HAVE_DOXYGEN"; then AC_MSG_WARN([Doxygen not found - continuing without Doxygen support.]) diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile index 56823e40..a999bf35 100755 --- a/contrib/docker/Dockerfile +++ b/contrib/docker/Dockerfile @@ -13,12 +13,14 @@ WORKDIR /build ARG TARGETARCH ARG TARGETVARIANT ARG EBUSD_VERSION +ARG GIT_REVISION ENV EBUSD_ARCH $TARGETARCH$TARGETVARIANT ENV EBUSD_VERSION $EBUSD_VERSION +ENV GIT_REVISION $GIT_REVISION ADD . /build -RUN RUNTEST=full ./make_debian.sh +RUN RUNTEST=full GIT_REVISION=$GIT_REVISION ./make_debian.sh diff --git a/contrib/docker/Dockerfile.release b/contrib/docker/Dockerfile.release index 8c66666d..f4315732 100644 --- a/contrib/docker/Dockerfile.release +++ b/contrib/docker/Dockerfile.release @@ -13,12 +13,14 @@ WORKDIR /build ARG TARGETARCH ARG TARGETVARIANT ARG EBUSD_VERSION +ARG GIT_REVISION ENV EBUSD_ARCH $TARGETARCH$TARGETVARIANT ENV EBUSD_VERSION $EBUSD_VERSION +ENV GIT_REVISION $GIT_REVISION ADD . /build -RUN ./make_debian.sh +RUN GIT_REVISION=$GIT_REVISION ./make_debian.sh diff --git a/contrib/docker/Dockerfile.template b/contrib/docker/Dockerfile.template index 82e7f6da..ae486783 100644 --- a/contrib/docker/Dockerfile.template +++ b/contrib/docker/Dockerfile.template @@ -13,9 +13,11 @@ WORKDIR /build ARG TARGETARCH ARG TARGETVARIANT ARG EBUSD_VERSION +ARG GIT_REVISION ENV EBUSD_ARCH $TARGETARCH$TARGETVARIANT ENV EBUSD_VERSION $EBUSD_VERSION +ENV GIT_REVISION $GIT_REVISION ADD . /build RUN %EBUSD_MAKE% diff --git a/contrib/docker/build.sh b/contrib/docker/build.sh index 6b241e43..e52965db 100755 --- a/contrib/docker/build.sh +++ b/contrib/docker/build.sh @@ -58,6 +58,7 @@ for image in $images; do --build-arg "UPLOAD_URL=$UPLOAD_URL" \ --build-arg "UPLOAD_CREDENTIALS=$UPLOAD_CREDENTIALS" \ --build-arg "UPLOAD_OS=$image" \ + --build-arg "GIT_REVISION=$GIT_REVISION" \ -t $tagprefix$tagsuffix \ $extratag \ $output \ diff --git a/contrib/docker/update.sh b/contrib/docker/update.sh index 5c8e02d8..65a4a0f6 100755 --- a/contrib/docker/update.sh +++ b/contrib/docker/update.sh @@ -15,7 +15,7 @@ function replaceTemplate () { # devel update version_variant='-devel' -make='RUNTEST=full ./make_debian.sh' +make='RUNTEST=full GIT_REVISION=\$GIT_REVISION ./make_debian.sh' upload_lines='' copydeb='COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb' debsrc='ebusd.deb \&\& rm -f ebusd.deb' @@ -25,7 +25,7 @@ replaceTemplate # release update version_variant='' -make='./make_debian.sh' +make='GIT_REVISION=\$GIT_REVISION ./make_debian.sh' copydeb="ADD https://github.com/john30/ebusd/releases/download/v\${EBUSD_VERSION}/ebusd-\${EBUSD_VERSION}_\${TARGETARCH}\${TARGETVARIANT}-\${EBUSD_IMAGE}_mqtt1.deb ebusd.deb" copyentry='COPY contrib/docker/docker-entrypoint.sh /' namesuffix='.release' @@ -33,7 +33,7 @@ replaceTemplate if [[ -n "$1" ]]; then # build releases update - make='./make_all.sh' + make='GIT_REVISION=\$GIT_REVISION ./make_all.sh' upload_lines='ARG UPLOAD_URL\nARG UPLOAD_CREDENTIALS\nARG UPLOAD_OS\nRUN if [ -n "\$UPLOAD_URL" ] \&\& [ -n "\$UPLOAD_CREDENTIALS" ]; then for img in ebusd-*.deb; do echo -n "upload \$img: "; curl -fsSk -u "\$UPLOAD_CREDENTIALS" -X POST --data-binary "@\$img" -H "Content-Type: application/octet-stream" "\$UPLOAD_URL/\$img?a=\$EBUSD_ARCH\&o=\$UPLOAD_OS\&v=\$EBUSD_VERSION" || echo "failed"; done; fi' upload_lines+='\n\n\nFROM scratch as deb\nCOPY --from=build /build/*.deb /' namesuffix='.build'