diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cdd167..7c10efb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,26 +29,32 @@ jobs: - name: Generate build version shell: bash run: | - sha="${{ github.sha }}" + SHA="${{ github.sha }}" + SHORT_SHA="${SHA:0:7}" + REF="${{ github.ref }}" + REF_TYPE="${{ github.ref_type }}" + REF_NAME="${{ github.ref_name }}" - # Default to "git-" - buildver="git-${sha:0:7}" + # Set default to "git-" + BUILD_VERSION="git-$SHORT_SHA" - if [[ "${{ github.ref_type }}" == "tag" ]]; then - buildver="${{ github.ref_name }}" - elif [[ "${{ github.ref_type }}" == "branch" ]]; then + if [[ "$REF_TYPE" == "tag" ]]; then + BUILD_VERSION="$REF_NAME" + elif [[ "$REF_TYPE" == "branch" ]]; then # Check if there's a reachable tag on the branch - if git name-rev --name-only --tags --no-undefined "${{ github.ref }}" 2>/dev/null; then - buildver="$(git describe --tags "${{ github.ref }}")" + if git name-rev --name-only --tags --no-undefined "$REF" 2>/dev/null; then + # Format: -<#-of-commits-since-tag>- + BUILD_VERSION="$(git describe --tags --abbrev=7 "$REF")" else # No reachable parent tag on branch - buildver="git-${{ github.ref_name }}-${sha:0:7}" + BUILD_VERSION="$REF_NAME-g$SHORT_SHA" fi fi - echo "github.sha: ${{ github.sha }}" - echo "github.ref: ${{ github.ref }}" - echo "github.ref_type: ${{ github.ref_type }}" - echo "github.ref_name: ${{ github.ref_name }}" - echo "build_version=$buildver" - echo "build_version=$buildver" >> "$GITHUB_OUTPUT" + echo "SHA: $SHA" + echo "SHORT_SHA: $SHA" + echo "REF: $REF" + echo "REF_TYPE: $REF_TYPE" + echo "REF_NAME: $REF_NAME" + echo "BUILD_VERSION: $BUILD_VERSION" + echo "BUILD_VERSION=$BUILD_VERSION" >> "$GITHUB_OUTPUT"