diff --git a/.github/workflows/publish.yml b/.github/workflows/build+test+publish.yml similarity index 58% rename from .github/workflows/publish.yml rename to .github/workflows/build+test+publish.yml index 33964b4f8..9c9dc020e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/build+test+publish.yml @@ -1,12 +1,42 @@ -name: Publish +name: .NET 5.0 on: + pull_request: push: tags: - - 'v*' # Publish on any new tag + - 'v*' + branches: + - '*' jobs: - build: + buildAndTest: + + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + - macOS-latest + dotnet: [5.0.202] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v1 + - name: Setup .NET 5 + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore tools + run: dotnet tool restore + - name: Restore dependencies + run: dotnet restore + - name: Build and run tests + run: dotnet fake build -t Test + - name: Run FSharpLint on itself + run: dotnet fake build -t SelfCheck + + publish: + needs: buildAndTest strategy: matrix: @@ -32,12 +62,14 @@ jobs: with: version: ${{ github.ref }} path: ./CHANGELOG.md - - name: Upload binaries to nuget + - name: Upload binaries to nuget (if nugetKey present) env: nuget-key: ${{ secrets.NUGET_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: github.event_name == 'push' && env.nuget-key != null run: dotnet fake build -t Push - - name: Create Release + - name: Create Release (if tag) + if: startsWith(github.ref, 'refs/tags/') id: create_release uses: actions/create-release@latest env: @@ -48,7 +80,8 @@ jobs: body: ${{ steps.changelog_reader.outputs.log_entry }} draft: false prerelease: false - - name: Upload binaries to release + - name: Upload binaries to release (if tag) + if: startsWith(github.ref, 'refs/tags/') uses: svenstaro/upload-release-action@v1-release with: repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml deleted file mode 100644 index 48003da66..000000000 --- a/.github/workflows/buildAndTest.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: .NET 5.0 - -on: [push, pull_request] - -jobs: - buildAndTest: - - strategy: - matrix: - os: - - ubuntu-latest - - windows-latest - - macOS-latest - dotnet: [5.0.202] - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v1 - - name: Setup .NET 5 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: ${{ matrix.dotnet }} - - name: Restore tools - run: dotnet tool restore - - name: Restore dependencies - run: dotnet restore - - name: Build and run tests - run: dotnet fake build -t Test - - name: Run FSharpLint on itself - run: dotnet fake build -t SelfCheck diff --git a/FSharpLint.sln b/FSharpLint.sln index dc7a34f1b..99b625527 100644 --- a/FSharpLint.sln +++ b/FSharpLint.sln @@ -19,6 +19,11 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharpLint.Console.Tests", EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpLint.Benchmarks", "tests\FSharpLint.Benchmarks\FSharpLint.Benchmarks.fsproj", "{B4A92AC6-F74A-4709-B2F7-6C5BABBFDEB0}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{270E691D-ECA1-4BC5-B851-C5431A64E9FA}" + ProjectSection(SolutionItems) = preProject + build.fsx = build.fsx + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build.fsx b/build.fsx index 4d95f1a59..090779ba3 100644 --- a/build.fsx +++ b/build.fsx @@ -13,6 +13,7 @@ open Fake.IO.Globbing.Operators open Fake.Core.TargetOperators open Fake.Api +open System open System.IO Target.initEnvironment() @@ -30,48 +31,77 @@ let gitName = "FSharpLint" let gitHome = "https://github.com/" + gitOwner let gitUrl = gitHome + "/" + gitName +// -------------------------------------------------------------------------------------- +// Helpers +// -------------------------------------------------------------------------------------- +let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace + +let exec cmd args dir = + let proc = + CreateProcess.fromRawCommandLine cmd args + |> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args) + (if isNullOrWhiteSpace dir then proc + else proc |> CreateProcess.withWorkingDirectory dir) + |> Proc.run + |> ignore + +let getBuildParam = Environment.environVar +let DoNothing = ignore + // -------------------------------------------------------------------------------------- // Build variables // -------------------------------------------------------------------------------------- let buildDir = "./build/" let nugetDir = "./out/" +let rootDir = __SOURCE_DIRECTORY__ |> DirectoryInfo - -System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ +System.Environment.CurrentDirectory <- rootDir.FullName let changelogFilename = "CHANGELOG.md" let changelog = Changelog.load changelogFilename + +let githubRef = Environment.GetEnvironmentVariable "GITHUB_REF" +let tagPrefix = "refs/tags/" +let isTag = + if isNull githubRef then + false + else + githubRef.StartsWith tagPrefix + let nugetVersion = - match changelog.Unreleased with - | None -> + match (changelog.Unreleased, isTag) with + | (Some _unreleased, true) -> failwith "Shouldn't publish a git tag for changes outside a real release" + | (None, true) -> changelog.LatestEntry.NuGetVersion - | Some _unreleased -> + | (_, false) -> let current = changelog.LatestEntry.NuGetVersion |> SemVer.parse let bumped = { current with Minor = current.Minor + 1u Patch = 0u Original = None - PreRelease = PreRelease.TryParse "alpha01" } - string bumped - -let packageReleaseNotes = sprintf "%s/blob/v%s/CHANGELOG.md" gitUrl nugetVersion + PreRelease = None } + let bumpedBaseVersion = string bumped + + let nugetPreRelease = Path.Combine(rootDir.FullName, "nugetPreRelease.fsx") + let procResult = + CreateProcess.fromRawCommand + "dotnet" + [ + "fsi" + nugetPreRelease + bumpedBaseVersion + ] + |> CreateProcess.redirectOutput + |> CreateProcess.ensureExitCode + |> Proc.run + procResult.Result.Output.Trim() + +let PackageReleaseNotes baseProps = + if isTag then + ("PackageReleaseNotes", sprintf "%s/blob/v%s/CHANGELOG.md" gitUrl nugetVersion)::baseProps + else + baseProps -// -------------------------------------------------------------------------------------- -// Helpers -// -------------------------------------------------------------------------------------- -let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace - -let exec cmd args dir = - let proc = - CreateProcess.fromRawCommandLine cmd args - |> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args) - (if isNullOrWhiteSpace dir then proc - else proc |> CreateProcess.withWorkingDirectory dir) - |> Proc.run - |> ignore - -let getBuildParam = Environment.environVar -let DoNothing = ignore // -------------------------------------------------------------------------------------- // Build Targets // -------------------------------------------------------------------------------------- @@ -100,28 +130,29 @@ Target.create "Docs" (fun _ -> // -------------------------------------------------------------------------------------- // Release Targets // -------------------------------------------------------------------------------------- + Target.create "BuildRelease" (fun _ -> + let properties = ("Version", nugetVersion) |> List.singleton |> PackageReleaseNotes + DotNet.build (fun p -> { p with Configuration = DotNet.BuildConfiguration.Release OutputPath = Some buildDir - MSBuildParams = { p.MSBuildParams with Properties = [("Version", nugetVersion); ("PackageReleaseNotes", packageReleaseNotes)]} + MSBuildParams = { p.MSBuildParams with Properties = properties } } ) "FSharpLint.sln" ) Target.create "Pack" (fun _ -> - let properties = [ + let properties = PackageReleaseNotes ([ ("Version", nugetVersion); ("Authors", authors) ("PackageProjectUrl", gitUrl) ("RepositoryType", "git") ("RepositoryUrl", gitUrl) ("PackageLicenseExpression", "MIT") - ("PackageReleaseNotes", packageReleaseNotes) - ] - + ]) DotNet.pack (fun p -> { p with @@ -142,7 +173,6 @@ Target.create "Push" (fun _ -> Target.create "SelfCheck" (fun _ -> let frameworkVersion = "net5.0" - let rootDir = __SOURCE_DIRECTORY__ |> DirectoryInfo let srcDir = Path.Combine(rootDir.FullName, "src") |> DirectoryInfo let consoleProj = Path.Combine(srcDir.FullName, "FSharpLint.Console", "FSharpLint.Console.fsproj") |> FileInfo diff --git a/nugetPreRelease.fsx b/nugetPreRelease.fsx new file mode 100644 index 000000000..71cadf764 --- /dev/null +++ b/nugetPreRelease.fsx @@ -0,0 +1,6 @@ +#r "nuget: Fsdk, Version=0.6.0--date20231213-0703.git-d7a5962" + +let args = fsi.CommandLineArgs + +Fsdk.Network.GetNugetPrereleaseVersionFromBaseVersion args.[1] +|> System.Console.WriteLine