Skip to content

Commit 1fcece1

Browse files
authored
Fix versioning (#221)
1 parent 29dafe2 commit 1fcece1

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,41 @@ jobs:
147147
# See explanation at https://dusted.codes/github-actions-for-dotnet-core-nuget-packages.
148148
- name: Set NuGet packages and suffix version
149149
run: |
150+
# Obtain the latest tag, default to 0.0.1 if no tags are found.
151+
latestTag=$(git describe --tags --abbrev=0 2>/dev/null || echo 0.0.1)
152+
153+
# Case 1: A release is being created.
150154
if [[ $GITHUB_EVENT_NAME == 'release' ]]; then
151-
arrTag=(${GITHUB_REF//\// })
152-
VERSION="${arrTag[2]}"
153-
VERSION="${VERSION//v}-${GITHUB_SHA::7}"
154-
echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV"
155-
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
156-
echo "VERSION_SUFFIX=$VERSION-release" >> "$GITHUB_ENV"
155+
# Extract the version number from the release tag and remove any 'v' prefix.
156+
arrTag=(${GITHUB_REF//\// })
157+
VERSION="${arrTag[2]}"
158+
VERSION="${VERSION//v}"
159+
160+
# Set the PACKAGE_VERSION and VERSION.
161+
# Add a VERSION_SUFFIX that identifies this as a release and includes the short SHA.
162+
echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV"
163+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
164+
echo "VERSION_SUFFIX=release-${GITHUB_SHA::7}" >> "$GITHUB_ENV"
165+
166+
# Case 2: The 'develop' branch.
157167
elif [[ $GITHUB_REF == 'refs/heads/develop' ]]; then
158-
echo "PACKAGE_VERSION=0.0.0.1-$GITHUB_RUN_ID-${GITHUB_SHA::7}-develop" >> "$GITHUB_ENV"
159-
echo "PACKAGE=0.0.0.1" >> "$GITHUB_ENV"
160-
echo "VERSION_SUFFIX=$GITHUB_RUN_ID-${GITHUB_SHA::7}-develop" >> "$GITHUB_ENV"
168+
# Set the PACKAGE_VERSION and PACKAGE.
169+
# Add a VERSION_SUFFIX with the 'develop' label, the run ID, and the short SHA.
170+
echo "PACKAGE_VERSION=${latestTag//v}" >> "$GITHUB_ENV"
171+
echo "PACKAGE=${latestTag//v}" >> "$GITHUB_ENV"
172+
echo "VERSION_SUFFIX=develop-${GITHUB_RUN_ID}-${GITHUB_SHA::7}" >> "$GITHUB_ENV"
173+
174+
# Case 3: Any other build.
161175
else
162-
echo "PACKAGE_VERSION=0.0.0.1-$GITHUB_RUN_ID-${GITHUB_SHA::7}-dev" >> "$GITHUB_ENV"
163-
echo "VERSION=0.0.0.1" >> "$GITHUB_ENV"
164-
echo "VERSION_SUFFIX=$GITHUB_RUN_ID-${GITHUB_SHA::7}-dev" >> "$GITHUB_ENV"
176+
# Set the PACKAGE_VERSION and VERSION.
177+
# Add a VERSION_SUFFIX with the 'build' label, the run ID, and the short SHA.
178+
echo "PACKAGE_VERSION=${latestTag//v}" >> "$GITHUB_ENV"
179+
echo "VERSION=${latestTag//v}" >> "$GITHUB_ENV"
180+
echo "VERSION_SUFFIX=build-${GITHUB_RUN_ID}-${GITHUB_SHA::7}" >> "$GITHUB_ENV"
165181
fi
166182
shell: bash
167183

184+
168185
- name: Print NuGet packages version
169186
run: echo $PACKAGE_VERSION
170187
shell: bash

0 commit comments

Comments
 (0)