Skip to content

Commit 3ddeef2

Browse files
committed
Replace GitVersion with a simpler script that produces equivalent output
1 parent ebf737b commit 3ddeef2

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,9 @@ jobs:
2222
- name: Fetch all commits
2323
run: git fetch --unshallow
2424

25-
- uses: gittools/actions/gitversion/setup@v0.9.10
26-
name: Install GitVersion
27-
with:
28-
versionSpec: "6.x"
29-
30-
- uses: gittools/actions/gitversion/execute@v0.9.10
31-
name: Execute GitVersion
32-
id: gitversion # step id used as reference for output values
33-
with:
34-
updateAssemblyInfo: true
35-
36-
- name: Print version information
37-
run: |
38-
echo "Major: ${{ steps.gitversion.outputs.major }}"
39-
echo "Minor: ${{ steps.gitversion.outputs.minor }}"
40-
echo "Patch: ${{ steps.gitversion.outputs.patch }}"
41-
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}"
42-
echo "SemVer: ${{ steps.gitversion.outputs.semVer }}"
25+
- name: Update version
26+
id: version
27+
run: ./get-version.sh
4328

4429
- name: Restore dependencies
4530
run: dotnet restore

.github/workflows/release.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@ jobs:
2222
- name: Fetch all commits
2323
run: git fetch --unshallow
2424

25-
- uses: gittools/actions/gitversion/setup@v0.9.10
26-
name: Install GitVersion
27-
with:
28-
versionSpec: "6.x"
29-
30-
- uses: gittools/actions/gitversion/execute@v0.9.10
31-
name: Execute GitVersion
32-
id: gitversion # step id used as reference for output values
33-
with:
34-
updateAssemblyInfo: true
25+
- name: Update version
26+
id: version
27+
run: ./get-version.sh
3528

3629
- name: Restore dependencies
3730
run: dotnet restore
@@ -45,7 +38,7 @@ jobs:
4538
- name: Deploy to NuGet
4639
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
4740
run: |
48-
dotnet pack -c Release /p:Version=${{ steps.gitversion.outputs.SemVer}} -o "nuget"
41+
dotnet pack -c Release /p:Version=${{ steps.version.outputs.SemVer }} -o "nuget"
4942
dotnet nuget push nuget/*.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json
5043
5144
- name: Extract release notes

GitVersion.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

get-version.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Get info about the current commit
4+
most_recent_tag=$(git describe --tags --match="v*" --abbrev=0)
5+
commits_since_tag=$(git rev-list $most_recent_tag..HEAD | wc -l | awk '{$1=$1};1')
6+
sha=$(git log -1 --format=%H)
7+
branch=$(git rev-parse --abbrev-ref HEAD)
8+
9+
# A regex for extracting data from a version number: major, minor, patch,
10+
# [prerelease]
11+
REGEX='v(\d+)\.(\d+)\.(\d+)(-.*)?'
12+
13+
# Extract the data from the version number
14+
major=$(echo $most_recent_tag | perl -pe "s|$REGEX|\1|" )
15+
minor=$(echo $most_recent_tag | perl -pe "s|$REGEX|\2|" )
16+
patch=$(echo $most_recent_tag | perl -pe "s|$REGEX|\3|" )
17+
prerelease=$(echo $most_recent_tag | perl -pe "s|$REGEX|\4|" )
18+
19+
# Create the version strings we'll write into the AssemblyInfo files
20+
OutputAssemblyVersion="$major.$minor.$patch.$commits_since_tag"
21+
OutputAssemblyInformationalVersion="$major.$minor.$patch$prerelease+$commits_since_tag.Branch.$branch.Sha.$sha"
22+
OutputAssemblyFileVersion="$major.$minor.$patch.$commits_since_tag"
23+
24+
# Calculate the semver from the version (should be the same as the version, but
25+
# just in case)
26+
SemVer="v$major.$minor.$patch$prerelease"
27+
28+
# If there are any commits since the current tag, add that note
29+
if [ "$commits_since_tag" -gt 0 ]; then
30+
SemVer="$Semver+$commits_since_tag"
31+
fi
32+
33+
# Update the AssemblyInfo.cs files
34+
for infoFile in $(find . -name "AssemblyInfo.cs"); do
35+
perl -pi -e "s/AssemblyVersion\(\".*\"\)/AssemblyVersion(\"$OutputAssemblyVersion\")/" $infoFile
36+
perl -pi -e "s/AssemblyInformationalVersion\(\".*\"\)/AssemblyInformationalVersion(\"$OutputAssemblyInformationalVersion\")/" $infoFile
37+
perl -pi -e "s/AssemblyFileVersion\(\".*\"\)/AssemblyFileVersion(\"$OutputAssemblyFileVersion\")/" $infoFile
38+
done
39+
40+
# If we're running in GitHub Workflows, output our calculated SemVer
41+
if [[ -n $GITHUB_OUTPUT ]]; then
42+
echo "SemVer=$SemVer" >> "$GITHUB_OUTPUT"
43+
fi
44+
45+
# Log our SemVer
46+
echo $SemVer

0 commit comments

Comments
 (0)