Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasOnatsu committed Nov 11, 2024
1 parent 7a0eefb commit 07a3e1e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-<sha>"
buildver="git-${sha:0:7}"
# Set default to "git-<short-sha>"
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: <tag-name>-<#-of-commits-since-tag>-<abbrev-hash>
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"

0 comments on commit 07a3e1e

Please sign in to comment.