Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI,make.fsx: upload a nuget package #266

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,39 @@ jobs:
if: github.event_name == 'pull_request'
run: ./conventions/commitlint.sh --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

snap_pkg:

nuget_pkg_beta:
needs:
- conventions

runs-on: ubuntu-22.04
container:
image: "ubuntu:22.04"

env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

steps:
- uses: actions/checkout@v1
- name: install sudo
run: apt update && apt install --yes sudo
- name: install all dependencies
run: sudo DEBIAN_FRONTEND=noninteractive apt install --yes git make dotnet6
# workaround for https://github.com/actions/runner/issues/2033
- name: ownership workaround
run: git config --global --add safe.directory '*'
- name: configure
run: ./configure.sh --native-segwit
- name: Bump version to beta (because segwit)
run: |
./scripts/populate_gitsubmodules.sh
dotnet fsi ./scripts/beta_bump.fsx
- name: pack&push
run: make push

snap_pkg:
needs:
- nuget_pkg_beta

runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -538,7 +566,7 @@ jobs:
snap_pkg_beta:

needs:
- conventions
- nuget_pkg_beta

runs-on: ubuntu-22.04
steps:
Expand All @@ -557,8 +585,8 @@ jobs:

- name: Bump snap version
run: |
git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive
dotnet fsi ./scripts/snap_bump.fsx
./scripts/populate_gitsubmodules.sh
dotnet fsi ./scripts/beta_bump.fsx

- name: Generate snap package
run: |
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ update-servers:
nuget:
@./scripts/make.sh nuget

push:
@./scripts/make.sh push

sanitycheck:
@./scripts/make.sh sanitycheck

Expand Down
2 changes: 2 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
<config>
<!-- TODO: file a VS4Mac bug about this below setting making the tests disappear from the Tests view -->
<add key="globalPackagesFolder" value="packages" />

<add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" />
</config>
</configuration>
11 changes: 1 addition & 10 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ else

cp NuGet-legacy.config NuGet.config

if [ ! -f scripts/fsx/configure.sh ]; then
if ! which git >/dev/null 2>&1; then
echo "checking for git... not found" $'\n'

echo "$0" $'failed, please install "git" (to populate submodule) first'
exit 1
fi
echo "Populating sub-fsx module..."
git submodule sync --recursive && git submodule update --init --recursive
fi
./scripts/populate_gitsubmodules.sh

FSX_CHECK_MSG="checking for fsx..."
if ! which fsharpi >/dev/null 2>&1; then
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/bump.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ let RunUpdateServers () =


if not replaceScript.Exists then
Console.Error.WriteLine "Script replace.fsx not found, 'fsx' submodule not populated? Please run `git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive`"
Console.Error.WriteLine "Script replace.fsx not found, 'fsx' submodule not populated? Please run `populate_gitsubmodules.sh`"
Environment.Exit 1

GitDiff()
Expand Down
152 changes: 134 additions & 18 deletions scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open System.Linq
open System.Diagnostics

#if !LEGACY_FRAMEWORK
#r "nuget: Fsdk, Version=0.6.0--date20230818-1152.git-83d671b"
#r "nuget: Fsdk, Version=0.6.0--date20240306-1035.git-a0a5c67"
#else
#r "System.Configuration"
open System.Configuration
Expand All @@ -30,6 +30,8 @@ let GTK_FRONTEND_APP = sprintf "%s.Frontend.XF.Gtk" PASCALCASE_NAME
let CONSOLE_FRONTEND_APP = sprintf "%s.Frontend.ConsoleApp" PASCALCASE_NAME
let BACKEND_LIB = sprintf "%s.Backend" PASCALCASE_NAME

let currentVersion = Misc.GetCurrentVersion FsxHelper.RootDir

type FrontendProject =
| XF
| Gtk
Expand Down Expand Up @@ -172,19 +174,7 @@ let PrintNugetVersion () =
Console.Out.Flush()
failwith "nuget process' output contained errors ^"

let BuildSolutionOrProject
(buildToolAndBuildArg: string*string)
(file: FileInfo)
(binaryConfig: BinaryConfig)
(maybeConstant: Option<string>)
(extraOptions: string)
=
#if LEGACY_FRAMEWORK
NugetRestore file
#endif

let buildTool,buildArg = buildToolAndBuildArg

let GetBuildFlags (buildTool: string) (binaryConfig) (maybeConstant: Option<string>) =
let configOption =
if buildTool.StartsWith "dotnet" then
sprintf "--configuration %s" (binaryConfig.ToString())
Expand Down Expand Up @@ -233,6 +223,24 @@ let BuildSolutionOrProject
sprintf "%s -property:DefineConstants=\\\"%s\\\"" configOption (String.Join(semiColon, defineConstants))
else
configOption

configOptions

let BuildSolutionOrProject
(buildToolAndBuildArg: string*string)
(file: FileInfo)
(binaryConfig: BinaryConfig)
(maybeConstant: Option<string>)
(extraOptions: string)
=
#if LEGACY_FRAMEWORK
NugetRestore file
#endif

let buildTool,buildArg = buildToolAndBuildArg

let configOptions = GetBuildFlags buildTool binaryConfig maybeConstant

let buildArgs = sprintf "%s %s %s %s"
buildArg
file.FullName
Expand Down Expand Up @@ -403,6 +411,7 @@ let GetPathToFrontend (frontend: FrontendApp) (binaryConfig: BinaryConfig): Dire

let GetPathToBackend () =
Path.Combine (FsxHelper.RootDir.FullName, "src", BACKEND_LIB)
|> DirectoryInfo

let MakeAll (maybeConstant: Option<string>) =
#if LEGACY_FRAMEWORK
Expand Down Expand Up @@ -463,14 +472,12 @@ match maybeTarget with
let zipCommand = "zip"
MakeCheckCommand zipCommand

let version = (Misc.GetCurrentVersion FsxHelper.RootDir).ToString()

let release = BinaryConfig.Release
let frontend,script = JustBuild release None
let binDir = "bin"
Directory.CreateDirectory(binDir) |> ignore

let zipNameWithoutExtension = sprintf "%s-v%s" script.Name version
let zipNameWithoutExtension = sprintf "%s-v%s" script.Name (currentVersion.ToString())
let zipName = sprintf "%s.zip" zipNameWithoutExtension
let pathToZip = Path.Combine(binDir, zipName)
if (File.Exists (pathToZip)) then
Expand Down Expand Up @@ -623,7 +630,7 @@ match maybeTarget with

| Some "update-servers" ->
let _,buildConfig = MakeAll None
Directory.SetCurrentDirectory (GetPathToBackend())
Directory.SetCurrentDirectory (GetPathToBackend().FullName)
let proc1 = RunFrontend FrontendApp.Console buildConfig (Some "--update-servers-file")
if proc1.ExitCode <> 0 then
Environment.Exit proc1.ExitCode
Expand Down Expand Up @@ -663,6 +670,115 @@ match maybeTarget with
Echo.All
).UnwrapDefault() |> ignore<string>

| Some "push" ->
#if LEGACY_FRAMEWORK
Console.Error.WriteLine "Pushing a nuget package is not supported with .NET legacy or Mono"
Environment.Exit 1
#else
let githubRef = Environment.GetEnvironmentVariable "GITHUB_REF"
if isNull githubRef then
Console.Error.WriteLine "Pushing a nuget package is only meant for GitHub CI jobs"
Environment.Exit 1

let tagPrefix = "refs/tags/"
let masterBranchRef = "refs/heads/master"
let isTag =
githubRef.StartsWith tagPrefix

let backendDir = GetPathToBackend()
let backendProj = Path.Combine(backendDir.FullName, BACKEND_LIB + ".fsproj")

let createNugetPackageFile versionToPack =
let binaryConfig =
if isTag then
BinaryConfig.Release
else
BinaryConfig.Debug
let buildFlags = GetBuildFlags "dotnet" binaryConfig None
let allBuildFlags = sprintf "%s -property:Version=%s" buildFlags versionToPack
let maybeWarnAsError =
if currentVersion.Minor % 2 = 0 then
"-warnaserror"
else
String.Empty
Process.Execute(
{
Command = "dotnet"
Arguments = sprintf "pack %s %s %s" maybeWarnAsError allBuildFlags backendProj
},
Echo.All
).UnwrapDefault() |> ignore<string>

Directory.GetFiles(backendDir.FullName, "*.nupkg", SearchOption.AllDirectories)
|> Seq.tryExactlyOne

// try first to create a non-prerelease package (as we want to fail fast instead of just fail at git tag push)
let maybeNupkg = createNugetPackageFile (currentVersion.ToString())
let nupkg =
match maybeNupkg with
| None -> failwith "File *.nupkg not found, did `dotnet pack` work properly?"
| Some nupkg ->
if isTag then
nupkg
else
File.Delete nupkg
let nugetVersion = Network.GetNugetPrereleaseVersionFromBaseVersion (currentVersion.ToString())
match createNugetPackageFile nugetVersion with
| None ->
failwith "File *.nupkg not found (prerelease), did `dotnet pack` work properly?"
| Some nupkg ->
nupkg

let nugetApiKey = Environment.GetEnvironmentVariable "NUGET_API_KEY"
if String.IsNullOrEmpty nugetApiKey then
Console.WriteLine "NUGET_API_KEY not found, skipping push"
Environment.Exit 0
else
let push() =
Process.Execute(
{
Command = "dotnet"
Arguments = sprintf "nuget push --api-key %s %s" nugetApiKey nupkg
},
Echo.All
).UnwrapDefault() |> ignore<string>

let eventName = Environment.GetEnvironmentVariable "GITHUB_EVENT_NAME"
if isNull eventName then
failwith "Env var 'GITHUB_EVENT_NAME' not set; not running as GitHubActions job?"
if eventName <> "push" then
Console.WriteLine "GitHubActions event not 'push', skipping..."
Environment.Exit 0

if isTag then
push()
else
if githubRef <> masterBranchRef then
Console.WriteLine "Pushed to non-master branch, skipping..."
Environment.Exit 0

let commitHash = Environment.GetEnvironmentVariable "GITHUB_SHA"
if isNull commitHash then
failwith "Env var 'GITHUB_SHA' not set; not running as GitHubActions job?"
let gitArgs = sprintf "describe --exact-match --tags %s" commitHash
let gitProcRes =
Process.Execute(
{
Command = "git"
Arguments = gitArgs
},
Echo.All
).Result
match gitProcRes with
| ProcessResultState.Success _ ->
Console.WriteLine "Commit mapped to a tag, skipping pushing prerelease..."
Environment.Exit 0
| ProcessResultState.Error _ ->
push()
| _ ->
failwith "warning from git command?"
#endif

| Some(someOtherTarget) ->
Console.Error.WriteLine("Unrecognized target: " + someOtherTarget)
Environment.Exit 2
12 changes: 12 additions & 0 deletions scripts/populate_gitsubmodules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

if ! which git >/dev/null 2>&1; then
echo "checking for git... not found" $'\n'

echo "$0" $'failed, please install "git" (to populate submodules) first'
exit 1
fi
echo "Populating git submodules..."

git submodule foreach git fetch --all && git submodule sync --recursive && git submodule update --init --recursive
Loading