Skip to content

Commit e2b1c26

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

File tree

2 files changed

+70
-28
lines changed

2 files changed

+70
-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: 68 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,76 @@ 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+
elif not(githubRef.StartsWith tagPrefix) then
117+
failwithf "Unexpected GITHUB_REF value: %s" githubRef
118+
119+
let nugetApiKeyVarName = "NUGET_API_KEY"
120+
let nugetApiKey = Environment.GetEnvironmentVariable nugetApiKeyVarName
121+
122+
if String.IsNullOrEmpty nugetApiKey then
123+
Console.WriteLine(
124+
sprintf
125+
"Secret '%s' not set as env var, skipping dotnet nuget push"
126+
nugetApiKeyVarName
127+
)
128+
129+
Environment.Exit 0
130+
131+
let githubEventName = Environment.GetEnvironmentVariable "GITHUB_EVENT_NAME"
132+
133+
match githubEventName with
134+
| "push" ->
135+
let nugetApiSource = "https://api.nuget.org/v3/index.json"
136+
137+
let NugetPush proj =
138+
Process
139+
.Execute(
140+
{
141+
Command = "dotnet"
142+
Arguments =
143+
sprintf
144+
"nuget push %s/nupkg/%s.%s.nupkg --api-key %s --source %s"
145+
proj
146+
proj
147+
fullVersion
148+
nugetApiKey
149+
nugetApiSource
150+
},
151+
Echo.All
152+
)
153+
.UnwrapDefault()
154+
|> ignore
155+
156+
for proj in projs do
157+
NugetPush proj
158+
159+
| null
160+
| "" -> failwith "The env var for github event name should have a value"
161+
162+
| _ ->
163+
Console.WriteLine
164+
"Github event name is not 'push', skipping dotnet nuget push"
165+
166+
Environment.Exit 0

0 commit comments

Comments
 (0)