Skip to content

Commit

Permalink
Updated CI to Azure Pipelines (#70)
Browse files Browse the repository at this point in the history
* Updated CI

* test 1

* Install xml-lint instead of pulling in a docker image

* PrependPath

* Install tool in --tool-path

* Build -- e2e is run at a different stage, so no build-bin is available

* run-samples.sh no test-output
  • Loading branch information
gfoidl authored Jun 9, 2020
1 parent c99d0ce commit 2c9b023
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 257 deletions.
47 changes: 47 additions & 0 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variables:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
CI_BUILD_NUMBER: $(Build.BuildId)
BRANCH_NAME: $(Build.SourceBranchName)
TAG_NAME: $(Build.SourceBranchName)

trigger:
- master
- ci-*
- refs/tags/v*

pr:
branches:
include:
- master

#schedules:
# - cron: "0 0 * * *"
# displayName: "Daily midnight build"
# branches:
# include:
# - master

stages:
- stage: Build_Test
jobs:
- template: jobs/build_and_test.yml

- stage: E2E_Tests
dependsOn:
- Build_Test
jobs:
- template: jobs/e2e_tests.yml

- stage: Code_Coverage
dependsOn:
- Build_Test
jobs:
- template: jobs/coverage.yml

- stage: Deploy
dependsOn:
- E2E_Tests
condition: and( succeeded(), startsWith( variables['Build.SourceBranch'], 'refs/tags' ) )
jobs:
- template: jobs/deploy_nuget.yml
70 changes: 70 additions & 0 deletions .azure/pipelines/jobs/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
jobs:
- job: build_test
displayName: build and test
pool:
vmImage: 'ubuntu-18.04'
strategy:
matrix:
debug-build:
BUILD_CONFIG: Debug
release-build:
BUILD_CONFIG: Release
steps:
- bash: |
echo 'installed sdks:'
dotnet --list-sdks
echo "-------------------------------------------------"
echo 'environment variables:'
env | sort
chmod u+x ./build.sh
displayName: init
- bash: ./build.sh build
displayName: build

# coverlet.msbuild must be added as package to the tests
- bash: ./build.sh test-coverage
displayName: test

- task: PublishTestResults@2
condition: always()
inputs:
testRunner: VSTest
# no global glob, because of trx-test-files used in the project
testResultsFiles: 'tests/trx2junit.Tests/TestResults/*.trx'

- bash: |
cd tests/Coverage
workDir="$(System.DefaultWorkingDirectory)"
if [[ "$AGENT_OS" == "Windows_NT" ]]; then
# Windows needs special treetment for the substitution due the \
workDir="${workDir//\\/\\\\}\\\\"
else
workDir+="/"
fi
# Mac has a different sed, so special case it (hooray for standars ;-))
if [[ "$AGENT_OS" != "Darwin" ]]; then
sed -i 's|<source>[^<]*</source>|<source>/</source>|g' "Cobertura.xml"
sed -i "s|${workDir}||g" "Cobertura.xml"
else
sed -i '' 's|<source>[^<]+</source>|<source>/</source>|g' "Cobertura.xml"
sed -i '' "s|${workDir}||g" "Cobertura.xml"
fi
displayName: make Cobertura-paths relative
# shortcut for PublishPipelineArtifact
# Coverage report will be created later in a different stage
- publish: tests/Coverage/Cobertura.xml
artifact: 'Coverage-${{ parameters.name }}-$(BUILD_CONFIG)'

- bash: ./build.sh pack
displayName: pack
condition: and(succeeded(), eq(variables['BUILD_CONFIG'], 'Release'))

- publish: 'NuGet-Packed'
artifact: 'NuGet-Packed'
condition: and(succeeded(), eq(variables['BUILD_CONFIG'], 'Release'))
28 changes: 28 additions & 0 deletions .azure/pipelines/jobs/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
jobs:
- job: coverage_report_quality
pool:
vmImage: 'ubuntu-18.04'
steps:
# checkout is needed for file-references
#- checkout: none

- task: DownloadPipelineArtifact@2
inputs:
targetPath: './coverage'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: 'coverage/**/Cobertura.xml'
pathToSources: $(System.DefaultWorkingDirectory)

# extension from Marketplace https://marketplace.visualstudio.com/acquisition?itemName=mspremier.BuildQualityChecks
- task: BuildQualityChecks@6
displayName: 'Check build quality'
inputs:
checkCoverage: true
coverageFailOption: 'build'
coverageType: 'lines'
allowCoverageVariance: true
coverageVariance: '0.5'
baseBranchRef: 'master'
66 changes: 66 additions & 0 deletions .azure/pipelines/jobs/deploy_nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
jobs:
- job: deploy_nuget
pool:
vmImage: 'ubuntu-18.04'
steps:
- checkout: none

- task: DownloadPipelineArtifact@2
inputs:
artifactName: 'NuGet-Packed'
targetPath: './'

- bash: |
echo "NuGet-Packed:"
ls -la .
if [[ "$TAG_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(-(preview-[0-9]+))$ ]]; then
mkdir deploy_custom
for package in ./*.nupkg; do
mv $package deploy_custom
done
echo "##vso[task.setvariable variable=deploy_custom;]1"
elif [[ "$TAG_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
mkdir deploy_nuget
for package in ./*.nupkg; do
mv $package deploy_nuget
done
echo "##vso[task.setvariable variable=deploy_nuget;]1"
else
echo "no deploy, as $TAG_NAME does not match"
echo ##vso[task.complete result=Skipped;]tag does not match for deploy
fi
echo "-------------------------------------------------"
echo "custom:"
ls -la deploy_custom
echo "-------------------------------------------------"
echo "nuget:"
ls -la deploy_nuget
echo "-------------------------------------------------"
displayName: 'deploy to nuget / custom'
- task: NuGetAuthenticate@0
condition: eq(variables['deploy_custom'], '1')

- task: NuGetCommand@2
condition: eq(variables['deploy_custom'], '1')
inputs:
command: push
packagesToPush: deploy_custom/*.nupkg
nuGetFeedType: 'internal'
publishVstsFeed: 'github-Projects/gfoidl-public'
displayName: deploy to custom feed

- task: NuGetCommand@2
condition: eq(variables['deploy_nuget'], '1')
inputs:
command: push
packagesToPush: deploy_nuget/*.nupkg
nuGetFeedType: external
publishFeedCredentials: 'nuget - gfoidl'
displayName: deploy to nuget
82 changes: 82 additions & 0 deletions .azure/pipelines/jobs/e2e_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
jobs:
- job: e2e_tests
displayName: e2e tests
pool:
vmImage: 'ubuntu-18.04'
steps:
- bash: |
sudo apt update
sudo apt install -y libxml2-utils
displayName: install xml-lint
- task: DownloadPipelineArtifact@2
inputs:
artifactName: 'NuGet-Packed'
targetPath: './NuGet-Packed'

- bash: |
chmod ugo+x -R *.sh
chmod ugo+x ./tests/scripts/*.sh
displayName: init
- bash: |
# copied from build.sh (but modified)
if [[ -n "$TAG_NAME" ]]; then
if [[ "$TAG_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)(-(preview-[0-9]+))?$ ]]; then
export VersionMajor="${BASH_REMATCH[1]}"
export VersionMinor="${BASH_REMATCH[2]}"
export VersionPatch="${BASH_REMATCH[3]}"
export VersionSuffix="${BASH_REMATCH[5]}"
ToolVersion="$VersionMajor.$VersionMinor.$VersionPatch-$VersionSuffix"
fi
fi
# special handling for pre-releases (is a constraint by .NET Core global tools)
# and also to prevent installation from NuGet-feed (which may have higher version than the
# built tool)
if [[ -z "$ToolVersion" ]]; then
dotnet tool install --tool-path $(pwd)/tool --configfile=ci-nuget.config trx2junit
else
dotnet tool install --tool-path $(pwd)/tool --version="$ToolVersion" --configfile=ci-nuget.config trx2junit
fi
echo "##vso[task.prependpath]$(pwd)/tool"
displayName: install built trx2junit-tool
- bash: |
echo $PATH
echo "-------------------------------------------------"
dotnet tool list --tool-path $(pwd)/tool
echo "-------------------------------------------------"
trx2junit
if [[ $? != 1 ]]; then
echo "hm, something strange"
exit 1
fi
displayName: check tool installation
- bash: ./build.sh build
displayName: build

- bash: ./tests/scripts/run-samples.sh
displayName: samples

- bash: ./tests/scripts/run-single-arg.sh
displayName: single-arg

- bash: ./tests/scripts/run-multiple-args.sh
displayName: multiple-args

- bash: ./tests/scripts/run-globbing.sh
displayName: globbing

- bash: ./tests/scripts/run-no-globbing.sh
displayName: no-globbing

- bash: ./tests/scripts/run-different-output-location.sh
displayName: different-output-location

- bash: ./tests/scripts/run-junit2trx.sh
displayName: junit2trx
Loading

0 comments on commit 2c9b023

Please sign in to comment.