Skip to content

Commit dd2b9c5

Browse files
committed
GitHubCI,scripts: move more YML logic to F#
1 parent ce51031 commit dd2b9c5

File tree

3 files changed

+111
-95
lines changed

3 files changed

+111
-95
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,9 @@ jobs:
2828
- name: ownership workaround
2929
run: git config --global --add safe.directory '*'
3030

31-
- name: Extract full version
32-
run: dotnet fsi scripts/prePublish.fsx
33-
- name: Pack the fsxc NuGet package
34-
run: |
35-
. ./version.config
36-
dotnet pack fsxc/fsxc.fsproj -p:PackageVersion=$FullVersion
37-
- name: Pack the Fsdk NuGet package
38-
run: |
39-
. ./version.config
40-
dotnet pack Fsdk/Fsdk.fsproj -p:PackageVersion=$FullVersion
41-
- name: Pack the fsx NuGet package
42-
run: |
43-
. ./version.config
44-
dotnet pack fsx/fsx.fsproj -p:PackageVersion=$FullVersion
31+
- name: Create nuget packages
32+
run: dotnet fsi scripts/pack.fsx
33+
4534
- name: Publish fsxc on NuGet website
4635
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
4736
run: |

scripts/pack.fsx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
open System
2+
open System.IO
3+
4+
#r "System.Configuration"
5+
open System.Configuration
6+
7+
#load "../Fsdk/Misc.fs"
8+
#load "../Fsdk/Process.fs"
9+
#load "../Fsdk/Network.fs"
10+
#load "../Fsdk/Git.fs"
11+
12+
open Fsdk
13+
open Fsdk.Process
14+
15+
let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
16+
17+
let githubRef = Environment.GetEnvironmentVariable "GITHUB_REF"
18+
19+
if String.IsNullOrEmpty githubRef then
20+
Console.Error.WriteLine
21+
"This script is only meant to be launched within a CI pipeline"
22+
23+
Environment.Exit 1
24+
25+
let versionConfigFileName = "version.config"
26+
27+
let versionConfigFile =
28+
Path.Combine(rootDir.FullName, versionConfigFileName) |> FileInfo
29+
30+
let AppendFullVersion fullVersion =
31+
let fullVersionVarAssignment =
32+
sprintf "%sFullVersion=%s" Environment.NewLine fullVersion
33+
34+
File.AppendAllText(versionConfigFile.FullName, fullVersionVarAssignment)
35+
36+
let tagPrefix = "refs/tags/"
37+
38+
let fullVersion =
39+
if githubRef.StartsWith tagPrefix then
40+
githubRef.Substring tagPrefix.Length
41+
else
42+
let baseVersionTokenString = "BaseVersion="
43+
44+
let rec ReadBaseVersion(lines: seq<string>) =
45+
match Seq.tryHead lines with
46+
| None -> None
47+
| Some line ->
48+
if line.StartsWith baseVersionTokenString then
49+
line.Substring baseVersionTokenString.Length |> Some
50+
else
51+
ReadBaseVersion <| Seq.tail lines
52+
53+
let maybeBaseVersion =
54+
ReadBaseVersion <| File.ReadAllLines versionConfigFile.FullName
55+
56+
match maybeBaseVersion with
57+
| None ->
58+
failwithf
59+
"%s file should contain a line with %s var set"
60+
versionConfigFile.Name
61+
baseVersionTokenString
62+
| Some baseVersion ->
63+
let nugetPush =
64+
Path.Combine(rootDir.FullName, "Tools", "nugetPush.fsx")
65+
|> FileInfo
66+
67+
// to disable welcome msg, see https://stackoverflow.com/a/70493818/544947
68+
Environment.SetEnvironmentVariable("DOTNET_NOLOGO", "true")
69+
70+
let fullVersion =
71+
Process
72+
.Execute(
73+
{
74+
Command = "dotnet"
75+
Arguments =
76+
sprintf
77+
"fsi %s --output-version %s"
78+
nugetPush.FullName
79+
baseVersion
80+
},
81+
Echo.Off
82+
)
83+
.UnwrapDefault()
84+
.Trim()
85+
86+
fullVersion
87+
88+
AppendFullVersion fullVersion
89+
90+
let Pack proj =
91+
Process
92+
.Execute(
93+
{
94+
Command = "dotnet"
95+
Arguments =
96+
sprintf
97+
"pack %s/%s.fsproj -property:PackageVersion=%s"
98+
proj
99+
proj
100+
fullVersion
101+
},
102+
Echo.Off
103+
)
104+
.UnwrapDefault()
105+
|> ignore
106+
107+
for proj in [ "fsxc"; "Fsdk"; "fsx" ] do
108+
Pack proj

scripts/prePublish.fsx

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

0 commit comments

Comments
 (0)