Atau bagaimana cara mendapatkan lencana yang indah untuk proyek Anda dalam satu malam coding yang santai
Mungkin setiap pengembang yang memiliki setidaknya satu proyek kesayangan, pada titik tertentu ada gatal pada tema lencana indah dengan status, cakupan kode, versi paket di nuget ... Dan gatal ini membuat saya menulis artikel ini. Dalam persiapan untuk menulisnya, saya mendapatkan keindahan di salah satu proyek saya:

Artikel ini akan membahas pengaturan dasar integrasi dan pengiriman berkelanjutan untuk proyek perpustakaan kelas .Net Core di GitLab, dengan publikasi dokumentasi di Halaman GitLab dan mengirimkan paket yang dikumpulkan ke umpan pribadi di Azure DevOps.
VS Code digunakan sebagai lingkungan pengembangan dengan ekstensi GitLab Workflow (untuk memvalidasi file pengaturan langsung dari lingkungan pengembangan).
Pengantar singkat
CD - ini saat Anda baru saja mendorong, dan klien semuanya jatuh?
Apa itu CI / CD dan mengapa perlu dengan mudah google. Dokumentasi lengkap tentang cara mengkonfigurasi saluran pipa di GitLab juga mudah ditemukan . Di sini saya akan menjelaskan secara singkat dan sejauh mungkin tanpa cacat menggambarkan proses sistem dari pandangan mata burung:
- , merge request , - ,
- , ,
- ,
- â .. ,
- (.. ) â ( ),
- , .
, :
- â , , , , , , .,
- (stage) â , 1+ ,
- (job) â . (), , / .
, CI/CD , , , .
: ?, -, GitHub'e , â . , GitHub.
â . git â , SSH- â , .
:
:
:
- merge request,
- merge request ,
- Azure DevOps,
- GitLab Pages,
- !11
:
- 1 â
- 2 â
- 3 â
- 1 â nuget- Azure DevOps
- 2 â xmldoc GitLab Pages
!
Microsoft Azure
Azure DevOps
- â
- â

Create , . , ( -> Overview -> Azure DevOps Services)

Atrifacts, Create feed
- Include packages from common public sources,
nuget

Connect to feed, Visual Studio, Machine Setup Source

, Personal Access Token

- â
- â
- â 1
- (scope) â Packaging/Read & Write

â
GitLab, CI/CD

Variables,
- â ( )
- â . 9
- Mask variable

.
, CI/CD GitLab .gitlab-ci.yml
. , .
, YAML
. , , .
docker-, . .Net Core Docker Hub. GitHub , . .Net Core 3.1,
image: mcr.microsoft.com/dotnet/core/sdk:3.1
Microsoft , .
â stage'. GitLab 5 :
.pre
â ,.post
â ,build
â .pre
,test
â ,deploy
â .
, . , , , . , :
stages:
- build
- test
- deploy
, . , , before_script
:
before_script:
- $PSVersionTable.PSVersion
- dotnet --version
- nuget help | select-string Version
, . :
dummy job:
script:
- echo ok
, , , , , âĻ â bash: .PSVersion: command not found
. WTF?
â runner' ( , GitLab') bash
. , , :
dummy job on windows:
script:
- echo ok
tags:
- windows
! .
, , , test
, . , test
.
, , :
build job:
script:
- echo "building..."
tags:
- windows
stage: build
test and cover job:
script:
- echo "running tests and coverage analysis..."
tags:
- windows
stage: test
pack and deploy job:
script:
- echo "packing and pushing to nuget..."
tags:
- windows
stage: deploy
pages:
script:
- echo "creating docs..."
tags:
- windows
stage: deploy
, .
- , , . , .
: only/except rules. , only/except
(merge_request
, â , ) ( .. ); rules
, , (when
GitLab CI/CD).
â merge request, Azure DevOps â merge request , â .
, merge request:
build job:
# snip
only:
- merge_request
merge request :
pack and deploy job:
# snip
only:
- merge_request
- master
, .
merge request :
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
; rules
only/except
.
build job
, . , , artifacts
:
build job:
# snip
artifacts:
paths:
- path/to/build/artifacts
- another/path
- MyCoolLib.*/bin/Release/*
wildcards, .
, â , . .
, ( ) , .
, - , - , ( .net) . , 3 :
dotnet build
dotnet test
dotnet pack
, , - .
- , ,
-c Release
- , :
coverlet.msbuild
: dotnet add package coverlet.msbuild
/p:CollectCoverage=true
- (. )
- nuget- :
-o .
Coverlet :
Calculating coverage result...
Generating report 'C:\Users\xxx\source\repos\my-project\myProject.tests\coverage.json'
+-------------+--------+--------+--------+
| Module | Line | Branch | Method |
+-------------+--------+--------+--------+
| project 1 | 83,24% | 66,66% | 92,1% |
+-------------+--------+--------+--------+
| project 2 | 87,5% | 50% | 100% |
+-------------+--------+--------+--------+
| project 3 | 100% | 83,33% | 100% |
+-------------+--------+--------+--------+
+---------+--------+--------+--------+
| | Line | Branch | Method |
+---------+--------+--------+--------+
| Total | 84,27% | 65,76% | 92,94% |
+---------+--------+--------+--------+
| Average | 90,24% | 66,66% | 97,36% |
+---------+--------+--------+--------+
GitLab , . coverage
; capture-, :
test and cover job:
# snip
coverage: /\|\s*Total\s*\|\s*(\d+[,.]\d+%)/
.
â , .
:
nuget (nuget.config
), : dotnet new nugetconfig
: ( ) . , .
- :
nuget sources add -name <name> -source <url> -username <organization> -password <gitlab variable> -configfile nuget.config -StorePasswordInClearText
name
â ,url
â URL " ", . 6organization
â Azure DevOpsgitlab variable
â , GitLab (" ", . 11). , $variableName
-StorePasswordInClearText
â ( )-verbosity detailed
- :
nuget push -source <name> -skipduplicate -apikey <key> *.nupkg
- ,
*.nupkg
. name
â .key
â . Azure DevOps Connect to feed az
.-skipduplicate
â 409 Conflict
; .
:
- , , master, docfx.
docfx init
. .
..\public
â GitLab public Pages. .. â .
- GitLab.
pages
( GitLab Pages):
- :
nuget install docfx.console -version 2.51.0
â docfx; ..\docfx.console.2.51.0\tools\docfx.exe .\docfx_project\docfx.json
â
- artifacts:
pages:
# snip
artifacts:
paths:
- public
docfx
. â . , , metadata.src
:
{
"metadata": [
{
"src": [
{
"src": "../",
"files": [
"**/*.csproj"
],
"exclude":[
"*.tests*/**"
]
}
],
},
],
}
metadata.src.src: "../"
â docfx.json
, .. .metadata.src.files: ["**/*.csproj"]
â , C# .metadata.src.exclude: ["*.tests*/**"]
â , .tests
, , , , README .
.gitlab-ci.ymlimage: mcr.microsoft.com/dotnet/core/sdk:3.1
before_script:
- $PSVersionTable.PSVersion
- dotnet --version
- nuget help | select-string Version
stages:
- build
- test
- deploy
build job:
stage: build
script:
- dotnet build -c Release
tags:
- windows
only:
- merge_requests
- master
artifacts:
paths:
- your/path/to/binaries
test and cover job:
stage: test
tags:
- windows
script:
- dotnet test -c Release /p:CollectCoverage=true
coverage: /\|\s*Total\s*\|\s*(\d+[,.]\d+%)/
only:
- merge_requests
- master
pack and deploy job:
stage: deploy
tags:
- windows
script:
- dotnet pack -c Release -o .
- dotnet new nugetconfig
- nuget sources add -name feedName -source https://pkgs.dev.azure.com/your-organization/_packaging/your-feed/nuget/v3/index.json -username your-organization -password $nugetFeedToken -configfile nuget.config -StorePasswordInClearText
- nuget push -source feedName -skipduplicate -apikey az *.nupkg
only:
- master
pages:
tags:
- windows
stage: deploy
script:
- nuget install docfx.console -version 2.51.0
- $env:path = "$env:path;$($(get-location).Path)"
- .\docfx.console.2.51.0\tools\docfx.exe .\docfx\docfx.json
artifacts:
paths:
- public
only:
- master
!
GitLab CI/CD Gtntral pipelines:

Shields.io â , .


Azure DevOps Artifacts . Azure DevOps Create badge markdown-:


, YAML â .
, windows
, / ( ). , :
.common_tags: &common_tags
tags:
- windows
.common_only: &common_only
only:
- merge_requests
- master
:
build job:
<<: *common_tags
<<: *common_only
, .
, â ; Version, . , , , .
â , . , â , .
, release (v./ver./version) <version number> (rev./revision <revision>)?
, , dotnet pack
. â .
:
$rx = "release\s+(v\.?|ver\.?|version)\s*(?<maj>\d+)(?<min>\.\d+)?(?<rel>\.\d+)?\s*((rev\.?|revision)?\s+(?<rev>[a-zA-Z0-9-_]+))?"
$found = $env:CI_COMMIT_MESSAGE -match $rx
if (!$found) { Write-Output "no release info found, aborting"; exit }
$maj = $matches['maj']
$min = $matches['min']
if ($matches.ContainsKey('rel')) { $rel = $matches['rel'] } else { $rel = ".$(get-date -format "yyyy")" }
$bld = $(get-date -format "MMdd")
if ($matches.ContainsKey('rev')) { $rev = "-$($matches['rev'])" } else { $rev = '' }
$version = "$maj$min$rel.$bld$rev"
dotnet pack -c Release -o . /p:Version=$version
pack and deploy job
.
- , powershell , , , .
Tentu saja, GitLab CI / CD jauh lebih luas dan beragam daripada yang terlihat setelah membaca panduan ini - ini sama sekali tidak begitu . Bahkan ada Auto DevOps di sana , memungkinkan
secara otomatis mendeteksi, membuat, menguji, menyebarkan, dan memonitor aplikasi Anda
Sekarang ada rencana untuk mengonfigurasi pipeline untuk menggunakan aplikasi di Azure, menggunakan Pulumi dan secara otomatis mendeteksi lingkungan target, yang akan dibahas dalam artikel berikutnya.