Skip to content

Commit cac1a76

Browse files
authored
Add a version suffix when testing in CI (#445)
1 parent 5aaff18 commit cac1a76

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

.github/workflows/ci.yml

+28-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
env:
1212
DOTNET_CLI_TELEMETRY_OPTOUT: true
1313
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
14+
PUBLISH_RELEASE: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !github.event.repository.fork }}
1415

1516
permissions:
1617
contents: read
@@ -203,6 +204,8 @@ jobs:
203204
name: Build NuGet package
204205
runs-on: ubuntu-latest
205206
needs: build-native
207+
outputs:
208+
version: ${{ steps.get-version.outputs.version }}
206209
steps:
207210
- name: Checkout
208211
uses: actions/checkout@v4
@@ -218,8 +221,23 @@ jobs:
218221
uses: actions/setup-dotnet@v4
219222
with:
220223
dotnet-version: 7.0.x
224+
- name: Get version
225+
id: get-version
226+
shell: pwsh
227+
run: |
228+
$version_prefix=$((Select-Xml -Path ./csharp/ParquetSharp.csproj -XPath '/Project/PropertyGroup/VersionPrefix/text()').node.Value)
229+
if ( "${env:PUBLISH_RELEASE}" -eq "true") {
230+
$version_suffix=""
231+
$version="${version_prefix}"
232+
} else {
233+
$version_suffix="$(git rev-parse --short HEAD)"
234+
$version="${version_prefix}-${version_suffix}"
235+
}
236+
echo "version=${version}"
237+
echo "version=${version}" >> $env:GITHUB_OUTPUT
238+
echo "version_suffix=${version_suffix}" >> $env:GITHUB_OUTPUT
221239
- name: Build NuGet package
222-
run: dotnet build csharp --configuration=Release
240+
run: dotnet build csharp --configuration=Release --version-suffix="${{ steps.get-version.outputs.version_suffix }}"
223241
- name: Upload NuGet artifact
224242
uses: actions/upload-artifact@v4
225243
with:
@@ -245,10 +263,6 @@ jobs:
245263
steps:
246264
- name: Checkout
247265
uses: actions/checkout@v4
248-
- name: Get version
249-
id: get-version
250-
run: echo "version=$((Select-Xml -Path ./csharp/ParquetSharp.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value)" >> $env:GITHUB_OUTPUT
251-
shell: pwsh
252266
- name: Download NuGet artifact
253267
uses: actions/download-artifact@v4
254268
with:
@@ -275,9 +289,9 @@ jobs:
275289
- name: Change test project references to use local NuGet package
276290
run: |
277291
dotnet remove csharp.test reference csharp/ParquetSharp.csproj
278-
dotnet add csharp.test package ParquetSharp -v ${{ steps.get-version.outputs.version }}
292+
dotnet add csharp.test package ParquetSharp -v ${{ needs.build-nuget.outputs.version }}
279293
dotnet remove fsharp.test reference csharp/ParquetSharp.csproj
280-
dotnet add fsharp.test package ParquetSharp -v ${{ steps.get-version.outputs.version }}
294+
dotnet add fsharp.test package ParquetSharp -v ${{ needs.build-nuget.outputs.version }}
281295
- name: Build & Run C# unit tests
282296
run: dotnet test csharp.test --configuration=Release --framework ${{ matrix.dotnet }}
283297
- name: Build & Run F# unit tests
@@ -297,26 +311,26 @@ jobs:
297311

298312
# Create a GitHub release and publish the NuGet packages to nuget.org when a tag is pushed.
299313
publish-release:
314+
# This should match env.PUBLISH_RELEASE (which we can't access in an if condition)
300315
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !github.event.repository.fork
301316
name: Publish release
302317
runs-on: ubuntu-latest
303318
permissions:
304319
contents: write
305-
needs: all-required-checks-done
320+
needs: [build-nuget,all-required-checks-done]
306321
steps:
307322
- name: Checkout
308323
uses: actions/checkout@v4
309324
- name: Check version
310325
id: check-version
311326
shell: pwsh
312327
run: |
313-
$version = (Select-Xml -Path ./csharp/ParquetSharp.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value
328+
$version = "${{ needs.build-nuget.outputs.version }}"
314329
$tag = "${{ github.ref }}".SubString(10)
315330
if (-not ($tag -eq $version)) {
316331
echo "::error ::There is a mismatch between the project version ($version) and the tag ($tag)"
317332
exit 1
318333
}
319-
echo "version=$version" >> $env:GITHUB_OUTPUT
320334
- name: Download NuGet artifact
321335
uses: actions/download-artifact@v4
322336
with:
@@ -331,12 +345,12 @@ jobs:
331345
- name: Create release
332346
uses: softprops/action-gh-release@v2
333347
with:
334-
name: ParquetSharp ${{ steps.check-version.outputs.version }}
348+
name: ParquetSharp ${{ needs.build-nuget.outputs.version }}
335349
draft: true
336-
prerelease: ${{ contains(steps.check-version.outputs.version, '-') }}
350+
prerelease: ${{ contains(needs.build-nuget.outputs.version, '-') }}
337351
files: |
338-
nuget/ParquetSharp.${{ steps.check-version.outputs.version }}.nupkg
352+
nuget/ParquetSharp.${{ needs.build-nuget.outputs.version }}.nupkg
339353
env:
340354
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
341355
- name: Publish to NuGet
342-
run: dotnet nuget push nuget/ParquetSharp.${{ steps.check-version.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
356+
run: dotnet nuget push nuget/ParquetSharp.${{ needs.build-nuget.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

csharp/ParquetSharp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<NoWarn>1591;</NoWarn>
15-
<Version>15.0.2.1</Version>
15+
<VersionPrefix>15.0.2.1</VersionPrefix>
1616
<Company>G-Research</Company>
1717
<Authors>G-Research</Authors>
1818
<Product>ParquetSharp</Product>

0 commit comments

Comments
 (0)