From 8a2d4c7745032d059ab586616e71a2ac1dfaf140 Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Tue, 7 Dec 2021 17:09:00 -0600 Subject: [PATCH] build: switching to Nix-based setup --- .envrc | 2 +- .gitignore | 5 +++++ .gitlab-ci.yml | 51 -------------------------------------------- .gitlab/build.sh | 3 +++ .gitlab/ci.yml | 41 +++++++++++++++++++++++++++++++++++ .gitlab/release.sh | 3 +++ .gitlab/test.sh | 5 +++++ .tool-versions | 3 --- commitlint.config.js | 3 +++ flake.lock | 42 ++++++++++++++++++++++++++++++++++++ flake.nix | 17 +++++++++++++++ package.json | 18 +++++++++------- release.config.js | 12 ++++++++--- 13 files changed, 139 insertions(+), 66 deletions(-) delete mode 100644 .gitlab-ci.yml create mode 100755 .gitlab/build.sh create mode 100644 .gitlab/ci.yml create mode 100755 .gitlab/release.sh create mode 100755 .gitlab/test.sh delete mode 100644 .tool-versions create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index a63eb96..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use asdf +use flake diff --git a/.gitignore b/.gitignore index 50364fe..d7e7938 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ obj/ .idea/ _ReSharper.Caches/ node_modules/ +.direnv/ +coverage/ +tests/artifacts/ +TestResults/ +.config/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 1d4e850..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,51 +0,0 @@ -stages: - - build - -default: - before_script: - - curl -sL https://deb.nodesource.com/setup_15.x | bash - - - apt-get install -y nodejs - -build: - image: mcr.microsoft.com/dotnet/sdk:5.0 - stage: build - script: - # Set up the environment. - - npx npm install --ci - - npx commitlint-gitlab-ci -x @commitlint/config-conventional - - # Build and test everything. - - dotnet restore - - dotnet build - #- 'dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"' - - # Summarize the output for Gitlab CI reporting. - #- dotnet new tool-manifest - #- dotnet tool install dotnet-reportgenerator-globaltool - #- dotnet tool run reportgenerator -reports:src/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary" - #- grep "Line coverage" coverage/Summary.txt - - # Perform the release. - - npx semantic-release - - rules: - - if: '$CI_COMMIT_TITLE =~ /^chore\(release\)/' - when: never - - if: '$CI_COMMIT_TAG' - when: never - - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH' - when: never - - when: on_success - - artifacts: - when: always - paths: - - ./**/*test-result.xml - - ./coverage/Cobertura.xml - - ./coverage/Summary.* - - ./**/*.nupkg - reports: - junit: - - ./**/*test-result.xml - cobertura: - - ./coverage/Cobertura.xml diff --git a/.gitlab/build.sh b/.gitlab/build.sh new file mode 100755 index 0000000..10561a4 --- /dev/null +++ b/.gitlab/build.sh @@ -0,0 +1,3 @@ +npm install --ci +npx commitlint-gitlab-ci -x @commitlint/config-conventional +npm run build diff --git a/.gitlab/ci.yml b/.gitlab/ci.yml new file mode 100644 index 0000000..5effae5 --- /dev/null +++ b/.gitlab/ci.yml @@ -0,0 +1,41 @@ +include: + - template: Security/SAST.gitlab-ci.yml + +stages: + - build + - test + - release + +default: + image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest + +build: + stage: build + script: + - nix develop --command .gitlab/build.sh + rules: + - if: $CI_COMMIT_BRANCH + +test: + stage: test + script: + - nix develop --command .gitlab/test.sh + artifacts: + when: always + paths: + - ./**/*test-result.xml + - ./coverage/Cobertura.xml + - ./coverage/Summary.* + - ./**/*.nupkg + reports: + junit: + - ./**/*test-result.xml + cobertura: + - ./coverage/Cobertura.xml + +publish: + stage: release + script: + - nix develop --command .gitlab/release.sh + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH diff --git a/.gitlab/release.sh b/.gitlab/release.sh new file mode 100755 index 0000000..90f5c48 --- /dev/null +++ b/.gitlab/release.sh @@ -0,0 +1,3 @@ +npm install --ci +npm run build +npx semantic-release diff --git a/.gitlab/test.sh b/.gitlab/test.sh new file mode 100755 index 0000000..6f7b13e --- /dev/null +++ b/.gitlab/test.sh @@ -0,0 +1,5 @@ +#dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage" +#dotnet new tool-manifest +#dotnet tool install dotnet-reportgenerator-globaltool +#dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary" +#grep "Line coverage" coverage/Summary.txt diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index f84212e..0000000 --- a/.tool-versions +++ /dev/null @@ -1,3 +0,0 @@ -dotnet-core 5.0.100 -yarn 1.22.10 -nodejs 15.0.1 diff --git a/commitlint.config.js b/commitlint.config.js index db74d15..29519fc 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,6 @@ module.exports = { extends: ["@commitlint/config-conventional"], + rules: { + "body-max-line-length": [0], + }, }; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4c57fd5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1638806821, + "narHash": "sha256-v2qd2Bsmzft53s43eCbN+4ocrLksRdFLyF/MAGuWuDA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bc5d68306b40b8522ffb69ba6cff91898c2fbbff", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d6a1166 --- /dev/null +++ b/flake.nix @@ -0,0 +1,17 @@ +{ + description = "A .NET core library for building tools"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + devShell = pkgs.mkShell { + buildInputs = [ pkgs.dotnet-sdk_5 pkgs.nodejs-16_x pkgs.nixfmt ]; + }; + }); +} diff --git a/package.json b/package.json index 4067205..9ef7032 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,20 @@ "version": "1.0.4", "private": true, "scripts": { - "prepare": "husky install" + "prepare": "husky install", + "build": "dotnet build", + "test": "dotnet test" }, "devDependencies": { - "@commitlint/cli": "^13.1.0", - "@commitlint/config-conventional": "^13.1.0", - "@semantic-release/changelog": "^5.0.1", - "@semantic-release/git": "^9.0.0", - "@semantic-release/gitlab": "^6.2.2", - "@semantic-release/npm": "^7.1.3", + "@commitlint/cli": "^15.0.0", + "@commitlint/config-conventional": "^15.0.0", + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/git": "^10.0.1", + "@semantic-release/gitlab": "^7.0.4", + "@semantic-release/npm": "^8.0.3", "commitlint-gitlab-ci": "^0.0.4", "husky": "^7.0.2", - "semantic-release": "^17.4.7", + "semantic-release": "^18.0.1", "semantic-release-dotnet": "^1.0.0", "semantic-release-nuget": "^1.1.1" } diff --git a/release.config.js b/release.config.js index 9184c5d..b217e78 100644 --- a/release.config.js +++ b/release.config.js @@ -1,14 +1,20 @@ module.exports = { + extends: ["@commitlint/config-conventional"], branches: ["main"], - message: "chore(release): v${nextRelease.version}\n\n${nextRelease.notes}", + message: "chore(release): v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}", plugins: [ - "@semantic-release/commit-analyzer", + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + }, + ], "@semantic-release/release-notes-generator", "@semantic-release/npm", [ "semantic-release-dotnet", { - paths: ["src/Directory.Build.props"], + paths: ["src/Directory.Build.props"], }, ], [