大概做法~


1.將.net core程式專案與xunit測試專案整理到一個資料夾

code

-app (程式專案資料夾)

-test (xunit測試專案)

2.註冊AppVeyor/travis帳號(可透過github帳號SSO登入)

https://www.appveyor.com/
https://travis-ci.org/
 

3.撰寫appveyor.yml/.travis.yml
裡面詳實寫到如何用指令碼compile程式與執行測試的指令碼

 

4.同步code資料夾到github

 

5.登入AppVeyor/travis選擇github專案,即可做CI

會自動抓取appveyor.yml/.travis.yml 執行安裝、佈署與測試

每次push到github ,AppVeyor/travis會自動抓取最新版本重新執行安裝、佈署與測試

 

 

appveyor.yml
version: '1.0.{build}'
image: Visual Studio 2017
services:
 - mongodb
branches:
 only:
 - master
init:
 # Good practise, because Windows line endings are different from Unix/Linux ones
 - cmd: git config --global core.autocrlf true
install:
 # Install repo specific stuff here
before_build:
 # Display .NET Core version
 - cmd: dotnet --version
 # Display minimal restore text
 - cmd: dotnet restore ./app/APISample.csproj --verbosity m
build_script:
 # output will be in ./src/bin/debug/netcoreapp1.1/publish
 - cmd: dotnet publish ./app/APISample.csproj
after_build:
 # For once the build has completed
artifacts:
 - path: '\bin\Debug\netcoreapp2.0\publish'
 name: WebSite
 type: WebDeployPackage
clone_depth: 1
test_script:
 # restore packages for our unit tests
 - cmd: dotnet restore ./test/MyFirstUnitTests.csproj --verbosity m
 - cmd: dotnet build ./test/MyFirstUnitTests.csproj --verbosity m
 - cmd: tree ./test
 # 複製appsettings.json
 - cmd: cp ./app/appsettings_appveyor.json ./test/bin/Debug/netcoreapp2.0/appsettings.json
 # run the unit tests (requires changing into the test directory)
 - cmd: cd test
 - cmd: dotnet test
on_finish :
 # any cleanup in here
deploy: off

 

.travis.yml
language: csharp
mono: none
dotnet: 2.1.3
services:
 - mongodb
 - redis-server
script:
 - dotnet --version
 - mongo --version
 - dotnet restore ./app/APISample.csproj --verbosity m
 - dotnet publish ./app/APISample.csproj
 - dotnet restore ./test/MyFirstUnitTests.csproj --verbosity m
 - dotnet build ./test/MyFirstUnitTests.csproj --verbosity m
 - cp ./app/appsettings_appveyor.json ./test/bin/Debug/netcoreapp2.0/appsettings.json
 - cd test
 - dotnet test

arrow
arrow
    全站熱搜

    45 發表在 痞客邦 留言(0) 人氣()