Skip to content

Commit 60deddd

Browse files
committed
fix build script to properly use GitVersion with dotnet build and dotnet pack
1 parent aa56c41 commit 60deddd

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

.github/workflows/build.yml

+46-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- main
7-
- develop*
7+
- develop
88
- feature/*
99
- fix/*
1010
- release/*
@@ -29,10 +29,26 @@ jobs:
2929

3030
- name: Determine Version
3131
run: |
32-
rm -rf .git/gitversion_cache # Ensure no cached versioning issues
33-
VERSION=$(dotnet-gitversion /showvariable FullSemVer)
34-
echo "VERSION=${VERSION}" >> $GITHUB_ENV
35-
echo "🔹 Version resolved: ${VERSION}"
32+
VERSION_JSON=$(dotnet-gitversion /output json)
33+
FULL_VERSION=$(echo $VERSION_JSON | jq -r '.FullSemVer')
34+
FILE_VERSION=$(echo $VERSION_JSON | jq -r '.AssemblySemFileVer')
35+
ASSEMBLY_VERSION=$(echo $VERSION_JSON | jq -r '.AssemblySemVer')
36+
37+
# Ensure NuGet Package Version is valid
38+
NUGET_VERSION=$(echo $VERSION_JSON | jq -r '.NuGetVersionV2')
39+
if [[ -z "$NUGET_VERSION" || "$NUGET_VERSION" == "null" ]]; then
40+
NUGET_VERSION=$FULL_VERSION
41+
fi
42+
43+
# Export versions to GitHub environment variables
44+
echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_ENV
45+
echo "FILE_VERSION=$FILE_VERSION" >> $GITHUB_ENV
46+
echo "ASSEMBLY_VERSION=$ASSEMBLY_VERSION" >> $GITHUB_ENV
47+
echo "NUGET_VERSION=$NUGET_VERSION" >> $GITHUB_ENV
48+
49+
# Debug output
50+
echo "🔹 Resolved Full Version: $FULL_VERSION"
51+
echo "🔹 Resolved NuGet Version: $NUGET_VERSION"
3652

3753
- name: Add UiPath NuGet Source
3854
run: |
@@ -42,25 +58,28 @@ jobs:
4258
run: dotnet restore
4359

4460
- name: Build Solution
45-
run: dotnet build --configuration Release /p:Version=${{ env.VERSION }}
61+
run: |
62+
dotnet build --configuration Release \
63+
/p:Version=${{ env.FULL_VERSION }} \
64+
/p:FileVersion=${{ env.FILE_VERSION }} \
65+
/p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }}
4666
47-
- name: Pack NuGet Package (Optional)
48-
run: dotnet pack --configuration Release --output ./nupkg /p:Version=${{ env.VERSION }}
67+
- name: Pack NuGet Package
68+
run: |
69+
dotnet pack --configuration Release --no-build --output ./nupkg \
70+
/p:PackageVersion=${{ env.NUGET_VERSION }} \
71+
/p:Version=${{ env.FULL_VERSION }} \
72+
/p:FileVersion=${{ env.FILE_VERSION }} \
73+
/p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }}
4974
5075
- name: Debug Build Output
51-
run: ls -R src/CPRIMA.WorkflowAnalyzerRules/bin/Release/
76+
run: ls -R src/**/bin/Release/
5277

5378
- name: Get Built File Names
5479
run: |
55-
# Set default values
56-
DEFAULT_DLL_NAME="built-dll"
57-
DEFAULT_NUPKG_NAME="nuget-package"
58-
59-
# Try to find the actual file names
60-
DLL_NAME=$(ls src/**/bin/Release/net6.0/*.dll 2>/dev/null | head -n 1 | xargs -n 1 basename || echo "${DEFAULT_DLL_NAME}.dll")
61-
NUPKG_NAME=$(ls nupkg/*.nupkg 2>/dev/null | head -n 1 | xargs -n 1 basename || echo "${DEFAULT_NUPKG_NAME}.nupkg")
80+
DLL_NAME=$(find src -type f -name "*.dll" -path "*/bin/Release/*" | head -n 1 | xargs -n 1 basename)
81+
NUPKG_NAME=$(find nupkg -type f -name "*.nupkg" | head -n 1 | xargs -n 1 basename)
6282
63-
# Export values to GitHub environment variables
6483
echo "DLL_NAME=${DLL_NAME}" >> $GITHUB_ENV
6584
echo "NUPKG_NAME=${NUPKG_NAME}" >> $GITHUB_ENV
6685
echo "🔹 DLL Name: ${DLL_NAME}"
@@ -69,15 +88,19 @@ jobs:
6988
- name: Upload DLL Artifact
7089
uses: actions/upload-artifact@v4
7190
with:
72-
name: ${{ env.DLL_NAME }}-${{ env.VERSION }}
73-
path: |
74-
src/**/bin/Release/net6.0/*.dll
75-
src/**/bin/Release/net8.0/*.dll
76-
src/**/bin/Release/**/*.dll
91+
name: ${{ env.DLL_NAME }}-${{ env.FULL_VERSION }}
92+
path: src/**/bin/Release/**/*.dll
7793

7894
- name: Upload NuGet Package
7995
uses: actions/upload-artifact@v4
8096
with:
81-
name: ${{ env.NUPKG_NAME }}-${{ env.VERSION }}
97+
name: ${{ env.NUPKG_NAME }}-${{ env.FULL_VERSION }}
8298
path: nupkg/**/*.nupkg
8399

100+
# - name: Publish NuGet Package (Pre-release)
101+
# if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/feature/')
102+
# run: dotnet nuget push "nupkg/**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
103+
#
104+
# - name: Publish NuGet Package (Stable)
105+
# if: startsWith(github.ref, 'refs/tags/v')
106+
# run: dotnet nuget push "nupkg/**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

GitVersion.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
branches:
2-
develop:
3-
increment: None # Prevents automatic version increments
4-
label: alpha
5-
prevent-increment: true
1+
workflow: GitFlow/v1

0 commit comments

Comments
 (0)