Skip to content

Commit 34818e9

Browse files
committed
GitHub,scripts: finish moving publish logic to F#
1 parent dd2b9c5 commit 34818e9

File tree

2 files changed

+71
-28
lines changed

2 files changed

+71
-28
lines changed

.github/workflows/CI.yml

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

31-
- name: Create nuget packages
32-
run: dotnet fsi scripts/pack.fsx
33-
34-
- name: Publish fsxc on NuGet website
35-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
36-
run: |
37-
. ./version.config
38-
dotnet nuget push fsxc/nupkg/fsxc.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
39-
- name: Publish Fsdk on NuGet website
40-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
41-
run: |
42-
. ./version.config
43-
dotnet nuget push Fsdk/nupkg/Fsdk.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
44-
- name: Publish fsx on NuGet website
45-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
46-
run: |
47-
. ./version.config
48-
dotnet nuget push fsx/nupkg/fsx.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
31+
- name: Publish nuget packages
32+
run: dotnet fsi scripts/publish.fsx
4933

5034
sanity-check:
5135
needs:

scripts/pack.fsx renamed to scripts/publish.fsx

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ let versionConfigFileName = "version.config"
2727
let versionConfigFile =
2828
Path.Combine(rootDir.FullName, versionConfigFileName) |> FileInfo
2929

30-
let AppendFullVersion fullVersion =
31-
let fullVersionVarAssignment =
32-
sprintf "%sFullVersion=%s" Environment.NewLine fullVersion
33-
34-
File.AppendAllText(versionConfigFile.FullName, fullVersionVarAssignment)
35-
3630
let tagPrefix = "refs/tags/"
3731

3832
let fullVersion =
@@ -85,8 +79,6 @@ let fullVersion =
8579

8680
fullVersion
8781

88-
AppendFullVersion fullVersion
89-
9082
let Pack proj =
9183
Process
9284
.Execute(
@@ -99,10 +91,77 @@ let Pack proj =
9991
proj
10092
fullVersion
10193
},
102-
Echo.Off
94+
Echo.All
10395
)
10496
.UnwrapDefault()
10597
|> ignore
10698

107-
for proj in [ "fsxc"; "Fsdk"; "fsx" ] do
99+
let projs = [ "fsxc"; "Fsdk"; "fsx" ]
100+
101+
for proj in projs do
108102
Pack proj
103+
104+
let defaultBranch = "master"
105+
let branchPrefix = "refs/heads/"
106+
107+
if githubRef.StartsWith branchPrefix then
108+
if not(githubRef.StartsWith(sprintf "%s%s" branchPrefix defaultBranch)) then
109+
Console.WriteLine(
110+
sprintf
111+
"Branch different than '%s', skipping dotnet nuget push"
112+
defaultBranch
113+
)
114+
115+
Environment.Exit 0
116+
else
117+
if not (githubRef.StartsWith tagPrefix) then
118+
failwithf "Unexpected GITHUB_REF value: %s" githubRef
119+
120+
let nugetApiKeyVarName = "NUGET_API_KEY"
121+
let nugetApiKey = Environment.GetEnvironmentVariable nugetApiKeyVarName
122+
123+
if String.IsNullOrEmpty nugetApiKey then
124+
Console.WriteLine(
125+
sprintf
126+
"Secret '%s' not set as env var, skipping dotnet nuget push"
127+
nugetApiKeyVarName
128+
)
129+
130+
Environment.Exit 0
131+
132+
let githubEventName = Environment.GetEnvironmentVariable "GITHUB_EVENT_NAME"
133+
134+
match githubEventName with
135+
| "push" ->
136+
let nugetApiSource = "https://api.nuget.org/v3/index.json"
137+
138+
let NugetPush proj =
139+
Process
140+
.Execute(
141+
{
142+
Command = "dotnet"
143+
Arguments =
144+
sprintf
145+
"nuget push %s/nupkg/%s.%s.nupkg --api-key %s --source %s"
146+
proj
147+
proj
148+
fullVersion
149+
nugetApiKey
150+
nugetApiSource
151+
},
152+
Echo.All
153+
)
154+
.UnwrapDefault()
155+
|> ignore
156+
157+
for proj in projs do
158+
NugetPush proj
159+
160+
| null
161+
| "" -> failwith "The env var for github event name should have a value"
162+
163+
| _ ->
164+
Console.WriteLine
165+
"Github event name is not 'push', skipping dotnet nuget push"
166+
167+
Environment.Exit 0

0 commit comments

Comments
 (0)