From 7dd3cdfab447bb485351015c847a74d2272cbe3d Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 18 May 2022 16:58:10 -0700 Subject: [PATCH] build: Fetch all tags before deciding which version we're building The actions/checkout workflow does some heroics to try to fetch exactly the commit being built and nothing else, even if asked to fetch the history leading up to that commit. That means we don't end up having enough information to get an accurate answer from "git describe". Since we're intentionally relying on the git history here, we'll fetch all of the tags explicitly after initial checkout. Although that does add some delay to this step, we're intentionally doing this version calculation only once as a separate workflow job so that all of the other jobs can still benefit from this action's quicker checkout behavior. --- .github/workflows/build.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d423829008..af6aa9db83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,13 +44,17 @@ jobs: product-version: ${{ steps.get-product-version.outputs.product-version }} steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Need all commits and tags to find a reasonable version number + - uses: actions/checkout@v3 - name: Git Describe id: git-describe run: | - git describe --first-parent + # The actions/checkout action tries hard to fetch as little as + # possible, to the extent that even with "depth: 0" it fails to + # produce enough tag metadata for us to "describe" successfully. + # We'll therefore re-fetch the tags here to make sure we will + # select the most accurate version number. + git fetch origin --force --tags + git tag echo "::set-output name=raw-version::$(git describe --first-parent)" - name: Decide version number id: get-product-version @@ -58,6 +62,7 @@ jobs: env: RAW_VERSION: ${{ steps.git-describe.outputs.raw-version }} run: | + echo "Version number is ${RAW_VERSION}" echo "::set-output name=product-version::${RAW_VERSION#v}" - name: Report chosen version number run: |