build: working on build and ci

This commit is contained in:
Dylan R. E. Moonfire 2021-09-03 21:33:54 -05:00
parent 619d583446
commit 677b12f57c
7 changed files with 56 additions and 5202 deletions

View file

@ -1,23 +1,21 @@
stages: stages:
- test - build
- tag
- deploy
default: default:
before_script: before_script:
- curl -sL https://deb.nodesource.com/setup_15.x | bash - - curl -sL https://deb.nodesource.com/setup_15.x | bash -
- apt-get install -y nodejs - apt-get install -y nodejs
# The test stage runs on every build and every branch. build:
test:
image: mcr.microsoft.com/dotnet/sdk:5.0 image: mcr.microsoft.com/dotnet/sdk:5.0
stage: test stage: build
script: script:
# Make sure the commits follow our rules. # Set up the environment.
- npx yarn install --frozen-lockfile - npx npm install --ci
- if [ $CI_BUILD_BEFORE_SHA == "0000000000000000000000000000000000000000" ]; then npx commitlint --to=HEAD; else npx commitlint --from=$CI_BUILD_BEFORE_SHA; fi - npx commitlint-gitlab-ci -x @commitlint/config-conventional
- npx semantic-release --publish
# Build and test the project. # Build and test everything.
- dotnet restore - dotnet restore
- dotnet build - dotnet build
- 'dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"' - 'dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"'
@ -27,34 +25,16 @@ test:
- dotnet tool install dotnet-reportgenerator-globaltool - dotnet tool install dotnet-reportgenerator-globaltool
- dotnet tool run reportgenerator -reports:src/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary" - dotnet tool run reportgenerator -reports:src/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
- grep "Line coverage" coverage/Summary.txt - grep "Line coverage" coverage/Summary.txt
rules:
- if: '$CI_COMMIT_TITLE =~ /^(docs|chore\(release\))/'
when: never
- if: '$CI_COMMIT_TAG'
when: never
- when: on_success
artifacts:
when: always
paths:
- ./**/*test-result.xml
- ./coverage/Cobertura.xml
- ./coverage/Summary.*
reports:
junit:
- ./**/*test-result.xml
cobertura:
- ./coverage/Cobertura.xml
# Tagging only runs on the master branches and after testing. # Perform the release.
tag:
image: mcr.microsoft.com/dotnet/sdk:5.0
stage: tag
needs: [test]
script:
- npx yarn install --frozen-lockfile
- npx semantic-release - npx semantic-release
# Create the NuGet packages.
- dotnet pack -c Release
- dotnet nuget push "bin/*.nupkg" --api-key $NUGET_TOKEN --source "$NUGET_PUSH_URL"
rules: rules:
- if: '$CI_COMMIT_TITLE =~ /^(docs|chore\(release\))/' - if: '$CI_COMMIT_TITLE =~ /^chore\(release\)/'
when: never when: never
- if: '$CI_COMMIT_TAG' - if: '$CI_COMMIT_TAG'
when: never when: never
@ -62,20 +42,15 @@ tag:
when: never when: never
- when: on_success - when: on_success
# Publish the packages. artifacts:
deploy: when: always
image: mcr.microsoft.com/dotnet/sdk:5.0 paths:
needs: [] - ./**/*test-result.xml
stage: deploy - ./coverage/Cobertura.xml
before_script: [] - ./coverage/Summary.*
script: - ./**/*.nupkg
- scripts/set-build-version.sh reports:
- dotnet restore junit:
- dotnet build - ./**/*test-result.xml
- dotnet pack -c Release cobertura:
- dotnet nuget push "bin/*.nupkg" --api-key $NUGET_TOKEN --source "$NUGET_PUSH_URL" - ./coverage/Cobertura.xml
rules:
- if: '$FORCE_DEPLOY'
- if: '$CI_COMMIT_TITLE =~ /^chore\(release\)/ && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never

4
.husky/commit-msg Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit $1

3
commitlint.config.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};

View file

@ -3,42 +3,18 @@
"version": "1.1.1", "version": "1.1.1",
"private": true, "private": true,
"scripts": { "scripts": {
"commitlint": "commitlint " "prepare": "husky install"
},
"release": {
"branch": "master",
"message": "chore(release): v${nextRelease.version}\n\n${nextRelease.notes}",
"verifyConditions": [
"@semantic-release/git"
],
"analyzeCommits": [
"@semantic-release/commit-analyzer"
],
"prepare": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"publish": [],
"success": [],
"fail": []
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^11.0.0", "@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^11.0.0", "@commitlint/config-conventional": "^13.1.0",
"@semantic-release/changelog": "^5.0.1", "@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0", "@semantic-release/git": "^9.0.0",
"husky": "^4.3.6", "@semantic-release/gitlab": "^6.2.2",
"semantic-release": "^17.3.0" "@semantic-release/npm": "^7.1.3",
"commitlint-gitlab-ci": "^0.0.4",
"husky": "^7.0.2",
"semantic-release": "^17.4.7",
"semantic-release-dotnet": "^1.0.0"
} }
} }

13
release.config.js Normal file
View file

@ -0,0 +1,13 @@
module.exports = {
branches: ["main"],
message: "chore(release): v${nextRelease.version}\n\n${nextRelease.notes}",
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"semantic-release-dotnet",
"@semantic-release/changelog",
"@semantic-release/git",
"@semantic-release/gitlab",
],
};

View file

@ -1,21 +0,0 @@
#!/bin/bash
# This sets the build version using a `Directory.Build.props` at the top-level
# of the project.
# Move into the root directory.
cd $(dirname $0)
cd ..
# Get the version from `package.json`.
VERSION=$(grep '"version":' package.json | cut -f 4 -d '"')
cat > src/Directory.Build.props << EOL
<Project>
<PropertyGroup>
<Version>$VERSION</Version>
</PropertyGroup>
</Project>
EOL

5096
yarn.lock

File diff suppressed because it is too large Load diff