build: preparing project layout

This commit is contained in:
D. Moonfire 2022-09-05 22:37:35 -05:00
parent e9fa2f6ce7
commit 341fbb071c
16 changed files with 332 additions and 171 deletions

18
.config/dotnet-tools.json Normal file
View file

@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"gitversion.tool": {
"version": "5.9.0",
"commands": [
"dotnet-gitversion"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.1.3",
"commands": [
"reportgenerator"
]
}
}
}

View file

@ -103,7 +103,7 @@ tab_width=2
[*.{cs,js,json,jsx,proto,resjson,ts,tsx}]
indent_style = space
indent_size=space
indent_size = 4
tab_width = 4
[*.{asax,ascx,aspx,cshtml,css,htm,html,master,razor,skin,vb,xaml,xamlx,xoml}]

3
.envrc
View file

@ -1 +1,2 @@
use flake
export PATH=$PWD/scripts:$PATH
use flake || use nix

14
.gitignore vendored
View file

@ -11,9 +11,15 @@ obj/
.idea/
_ReSharper.Caches/
node_modules/
# NixOS
.direnv/
coverage/
tests/artifacts/
# Tests and Coverage
coverage
TestResults/
.config/
.direnv/
tests/artifacts/
# Lefthook
.lefthook-local/
lefthook-local.yml

View file

@ -1,41 +0,0 @@
stages:
- build
- test
- release
default:
image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest
build:
stage: build
script:
- nix develop --command scripts/ci-build.sh
rules:
- if: $CI_COMMIT_BRANCH
test:
stage: test
script:
- nix develop --command scripts/ci-test.sh
rules:
- if: $CI_COMMIT_BRANCH
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
artifacts:
when: always
paths:
- ./**/*test-result.xml
- ./coverage/Cobertura.xml
- ./coverage/Summary.*
- ./**/*.nupkg
reports:
junit:
- ./**/*test-result.xml
cobertura:
- ./coverage/Cobertura.xml
release:
stage: release
script:
- nix develop --command scripts/ci-release.sh
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

36
.woodpecker.yml Normal file
View file

@ -0,0 +1,36 @@
clone:
git:
image: woodpeckerci/plugin-git
settings:
tags: true
pipeline:
build:
image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest
commands:
- nix develop --command scripts/build.sh
when:
event: [push, pull_request, tag]
tag: v*
test:
image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest
commands:
- nix develop --command scripts/test.sh
when:
event: [push, pull_request]
#paths:
# - ./**/*test-result.xml
# - ./coverage/Cobertura.xml
# - ./coverage/Summary.*
# - ./**/*.nupkg
release-main:
image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest
commands:
- nix develop --command scripts/release.sh
secrets:
- gitea_token
when:
event: push
branch: main

View file

@ -1,26 +0,0 @@
# [1.2.0](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/compare/v1.1.0...v1.2.0) (2022-02-16)
### Features
* added the abilty to add or remove the preformat block around tables ([0649c62](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/commit/0649c62685f16258daeba9450e0a09bcbe1352c0))
# [1.1.0](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/compare/v1.0.0...v1.1.0) (2022-02-16)
### Features
* added table rendering ([6fac646](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/commit/6fac646f189fdcc061c868b99e4f1174c08033ec))
# 1.0.0 (2021-09-07)
### Bug Fixes
* **test:** adding coverage test ([9250289](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/commit/925028984d782fc8f7a9a90812a6a57ae90cc617))
* correcting references and NuGet metadata ([de17b4a](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/commit/de17b4a75b3eed733f36032365d0f21d6a02e955))
### Features
* initial commit ([9fe90f8](https://gitlab.com/mfgames-cil/mfgames-markdown-gemtext-cil/commit/9fe90f820c7333d5cbc9b74cb301e64849ec21ca))

16
NuGet.Config Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="mfgames.com" value="https://src.mfgames.com/api/packages/mfgames-cil/nuget/index.json" protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="mfgames.com">
<package pattern="MfGames.*" />
</packageSource>
</packageSourceMapping>
</configuration>

22
lefthook.yml Normal file
View file

@ -0,0 +1,22 @@
pre-commit:
parallel: true
commands:
dotnet-format:
glob: "*.cs"
run: dotnet format
prettier:
run: prettier . --write --loglevel warn
nixfmt:
run: nixfmt flake.nix
commit-msg:
commands:
commit-check:
run: convco check -n 1
skip_output:
- meta # Skips lefthook version printing
- summary # Skips summary block (successful and failed steps) printing
- success # Skips successful steps printing
- failure # Skips failed steps printing
- execution # Skips printing successfully executed commands and their output (but still prints failed executions)

23
scripts/README.md Normal file
View file

@ -0,0 +1,23 @@
# Scripts Directory
This directory contains the basic scripts for working with the library.
## `setup.sh`
This verifies the environment is correct and makes sure everything is configured.
## `build.sh`
This builds the project and creates the binaries in debug mode.
## `test.sh`
This runs any required tests.
## `format.sh`
This is used to format the code base using our standards. It matches the commands in the `lefthook` pre-commit hook.
## `release.sh`
Intended to run in a CI environment, this creates a NuGet package and publishes it.

7
scripts/build.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
./scripts/setup.sh || exit 1
echo "$(basename $0): building project"
dotnet build

4
scripts/format.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
lefthook run pre-commit

51
scripts/release.sh Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
./scripts/setup.sh || exit 1
# Verify the input.
if [ "x$GITEA_TOKEN" = "x" ]
then
echo "the environment variable GITEA_TOKEN is not defined"
exit 1
fi
# Clean up everything from the previous runs.
echo "$(basename $0): cleaning project"
dotnet clean
# Version the file based on the Git repository.
echo "$(basename $0): setting project version"
(cd src && dotnet dotnet-gitversion /updateprojectfiles)
SEMVER="v$(dotnet gitversion /output json | jq -r .SemVer)"
if [ "x$SEMVER" = "x" ]
then
echo "$(basename $0): cannot figure out the semantic version"
exit 1
fi
# Build to pick up the new version.
echo "$(basename $0): building project $SEMVER"
dotnet build || exit 1
# Create and publish the NuGet packages.
echo "$(basename $0): creating NuGet packages"
dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg || exit 1
echo "$(basename $0): publishing NuGet package"
dotnet nuget remove source mfgames.com >& /dev/null
dotnet nuget add source --name mfgames.com --username dmoonfire --password $GITEA_TOKEN https://src.mfgames.com/api/packages/mfgames-cil/nuget/index.json --store-password-in-clear-text || exit 1
dotnet nuget push --skip-duplicate --source mfgames.com src/*/bin/Debug/*.nupkg || exit 1
# Tag and push, but only if we don't have a tag.
if ! git tag | grep $SEMVER >& /dev/null
then
echo "$(basename $0): tagging and pushing"
git remote add publish https://dmoonfire:$GITEA_TOKEN@src.mfgames.com/mfgames-cil/$(basename $(git config --get remote.origin.url))
git tag $SEMVER
git push publish $SEMVER || exit 1
git remote remove publish
else
echo "$(basename $0): not tagging, already exists"
fi

28
scripts/setup.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env sh
# Normalize our environment.
cd $(dirname $0)/..
# Make sure we have the needed executables installed.
for e in dotnet lefthook prettier nixfmt
do
if ! which $e >& /dev/null
then
echo "Cannot find '$e' in the path"
exit 1
fi
done
# Make sure we have lefthook is installed.
if [ ! -f .git/hooks/pre-commit ]
then
echo "$(basename $0): installing lefthook"
lefthook install
fi
# Make sure our tools are installed.
echo "$(basename $0): install .NET tools"
dotnet tool restore
# Everything is good.
exit 0

12
scripts/test.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
if [ -f ./tests/*/*.csproj ]
then
./scripts/setup.sh || exit 1
dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
grep "Line coverage" coverage/Summary.txt
fi

4
scripts/update-template.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
git pull template main --no-rebase