Skip to content

Commit

Permalink
Merge PR fsprojects#629 from knocte/nugetPreReleaseForEachCommitV3
Browse files Browse the repository at this point in the history
CI,build.fsx: publish prerelease nuget versions for every commit.
  • Loading branch information
knocte authored Dec 14, 2023
2 parents 47576d4 + 199b7ce commit 9618a8a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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 }}
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/buildAndTest.yml

This file was deleted.

5 changes: 5 additions & 0 deletions FSharpLint.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 61 additions & 31 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api

open System
open System.IO

Target.initEnvironment()
Expand All @@ -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
// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions nugetPreRelease.fsx
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9618a8a

Please sign in to comment.