This is a cross platform Github template for F#, using Paket as
Nuget package manager, Fake as build system, MkDocs
to generate HTML documentation at Read The Docs,
Expecto, Unquote
and FsCheck for the testing, AltCover to generate
coverage reports for CodeCov, FSharpLint
as static code checker and Github workflows.
Includes a F# Jupyter Notebook with a postBuild script for myBinder
to be able to use C# and PowerShell Kernels for the notebooks too.
This template (and .DotNet 5.0) is tested and runs on Linux, Mac OS X and Windows.
- Replace the string
FSHARP_TEMPLATE(and TEMPALTE and FHARP) with the real project name(s), and my name too, if you aren't me ;). - Add the Nuget key and the Codecov token as secrets
to the repository, named
CODECOV_SECRETandNUGET_PACKAGE. - Rename, move and edit the two project files,
src/LibTemplate/LibTemplate.fsprojandtests/TestsTemplate/TestsTemplate.fsprojSame with the source files insrc/LibTemplateandtests/TestsTemplate - Change this
Readme.md - Change the documentation in
docs/ - Add a solution file (
.sln) in this root directory - Add the source project(s) in
src/and the test projects intests/to the solution - Edit the GitHub workflow
.github/workflows/create_packages.ymlto append your generated binaries to the releases
There is an interactive F# Jupyter Notebook at .
The file postBuild holds the configuration for the Docker image generation
at MyBinder, the Jupyter Notebook file is TestFSharp.ipynb. The
Notebook supports C# and Powershell too.
For more information, see .Net Interactive
Before you can use the configured Tools of this template,
You have to download and install (aka. restore) the packages
of the tools.
-
First, download and install the "dotnet tools" using the command
dotnet tool restore
now you have installed Fake, Paket and FSharpLint, configured in the file
.config/dotnet-tools.json -
Download and install ("restore") the Paket Nuget packages.
dotnet paket restore
-
Delete the file
build.fsx.lockand run Fake, to download and install (restore) it's nuget packages.dotnet fake run build.fsx
-
To generate the documentation using MkDocs, a virtual Python environment is needed. A virtual Python environment is the same as the locally installed Nuget packages above. So, first you need to install Python, if you don't have it installed already - either from your distributions repository, using the XCode or Homebrew version, or getting it from Python.org. In the file
Pipfilethere is a stanza saying[requires] python_version = "3.9"
That's just because I used 3.9 when generating that template, and Pipenv is picky about the version mentioned there. Just edit that to match your installed Python version. Install
pipenvusing the package manager pippip install pipenv
Now you're ready to download and install the needed packages using pipenv
pipenv install --dev
- All build artifacts are generated in the directory
artifacts, set using the expressionbuildOutputPathinbuild.fsx. - NuGet packages generated by the target
Packagesare saved to the directorypackages, set using the expressionpackageOutputPathinbuild.fsx. - The test results of the targets
TestsandTestsDebare saved as a.trxfile in the directorytest_results, set using the expressiontestOutputPathinbuild.fsx. - The coverage report
coverage.xmlof the targetsTestsCoverageandTestsCoverageDebis saved to the directorytest_results, set using the expressiontestOutputPathinbuild.fsx. - The output of the
Publishtarget is copied to the directorybin, set using the expressionexeOutPathinbuild.fsx.
Warning:
All of these directories are cleaned - that means all files in them are deleted - using the target clean.
Which is called as the first build step of all targets. In other words: all generated
files (including Nuget packages) are deleted when calling any target.
The Fake script build.fsx defines the following targets:
-
Cleandeletes all files generated by the build. This is called first in every other target, all generated files are deleted before running any target! -
Distcleandeletes everything that isn't checked in to Git -
BuildandBuildDebbuild the configured projects usingdotnet build. Without suffix a release build is made,BuildDebuses the debug configuration. Default is to build all projects found in the directoriessrcandtests. The expressionbuildProjsinbuild.fsxdefines the projects to build. -
Docsgenerates the HTML documentation using MkDocs. The HTML is created in the directorysites. The output directory is configured in the MkDocs config filemkdocs.yml -
Lintruns FSharpLint on all configured projects. Default is all projects,lintProjsinbuild.fsxdefines the projects to runLinton. -
TestsandTestsDebbuild and run all test projects in the directorytestsusingdotnet test. Without suffix a release build is made,TestsDebuses the debug configuration. Default is testing all projects in the directorytests,testProjsinbuild.fsxdefines the projects to runTestsandTestsDebon. -
TestsCoverageandTestsCoverageDebbuild and run all tests projects and generate a coverage report using AltCover. With and without suffix a debug configuration is build and tested. Default is testing all projects in the directorytests,testProjsinbuild.fsxdefines the projects to runTestsCoverageandTestsCoverageDebon. -
Publishrunsdotnet publishon the configured projects, default is all insrc. The build is done with the release configuration, the version must be given as argument on the command line and be the same as the newest one in CHANGELOG.md.publishProjsinbuild.fsxdefines the projects to runPublishon. Published binaries are saved to the directorybin. -
Packagesbuilds the NuGet packages of all projects using a release build. The build is done with the release configuration, the version must be given as argument on the command line and be the same as the newest one in CHANGELOG.md.packageProjsinbuild.fsxdefines the projects to runPackageson. Packages are saved to the directorypackages -
Uploaduploads all packages in the directorypackagesto NuGet.org. The NuGet API key needs to be saved to the configuration usingnuget setApiKey API_KEY
-
Releaseis a pseudo-target, the same asBuild,Docs,Publish,PackagesandUpload. The build is done with the release configuration, the version must be given as argument on the command line and be the same as the newest one in CHANGELOG.md. -
Allis a pseudo-target, the same asBuildandDocs,
Usage:
dotnet fake build.fsx target TARGET VERSION_STRINGTARGETis the name of the target to call, see above list for possible targetsVERSION_STRINGis the version to use for the target, must be the same as the first (newest) version in the fileCHANGELOG.md. Targets that needVERSION_STRINGarePackages,Publish,UploadandRelease.
Run all default targets (see above):
dotnet fake build.fsxWhich is the same as
dotnet fake run build.fsx target AllE.g. to build a debug version of all projects:
dotnet fake run build.fsx target BuildDebGenerate the Nuget packages of version 2.65.93 and upload to NuGet.org
dotnet fake run build.fsx target Upload 2.65.93Run dotnet publish on the configured projects (publishProjs in build.fsx) setting the
version to 6.2.53
dotnet fake run build.fsx target Publish 6.2.53Run the tests - result is in the directory test_results:
dotnet fake run build.fsx target TestsRun the tests with coverage analysis - result is in the directory test_results:
dotnet fake run build.fsx target TestsCoverage-
mkdocs.ymlthe MkDocs configuration, specially the configuration of the navigation sidebar innavWhich you need to editnav: - Home: index.md - Project Links: - 'GitHub Project Page': 'https://github.com/Release-Candidate/FSHARP_TEMPLATE' - 'Nuget Package': 'https://pypi.org/project/FSHARP_TEMPLATE/' - 'Report a Bug or a Feature Request': 'https://github.com/Release-Candidate/FSHARP_TEMPLATE/issues/new/choose' - 'Issue Tracker at GitHub': 'https://github.com/Release-Candidate/FSHARP_TEMPLATE/issues' - 'Installation & Usage': - 'Installation & Usage': usage.md - License: license.md - Contributing: - Contributing: contributing.md
-
/docsthe markdown files that are used to generate the HTML sites in the directorysites
Generate an account at Read the Docs, and link your GitHub repositories.
.readthedocs.yamlthe configuration for Read the Docs/docs/requirements.txtthe packages needed by MkDocs when generating the documentation at Read the Docs. Locally needed packages are configured inPipfile
Read the Docs automatically generates the MkDocs documentation after each git push.
Generate an account at CodeCov, link your GitHub repositories, add the CodeCov token
as a secret to the GitHub repositories named CODECOV_SECRET and upload the coverage result
using a GitHub action. Used in the workflows linux_test.yml,
osx_test.yml and windows_test.yml
- name: Run Tests
run: |
cd $GITHUB_WORKSPACE
dotnet fake run ./build.fsx target TestsCoverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
if: ${{ always() }}
with:
token: ${{ secrets.CODECOV_SECRET }}
files: ./test_results/coverage.xml
directory: ./coverage/reports/
# flags: unittest
env_vars: OS,PYTHON
name: Linux-Test-Src
fail_ci_if_error: false
path_to_write_report: ./coverage/codecov_report.txt
verbose: trueAll tests and builds are executed on Linux, Mac OS X and Windows.
These are the GitHub workflows defined in the directory .github/workflows
create_packages.ymlcreates and uploads the NuGet packages, runsdotnet publishand generates a new GitHUb release with these files appended. Run automatically after tagging the source with a release tag of the formv?.?.?(must be the same version as the newest in CHANGELOG.md). Appends the newest entry in CHANGELOG.md to the release - scriptscripts/get_changelog.shSee the latest release as an examplefsharplint.ymlruns FSharpLint on all projects, after eachgit pushlinux.ymlruns a default build (targetAll) on Linux, after eachgit pushlinux_test.ymlruns the tests and coverage tests on Linux, uploads the test results as artifacts, uploads the coverage results to CodeCov.osx.ymlruns a default build (targetAll) on Mac OS X, after eachgit pushosx_test.ymlruns the tests and coverage tests on Mac OS X, uploads the test results as artifacts, uploads the coverage results to CodeCov.windows.ymlruns a default build (targetAll) on Windows, after eachgit pushwindows_test.ymlruns the tests and coverage tests on Windows, uploads the test results as artifacts, uploads the coverage results to CodeCov.
The badges of the workflows are linked in the section Badges
Issue templates for GitHub in .github/ISSUE_TEMPLATE/
bug_report.mdBug report templatefeature_request.mdFeature request template
List of changes: CHANGELOG.md
All content of FSHARP_TEMPLATE is licensed under the MIT license, see file LICENSE.