Skip to content

Commit

Permalink
GitHub,scripts: finish moving publish logic to F#
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Mar 19, 2023
1 parent dd2b9c5 commit 34818e9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 28 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,8 @@ jobs:
- name: ownership workaround
run: git config --global --add safe.directory '*'

- name: Create nuget packages
run: dotnet fsi scripts/pack.fsx

- name: Publish fsxc on NuGet website
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
run: |
. ./version.config
dotnet nuget push fsxc/nupkg/fsxc.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
- name: Publish Fsdk on NuGet website
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
run: |
. ./version.config
dotnet nuget push Fsdk/nupkg/Fsdk.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
- name: Publish fsx on NuGet website
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && env.NUGET_API_KEY != null
run: |
. ./version.config
dotnet nuget push fsx/nupkg/fsx.$FullVersion.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
- name: Publish nuget packages
run: dotnet fsi scripts/publish.fsx

sanity-check:
needs:
Expand Down
79 changes: 69 additions & 10 deletions scripts/pack.fsx → scripts/publish.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ let versionConfigFileName = "version.config"
let versionConfigFile =
Path.Combine(rootDir.FullName, versionConfigFileName) |> FileInfo

let AppendFullVersion fullVersion =
let fullVersionVarAssignment =
sprintf "%sFullVersion=%s" Environment.NewLine fullVersion

File.AppendAllText(versionConfigFile.FullName, fullVersionVarAssignment)

let tagPrefix = "refs/tags/"

let fullVersion =
Expand Down Expand Up @@ -85,8 +79,6 @@ let fullVersion =

fullVersion

AppendFullVersion fullVersion

let Pack proj =
Process
.Execute(
Expand All @@ -99,10 +91,77 @@ let Pack proj =
proj
fullVersion
},
Echo.Off
Echo.All
)
.UnwrapDefault()
|> ignore

for proj in [ "fsxc"; "Fsdk"; "fsx" ] do
let projs = [ "fsxc"; "Fsdk"; "fsx" ]

for proj in projs do
Pack proj

let defaultBranch = "master"
let branchPrefix = "refs/heads/"

if githubRef.StartsWith branchPrefix then
if not(githubRef.StartsWith(sprintf "%s%s" branchPrefix defaultBranch)) then
Console.WriteLine(
sprintf
"Branch different than '%s', skipping dotnet nuget push"
defaultBranch
)

Environment.Exit 0
else
if not (githubRef.StartsWith tagPrefix) then
failwithf "Unexpected GITHUB_REF value: %s" githubRef

let nugetApiKeyVarName = "NUGET_API_KEY"
let nugetApiKey = Environment.GetEnvironmentVariable nugetApiKeyVarName

if String.IsNullOrEmpty nugetApiKey then
Console.WriteLine(
sprintf
"Secret '%s' not set as env var, skipping dotnet nuget push"
nugetApiKeyVarName
)

Environment.Exit 0

let githubEventName = Environment.GetEnvironmentVariable "GITHUB_EVENT_NAME"

match githubEventName with
| "push" ->
let nugetApiSource = "https://api.nuget.org/v3/index.json"

let NugetPush proj =
Process
.Execute(
{
Command = "dotnet"
Arguments =
sprintf
"nuget push %s/nupkg/%s.%s.nupkg --api-key %s --source %s"
proj
proj
fullVersion
nugetApiKey
nugetApiSource
},
Echo.All
)
.UnwrapDefault()
|> ignore

for proj in projs do
NugetPush proj

| null
| "" -> failwith "The env var for github event name should have a value"

| _ ->
Console.WriteLine
"Github event name is not 'push', skipping dotnet nuget push"

Environment.Exit 0

0 comments on commit 34818e9

Please sign in to comment.