From 9a713fae0e74927610da1f2d602b5442f7eae0fd Mon Sep 17 00:00:00 2001 From: "D. Moonfire" Date: Mon, 5 Sep 2022 22:06:02 -0500 Subject: [PATCH] fix: integrating common project layout --- NuGet.Config | 15 ++++++++++++--- flake.lock | 12 ++++++------ lefthook.yml | 18 ++++++++++++------ scripts/build.sh | 1 + scripts/format.sh | 12 +----------- scripts/release.sh | 34 +++++++++++++++++++--------------- scripts/setup.sh | 7 ++++++- scripts/update-template.sh | 4 ++++ 8 files changed, 61 insertions(+), 42 deletions(-) create mode 100755 scripts/update-template.sh diff --git a/NuGet.Config b/NuGet.Config index af8eac9..ff47af7 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,16 @@ - + - + + - + + + + + + + + + diff --git a/flake.lock b/flake.lock index 2e87e5b..b67b61d 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1648297722, - "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "owner": "numtide", "repo": "flake-utils", - "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1648390671, - "narHash": "sha256-u69opCeHUx3CsdIerD0wVSR+DjfDQjnztObqfk9Trqc=", + "lastModified": 1662019588, + "narHash": "sha256-oPEjHKGGVbBXqwwL+UjsveJzghWiWV0n9ogo1X6l4cw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ce8cbe3c01fd8ee2de526ccd84bbf9b82397a510", + "rev": "2da64a81275b68fdad38af669afeda43d401e94b", "type": "github" }, "original": { diff --git a/lefthook.yml b/lefthook.yml index 795ae24..43a0f2b 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,9 +1,3 @@ -pre-push: - parallel: true - commands: - commit-check: - run: convco check -n 30 - pre-commit: parallel: true commands: @@ -14,3 +8,15 @@ pre-commit: 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) diff --git a/scripts/build.sh b/scripts/build.sh index 0cda922..66f32c5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,4 +3,5 @@ cd $(dirname $0)/.. ./scripts/setup.sh || exit 1 +echo "$(basename $0): building project" dotnet build diff --git a/scripts/format.sh b/scripts/format.sh index fd015be..7b31af0 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -1,14 +1,4 @@ #!/usr/bin/env sh -# Normalize our environment. cd $(dirname $0)/.. -./scripts/setup.sh || exit 1 - -# Format the .NET code -dotnet format || exit 1 - -# Format using Prettier. -prettier . --write --loglevel warn - -# Format the Flake. -nixfmt flake.nix +lefthook run pre-commit diff --git a/scripts/release.sh b/scripts/release.sh index 6cc26bf..94ed900 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -4,44 +4,48 @@ cd $(dirname $0)/.. ./scripts/setup.sh || exit 1 # Verify the input. -if [ "x$NUGET_TOKEN" = "x" ] +if [ "x$GITEA_TOKEN" = "x" ] then - echo "the environment variable NUGET_TOKEN is not defined" - exit 1 -fi - -if [ "x$NUGET_PUSH_URL" = "x" ] -then - echo "the environment variable NUGET_PUSH_URL is not defined" + 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 "cannot figure out the semantic version" + echo "$(basename $0): cannot figure out the semantic version" exit 1 fi # Build to pick up the new version. -dotnet build +echo "$(basename $0): building project $SEMVER" +dotnet build || exit 1 # Create and publish the NuGet packages. -dotnet pack --include-symbols --include-source -dotnet nuget push src/*/bin/Debug/*.nupkg --api-key $NUGET_TOKEN --source $NUGET_PUSH_URL +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 "tagging and pushing" + 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 origin $SEMVER + git push publish $SEMVER || exit 1 + git remote remove publish else - echo "not tagging, already exists" + echo "$(basename $0): not tagging, already exists" fi diff --git a/scripts/setup.sh b/scripts/setup.sh index 8cb2031..3ee77ae 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -14,9 +14,14 @@ do done # Make sure we have lefthook is installed. -lefthook install +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. diff --git a/scripts/update-template.sh b/scripts/update-template.sh new file mode 100755 index 0000000..2d80710 --- /dev/null +++ b/scripts/update-template.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +cd $(dirname $0)/.. +git pull template main --no-rebase