From 4c5b89a95aa2227709a3e26a58db651ce91bb78a Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Thu, 1 Feb 2024 17:08:10 +0100 Subject: [PATCH] run: fix git describe Full git tree was missing in CI for non-tagged builds --- .github/workflows/build-image.yml | 6 ++++-- run | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 48da22bc4..e0f08bf45 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -32,12 +32,14 @@ jobs: NETIFYD_ACCESS_TOKEN: ${{ secrets.NETIFYD_ACCESS_TOKEN }} steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - id: read_tag name: Set VERSION env variable if: ${{ startsWith(github.ref, 'refs/tags') }} run: | - # Set tag from GitHub: using git describe in this context seems not working - # even if the checkout has been done with fetch-depth set to 0 + # Set tag from GitHub: using git describe for tags inside the run script + # seems not working echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - id: build name: Build the image diff --git a/run b/run index d786a1b63..4803182a8 100755 --- a/run +++ b/run @@ -51,16 +51,18 @@ fi # Download latest image podman pull $image -# Renove existing container +# Remove existing container if [ "$(podman ps -a --format '{{.Names}}')" == "nethsec-builder" ]; then podman rm nethsec-builder fi # Use VERSION from the environment, need for CI # VERSION has the following format: 8--ns.[--g] -if [ -z "{$VERSION}" ]; then +if [ -z "${VERSION}" ]; then # Setup version from git if the env var is not set - VERSION=$(git describe --tags) + # Make sure to fetch all history to generate a correct git-descrive + git fetch --prune --unshallow + VERSION=$(git describe) fi # OWRT_VERSION is like 23.05.2 OWRT_VERSION=$(echo $VERSION | cut -d'-' -f1) @@ -83,6 +85,7 @@ fi export REPO_CHANNEL export OWRT_VERSION export VERSION +echo "Building version $VERSION" # Setup CI when pushing to Github. if [[ -n "${CI}" ]]; then