Skip to content

Commit f4980eb

Browse files
committed
CI: improve the Generaptor workflow
1 parent 9efecf7 commit f4980eb

File tree

7 files changed

+148
-56
lines changed

7 files changed

+148
-56
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
url: ${{ steps.deployment.outputs.page_url }}
2424
runs-on: ubuntu-24.04
2525
steps:
26-
- name: Checkout
26+
- name: Check out the sources
2727
uses: actions/checkout@v6
2828
- name: Set up .NET SDK
2929
uses: actions/setup-dotnet@v5

.github/workflows/main.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,29 @@ on:
1818
jobs:
1919
verify-workflows:
2020
runs-on: ubuntu-24.04
21+
env:
22+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
23+
DOTNET_NOLOGO: 1
24+
NUGET_PACKAGES: ${{ github.workspace }}/.github/nuget-packages
2125
steps:
22-
- uses: actions/checkout@v6
26+
- name: Check out the sources
27+
uses: actions/checkout@v6
2328
- name: Set up .NET SDK
2429
uses: actions/setup-dotnet@v5
30+
- name: Cache NuGet packages
31+
uses: actions/cache@v5
32+
with:
33+
key: ${{ runner.os }}.nuget.${{ hashFiles('**/*.*proj', '**/*.props') }}
34+
path: ${{ env.NUGET_PACKAGES }}
2535
- run: dotnet fsi ./scripts/github-actions.fsx verify
2636
check:
2737
strategy:
2838
matrix:
2939
image:
30-
- macos-15
40+
- macos-14
3141
- ubuntu-24.04
42+
- ubuntu-24.04-arm
43+
- windows-11-arm
3244
- windows-2025
3345
fail-fast: false
3446
runs-on: ${{ matrix.image }}
@@ -37,15 +49,14 @@ jobs:
3749
DOTNET_NOLOGO: 1
3850
NUGET_PACKAGES: ${{ github.workspace }}/.github/nuget-packages
3951
steps:
40-
- uses: actions/checkout@v6
52+
- name: Check out the sources
53+
uses: actions/checkout@v6
4154
- name: Set up .NET SDK
42-
uses: actions/setup-dotnet@v4
43-
with:
44-
dotnet-version: 8.0.x
45-
- name: NuGet cache
55+
uses: actions/setup-dotnet@v5
56+
- name: Cache NuGet packages
4657
uses: actions/cache@v5
4758
with:
48-
key: ${{ runner.os }}.nuget.${{ hashFiles('**/*.csproj') }}
59+
key: ${{ runner.os }}.nuget.${{ hashFiles('**/*.*proj', '**/*.props') }}
4960
path: ${{ env.NUGET_PACKAGES }}
5061
- name: Build
5162
run: dotnet build
@@ -55,19 +66,35 @@ jobs:
5566
licenses:
5667
runs-on: ubuntu-24.04
5768
steps:
58-
- uses: actions/checkout@v6
69+
- name: Check out the sources
70+
uses: actions/checkout@v6
5971
- name: REUSE license check
6072
uses: fsfe/reuse-action@v6
6173
encoding:
6274
runs-on: ubuntu-24.04
6375
steps:
64-
- uses: actions/checkout@v6
76+
- name: Check out the sources
77+
uses: actions/checkout@v6
6578
- name: Verify encoding
6679
shell: pwsh
6780
run: scripts/Test-Encoding.ps1
6881
nowarn-empty:
6982
runs-on: ubuntu-24.04
83+
env:
84+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
85+
DOTNET_NOLOGO: 1
86+
NUGET_PACKAGES: ${{ github.workspace }}/.github/nuget-packages
7087
steps:
71-
- uses: actions/checkout@v6
88+
- name: Check out the sources
89+
uses: actions/checkout@v6
90+
- name: Set up .NET SDK
91+
uses: actions/setup-dotnet@v5
92+
- name: Cache NuGet packages
93+
uses: actions/cache@v5
94+
with:
95+
key: ${{ runner.os }}.nuget.${{ hashFiles('**/*.*proj', '**/*.props') }}
96+
path: ${{ env.NUGET_PACKAGES }}
97+
- name: Check out the sources
98+
uses: actions/checkout@v6
7299
- name: Verify with NoWarn as empty
73100
run: dotnet build /p:NoWarn='' --no-incremental

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
contents: write
2424
runs-on: ubuntu-24.04
2525
steps:
26-
- uses: actions/checkout@v6
26+
- name: Check out the sources
27+
uses: actions/checkout@v6
2728
- id: version
2829
name: Get version
2930
shell: pwsh
@@ -54,8 +55,8 @@ jobs:
5455
./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.snupkg
5556
name: TruePath v${{ steps.version.outputs.version }}
5657
- if: startsWith(github.ref, 'refs/tags/v')
57-
name: Push artifact to NuGet
58+
name: Push TruePath to NuGet
5859
run: dotnet nuget push ./TruePath/bin/Release/TruePath.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN_TRUE_PATH }}
5960
- if: startsWith(github.ref, 'refs/tags/v')
60-
name: Push artifact to NuGet
61+
name: Push TruePath.SystemIo to NuGet
6162
run: dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.${{ steps.version.outputs.version }}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_TOKEN_TRUE_PATH_SYSTEM_IO }}

TruePath.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1818
REUSE.toml = REUSE.toml
1919
renovate.json = renovate.json
2020
renovate.json.license = renovate.json.license
21+
global.json = global.json
22+
global.json.license = global.json.license
2123
EndProjectSection
2224
EndProject
2325
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{8C064598-EE83-463D-9822-BAFA70B2C278}"

global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "10.0.102"
4+
}
5+
}

global.json.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2026 Friedrich von Never <friedrich@fornever.me>
2+
3+
SPDX-License-Identifier: MIT

scripts/github-actions.fsx

Lines changed: 95 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ let licenseHeader = """
55
66
# This file is auto-generated.""".Trim()
77

8-
#r "nuget: Generaptor.Library, 1.9.1"
8+
#r "nuget: Generaptor, 1.9.1"
99

1010
open System
1111
open Generaptor
1212
open Generaptor.GitHubActions
1313
open type Generaptor.GitHubActions.Commands
14-
open type Generaptor.Library.Actions
15-
open type Generaptor.Library.Patterns
1614

1715
let mainBranch = "main"
1816
let ubuntu = "ubuntu-24.04"
@@ -36,43 +34,83 @@ let workflows = [
3634
yield! actions
3735
]
3836

39-
workflow "main" [
40-
name "Main"
41-
yield! mainTriggers
37+
let checkOut = step(
38+
name = "Check out the sources",
39+
usesSpec = Auto "actions/checkout"
40+
)
4241

43-
job "verify-workflows" [
44-
runsOn "ubuntu-24.04"
42+
let dotNetJob id steps =
43+
job id [
44+
setEnv "DOTNET_CLI_TELEMETRY_OPTOUT" "1"
45+
setEnv "DOTNET_NOLOGO" "1"
46+
setEnv "NUGET_PACKAGES" "${{ github.workspace }}/.github/nuget-packages"
4547

46-
checkout
48+
checkOut
4749
step(
4850
name = "Set up .NET SDK",
4951
usesSpec = Auto "actions/setup-dotnet"
5052
)
53+
step(
54+
name = "Cache NuGet packages",
55+
usesSpec = Auto "actions/cache",
56+
options = Map.ofList [
57+
"key", "${{ runner.os }}.nuget.${{ hashFiles('**/*.*proj', '**/*.props') }}"
58+
"path", "${{ env.NUGET_PACKAGES }}"
59+
]
60+
)
61+
62+
yield! steps
63+
]
64+
65+
workflow "main" [
66+
name "Main"
67+
yield! mainTriggers
68+
69+
dotNetJob "verify-workflows" [
70+
runsOn "ubuntu-24.04"
5171
step(run = "dotnet fsi ./scripts/github-actions.fsx verify")
5272
]
5373

54-
job "check" [
55-
checkout
56-
yield! dotNetBuildAndTest(projectFileExtensions = [".csproj"])
57-
] |> addMatrix images
74+
dotNetJob "check" [
75+
strategy(failFast = false, matrix = [
76+
"image", [
77+
"macos-14"
78+
"ubuntu-24.04"
79+
"ubuntu-24.04-arm"
80+
"windows-11-arm"
81+
"windows-2025"
82+
]
83+
])
84+
runsOn "${{ matrix.image }}"
85+
86+
step(
87+
name = "Build",
88+
run = "dotnet build"
89+
)
90+
step(
91+
name = "Test",
92+
run = "dotnet test",
93+
timeoutMin = 10
94+
)
95+
]
5896

5997
job "licenses" [
6098
runsOn ubuntu
61-
checkout
99+
checkOut
62100

63101
step(name = "REUSE license check", usesSpec = Auto "fsfe/reuse-action")
64102
]
65103

66104
job "encoding" [
67105
runsOn ubuntu
68-
checkout
106+
checkOut
69107

70108
step(name = "Verify encoding", shell = "pwsh", run = "scripts/Test-Encoding.ps1")
71109
]
72110

73-
job "nowarn-empty" [
111+
dotNetJob "nowarn-empty" [
74112
runsOn ubuntu
75-
checkout
113+
checkOut
76114

77115
step(name = "Verify with NoWarn as empty", run = "dotnet build /p:NoWarn='' --no-incremental")
78116
]
@@ -84,15 +122,22 @@ let workflows = [
84122
onPushTags "v*"
85123
job "nuget" [
86124
runsOn ubuntu
87-
checkout
125+
checkOut
88126
jobPermission(PermissionKind.Contents, AccessKind.Write)
89127

90128
let configuration = "Release"
91129

92130
let versionStepId = "version"
93131
let versionField = "${{ steps." + versionStepId + ".outputs.version }}"
94-
getVersionWithScript(stepId = versionStepId, scriptPath = "scripts/Get-Version.ps1")
95-
dotNetPack(version = versionField)
132+
step(
133+
id = "version",
134+
name = "Get version",
135+
shell = "pwsh",
136+
run = "echo \"version=$(scripts/Get-Version.ps1 -RefName $env:GITHUB_REF)\" >> $env:GITHUB_OUTPUT"
137+
)
138+
step(
139+
run = "dotnet pack --configuration Release -p:Version=${{ steps.version.outputs.version }}"
140+
)
96141

97142
let releaseNotes = "./release-notes.md"
98143
step(
@@ -112,23 +157,35 @@ let workflows = [
112157
yield! artifacts "TruePath" true
113158
yield! artifacts "TruePath.SystemIo" true
114159
]
115-
uploadArtifacts [
116-
releaseNotes
117-
yield! allArtifacts
118-
]
119-
yield! ifCalledOnTagPush [
120-
createRelease(
121-
name = $"TruePath v{versionField}",
122-
releaseNotesPath = releaseNotes,
123-
files = allArtifacts
124-
)
125-
yield! pushToNuGetOrg "NUGET_TOKEN_TRUE_PATH" (
126-
artifacts "TruePath" false
127-
)
128-
yield! pushToNuGetOrg "NUGET_TOKEN_TRUE_PATH_SYSTEM_IO" (
129-
artifacts "TruePath.SystemIo" false
130-
)
131-
]
160+
161+
step(
162+
name = "Upload artifacts",
163+
usesSpec = Auto "actions/upload-artifact",
164+
options = Map.ofList [
165+
"path", [ releaseNotes; yield! allArtifacts ] |> String.concat "\n"
166+
]
167+
)
168+
169+
step(
170+
condition = "startsWith(github.ref, 'refs/tags/v')",
171+
name = "Create a release",
172+
usesSpec = Auto "softprops/action-gh-release",
173+
options = Map.ofList [
174+
"body_path", "./release-notes.md"
175+
"files", allArtifacts |> String.concat "\n"
176+
"name", $"TruePath v{versionField}"
177+
]
178+
)
179+
step(
180+
condition = "startsWith(github.ref, 'refs/tags/v')",
181+
name = "Push TruePath to NuGet",
182+
run = $"dotnet nuget push ./TruePath/bin/Release/TruePath.{versionField}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{{{ secrets.NUGET_TOKEN_TRUE_PATH }}}}"
183+
)
184+
step(
185+
condition = "startsWith(github.ref, 'refs/tags/v')",
186+
name = "Push TruePath.SystemIo to NuGet",
187+
run = $"dotnet nuget push ./TruePath.SystemIo/bin/Release/TruePath.SystemIo.{versionField}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{{{ secrets.NUGET_TOKEN_TRUE_PATH_SYSTEM_IO }}}}"
188+
)
132189
]
133190
]
134191

@@ -146,10 +203,7 @@ let workflows = [
146203
job "publish-docs" [
147204
environment(name = "github-pages", url = "${{ steps.deployment.outputs.page_url }}")
148205
runsOn "ubuntu-24.04"
149-
step(
150-
name = "Checkout",
151-
usesSpec = Auto "actions/checkout"
152-
)
206+
checkOut
153207
step(
154208
name = "Set up .NET SDK",
155209
usesSpec = Auto "actions/setup-dotnet",

0 commit comments

Comments
 (0)