Skip to content

Commit 225b233

Browse files
committed
Set version in a separate job.
1 parent af197ff commit 225b233

File tree

6 files changed

+51
-48
lines changed

6 files changed

+51
-48
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ permissions:
1212

1313
name: main
1414
jobs:
15+
version:
16+
name: Set version
17+
runs-on: ubuntu-24.04
18+
outputs:
19+
version: ${{steps.version.outputs.version}}
20+
commit: ${{steps.version.outputs.commit}}
21+
publish: ${{steps.version.outputs.publish}}
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v6
26+
with:
27+
fetch-tags: true
28+
persist-credentials: false
29+
30+
- name: Set version
31+
id: version
32+
run: |
33+
version=$(git describe --exact-match --tags HEAD 2> /dev/null)
34+
publish=false
35+
if [ -z "$version" ]; then
36+
version=$(git log -1 --date=format:"0.%Y.%m%d.%H%M" --format="%ad")
37+
else
38+
publish=true
39+
fi
40+
commit=$(git rev-parse HEAD)
41+
42+
echo "version=$version" >> $GITHUB_OUTPUT
43+
echo "version=$version"
44+
echo "commit=$commit" >> $GITHUB_OUTPUT
45+
echo "commit=$commit"
46+
echo "publish=$publish" >> $GITHUB_OUTPUT
47+
echo "publish=$publish"
48+
1549
linux:
1650
name: Linux (Q8/Q16/Q16-HDRI, x64)
1751
container:
@@ -169,6 +203,8 @@ jobs:
169203
windows:
170204
name: Windows (${{matrix.quantumName}}, ${{matrix.platformName}})
171205
runs-on: windows-2022
206+
needs:
207+
- version
172208

173209
strategy:
174210
fail-fast: false
@@ -193,7 +229,6 @@ jobs:
193229
- name: Checkout
194230
uses: actions/checkout@v6
195231
with:
196-
fetch-tags: true
197232
persist-credentials: false
198233

199234
- name: Install dependencies
@@ -220,12 +255,8 @@ jobs:
220255
run: ./build.Magick.NET.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}" Release
221256
working-directory: build/windows
222257

223-
- name: Set NuGet version
224-
run: ./set.version.ps1
225-
working-directory: publish
226-
227258
- name: Create NuGet package
228-
run: ./publish.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}"
259+
run: ./publish.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}" "${{ needs.version.outputs.version }}" "${{ needs.version.outputs.commit }}"
229260
working-directory: publish
230261

231262
- name: Upload library
@@ -238,6 +269,8 @@ jobs:
238269
name: Windows (${{matrix.quantumName}}, ${{matrix.platformName}})
239270
#runs-on: windows-11-arm
240271
runs-on: windows-2022
272+
needs:
273+
- version
241274

242275
strategy:
243276
fail-fast: false
@@ -249,7 +282,6 @@ jobs:
249282
- name: Checkout
250283
uses: actions/checkout@v6
251284
with:
252-
fetch-tags: true
253285
persist-credentials: false
254286

255287
- name: Install dependencies
@@ -276,12 +308,8 @@ jobs:
276308
run: ./build.Magick.NET.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}" Release
277309
working-directory: build/windows
278310

279-
- name: Set NuGet version
280-
run: ./set.version.ps1
281-
working-directory: publish
282-
283311
- name: Create NuGet package
284-
run: ./publish.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}"
312+
run: ./publish.cmd ${{ matrix.quantumName }} "${{ matrix.platformName }}" "${{ needs.version.outputs.version }}" "${{ needs.version.outputs.commit }}"
285313
working-directory: publish
286314

287315
- name: Upload library
@@ -293,6 +321,8 @@ jobs:
293321
libraries:
294322
name: Library
295323
runs-on: windows-2022
324+
needs:
325+
- version
296326

297327
strategy:
298328
fail-fast: false
@@ -303,7 +333,6 @@ jobs:
303333
- name: Checkout
304334
uses: actions/checkout@v6
305335
with:
306-
fetch-tags: true
307336
persist-credentials: false
308337

309338
- name: Install dependencies
@@ -322,12 +351,8 @@ jobs:
322351
run: ./build.Magick.NET.cmd "Q8" "Any CPU" Release
323352
working-directory: build/windows
324353

325-
- name: Set NuGet version
326-
run: ./set.version.ps1
327-
working-directory: publish
328-
329354
- name: Create NuGet package
330-
run: ./publish.library.cmd "Magick.NET.${{ matrix.libraryName }}"
355+
run: ./publish.library.cmd "Magick.NET.${{ matrix.libraryName }}" "${{ needs.version.outputs.version }}" "${{ needs.version.outputs.commit }}"
331356
working-directory: publish
332357

333358
- name: Upload library

publish/publish.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
call "..\tools\windows\init.visualstudio.cmd"
33

44
set PLATFORM_NAME=%2
5-
powershell .\publish.ps1 -destination output -quantumName %1 -platformName %PLATFORM_NAME:"='%
5+
powershell .\publish.ps1 -destination output -quantumName %1 -platformName %PLATFORM_NAME:"='% -version %3 -commit %4
66
if %errorlevel% neq 0 exit /b %errorlevel%

publish/publish.library.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
22
call "..\tools\windows\init.visualstudio.cmd"
33

4-
powershell .\publish.library.ps1 -destination output -library %1
4+
powershell .\publish.library.ps1 -destination output -library %1 -version %2 -commit %3
55
if %errorlevel% neq 0 exit /b %errorlevel%

publish/publish.library.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
param (
55
[string]$library,
6-
[string]$version = $env:NuGetVersion,
7-
[string]$commit = $env:GitCommitId,
6+
[string]$version,
7+
[string]$commit,
88
[parameter(mandatory=$true)][string]$destination
99
)
1010

publish/publish.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Licensed under the Apache License, Version 2.0.
33

44
param (
5-
[string]$quantumName = $env:QuantumName,
6-
[string]$platformName = $env:PlatformName,
7-
[string]$version = $env:NuGetVersion,
8-
[string]$commit = $env:GitCommitId,
5+
[string]$quantumName,
6+
[string]$platformName,
7+
[string]$version,
8+
[string]$commit,
99
[parameter(mandatory=$true)][string]$destination
1010
)
1111

publish/set.version.ps1

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)