Stages:
- Build
- Tests
- Compliance
- Package
This commit is contained in:
Mauro Agnoletti 2021-02-22 20:21:53 -03:00
Родитель 5ff57b761c
Коммит 6e1caacba8
14 изменённых файлов: 400 добавлений и 104 удалений

10
NuGet.Config Normal file
Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value=".nuget\packages" />
</config>
<packageSources>
<clear />
<add key="xvs" value="https://devdiv.pkgs.visualstudio.com/_packaging/xamarin-xvs/nuget/v3/index.json" />
</packageSources>
</configuration>

Просмотреть файл

@ -1,90 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
The MIT License (MIT)
Copyright (c) 2015 Daniel Cazzulino
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<Project Sdk="CoreBuild/1.0.0-alpha" DefaultTargets="Rebuild" TreatAsLocalProperty="Configuration">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(MSBuildProjectDirectory)\out</PackageOutputPath>
<!-- Whether to verify and initialize the target nuget feed before pushing as necessary. -->
<SleetInit>false</SleetInit>
<CommonBuildProperties>Configuration=$(Configuration);PackageOutputPath=$(PackageOutputPath);GitSkipCache=true</CommonBuildProperties>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sleet.Azure" Version="0.2.5" />
<PackageReference Include="xunit.runner.msbuild" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<Solution Include="src\Hermes.sln" />
<TestProject Include="src\Tests\Tests.csproj" />
<TestProject Include="src\IntegrationTests\IntegrationTests.csproj" />
</ItemGroup>
<Target Name="Rebuild" DependsOnTargets="Clean;Restore;Build" />
<Target Name="All" DependsOnTargets="Rebuild;Test" />
<!-- Clean solutions -->
<Target Name="Clean">
<Exec Command="rmdir $(PackageOutputPath) /S /Q" Condition="Exists('$(PackageOutputPath)')" />
<!-- Remove all bin/obj recursively under /src -->
<Exec Command='for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"'
WorkingDirectory='$(MSBuildThisFileDirectory)\src' />
<Exec Command="rmdir src\.vs /S /Q" Condition="Exists('src\.vs')" />
</Target>
<Target Name="Delete" DependsOnTargets="_SleetConfigCreate">
<Error Condition="'$(PackageId)' == ''" Text="No PackageId was specified for the Delete operation." />
<Exec Condition="'$(PackageVersion)' == ''" Command='"$(Sleet)" delete --id "$(PackageId)" -f -s feed -c $(_SleetConfig)' />
<Exec Condition="'$(PackageVersion)' != ''" Command='"$(Sleet)" delete --id "$(PackageId)" --version $(PackageVersion) -f -s feed -c $(_SleetConfig)' />
</Target>
<Target Name="_BeforeRestore" BeforeTargets="Restore" DependsOnTargets="Clean">
<MakeDir Directories="$(TEMP)\packages" Condition="!Exists('$(TEMP)\packages')" />
</Target>
<Target Name="_RestoreSolutions" AfterTargets="Restore">
<MSBuild Projects="@(Solution)" Targets="Restore" />
</Target>
<Target Name="_AddPackage" BeforeTargets="Push">
<ItemGroup>
<Package Include="$(PackageOutputPath)\*.nupkg" />
</ItemGroup>
</Target>
<Target Name="Build">
<MSBuild Projects="@(Solution)" Properties="$(CommonBuildProperties)" />
</Target>
<Target Name="Test">
<MSBuild Projects="@(TestProject)" Properties="$(CommonBuildProperties)">
<Output ItemName="TestAssembly" TaskParameter="TargetOutputs" />
</MSBuild>
<xunit Assemblies="@(TestAssembly)" />
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,9 @@
{
"tool": "Credential Scanner",
"suppressions": [
{
"file": "src\\IntegrationTests\\AuthenticationSpec.cs",
"_justification": "Dummy credentials for testing purposes"
}
]
}

Просмотреть файл

@ -0,0 +1,3 @@
<!-- Upper case must be used. All values will be compared only to the upper case strings -->
<PoliCheckExclusions>
</PoliCheckExclusions>

124
build/stages/build.yml Normal file
Просмотреть файл

@ -0,0 +1,124 @@
# Build Stage
stages:
- stage: Build
jobs:
- job: Windows
timeoutInMinutes: 10
pool:
name: $(WindowsPoolName)
steps:
- checkout: self
clean: true
- task: UseDotNet@2
displayName: 'Use .Net Core SDK $(DotNetCoreVersion)'
inputs:
version: '$(DotNetCoreVersion)'
condition: always()
- script: 'mkdir "$(Build.ArtifactStagingDirectory)\binlogs"'
displayName: 'Create Logs Dir'
condition: always()
# Ensure we clear bot-provided feeds, for reliability
- powershell: |
$configPath = "$(Build.SourcesDirectory)\NuGet.Config"
[xml]$config = get-content $configPath
$config.configuration.packageSources.PrependChild($config.CreateElement("clear"))
$config.Save($configPath)
displayName: 'Ensure Clean NuGet Sources'
condition: always()
- task: NuGetCommand@2
displayName: 'Restore Packages'
inputs:
restoreSolution: '$(Build.SourcesDirectory)/src/Hermes.sln'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.Config'
condition: always()
- task: MSBuild@1
displayName: 'Build Solution'
inputs:
solution: '$(Build.SourcesDirectory)/src/Hermes.sln'
msbuildArguments: /t:Build /noautoresponse /bl:"$(Build.ArtifactStagingDirectory)\binlogs\build.binlog"
condition: always()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: packages'
inputs:
PathtoPublish: '$(Build.SourcesDirectory)\pack'
ArtifactName: packages
continueOnError: true
condition: always()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: unit-tests'
inputs:
PathtoPublish: '$(Build.SourcesDirectory)\src\Tests\bin\$(Configuration)'
ArtifactName: unit-tests
continueOnError: true
condition: always()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: integration-tests'
inputs:
PathtoPublish: '$(Build.SourcesDirectory)\src\IntegrationTests\bin\$(Configuration)'
ArtifactName: integration-tests
continueOnError: true
condition: always()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: logs'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)\binlogs'
ArtifactName: logs
continueOnError: true
condition: always()
- task: CopyFiles@2
displayName: 'Copy Symbols'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/src/Server/bin/$(Configuration)'
Contents: |
**/System.Net.Mqtt.?(dll|pdb)
**/System.Net.Mqtt.Server.?(dll|pdb)
TargetFolder: '$(Build.ArtifactStagingDirectory)/Symbols'
CleanTargetFolder: true
FlattenFolders: true
OverWrite: true # Check if we should copy to $(TargetFramework) subfolders instead
condition: always()
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: symbols'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/Symbols'
ArtifactName: symbols
condition: always()
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
displayName: 'Component Governance'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], variables['MainBranch']))
- powershell: |
$complianceEnabled = if ($env:COMPLIANCEENABLED) { $env:COMPLIANCEENABLED } else { '' }
if ($complianceEnabled -eq '') {
$branch = '$(Build.SourceBranch)'
$reason = '$(Build.Reason)'
if($branch -eq '$(MainBranch)' -or $reason -eq 'PullRequest') {
$complianceEnabled = 'true'
} else {
$complianceEnabled = 'false'
}
}
Write-Host "Source Branch: $branch, Build Reason: $reason"
Write-Host "Requires Compliance Stage: $complianceEnabled"
Write-Host "##vso[task.setvariable variable=Xamarin.ComplianceEnabled;isOutput=true]$complianceEnabled"
name: 'SetComplianceNeed'
displayName: 'Evaluate Compliance Need'
condition: always()

101
build/stages/compliance.yml Normal file
Просмотреть файл

@ -0,0 +1,101 @@
# Compliance Stage
stages:
- stage : Compliance
dependsOn: Build
condition: eq(stageDependencies.Build.outputs['Windows.SetComplianceNeed.Xamarin.ComplianceEnabled'], 'true')
jobs:
- job: CodeAnalysis
displayName: Security & Analysis
pool: $(WindowsPoolName)
timeoutInMinutes: 60
cancelTimeoutInMinutes: 5
steps:
- checkout: self
clean: true
submodules: recursive
- task: DownloadBuildArtifacts@0
displayName: Download Symbols
inputs:
artifactName: symbols
downloadPath: '$(Build.ArtifactStagingDirectory)'
- task: AntiMalware@3
displayName: Run AntiMalware Scan
inputs:
FileDirPath: $(System.DefaultWorkingDirectory)
EnableServices: true
continueOnError: true
condition: succeededOrFailed()
- task: BinSkim@3
displayName: Run BinSkim Analysis
inputs:
InputType: Basic
AnalyzeTarget: '$(Build.ArtifactStagingDirectory)\Symbols\*.dll'
AnalyzeVerbose: true
continueOnError: true
condition: succeededOrFailed()
- template: security\credscan\v2.yml@templates # from xamarin/yaml-templates repository
parameters:
suppressionsFile: $(System.DefaultWorkingDirectory)\build\CredScanSuppressions.json
- template: security\policheck\v1.yml@templates # from xamarin/yaml-templates repository
parameters:
exclusionFile: $(System.DefaultWorkingDirectory)\build\PoliCheckExclusions.xml
- task: CodeInspector@2
displayName: Run Code Inspector Analysis
inputs:
ProductId: '$(System.TeamProjectId)'
continueOnError: true
condition: succeededOrFailed()
- task: SdtReport@1
displayName: Create Security Analysis Report
inputs:
AntiMalware: true
BinSkim: true
CredScan: true
RoslynAnalyzers: true
PoliCheck: true
CodeInspector: true
continueOnError: true
condition: succeededOrFailed()
- task: PublishSecurityAnalysisLogs@2
displayName: Publish Security Analysis Logs
inputs:
ArtifactName: ComplianceLogs
continueOnError: true
condition: succeededOrFailed()
- task: PostAnalysis@1
displayName: Run Security Post Analysis
inputs:
AntiMalware: true
BinSkim: true
CredScan: true
RoslynAnalyzers: true
PoliCheck: true
CodeInspector: true
continueOnError: true
condition: succeededOrFailed()
- task: TSAUpload@1
inputs:
tsaVersion: 'TsaV2'
codebase: 'NewOrUpdate'
tsaEnvironment: 'PROD'
codeBaseName: 'mqtt_main'
notificationAlias: 'xvs@microsoft.com,maagno@microsoft.com'
notifyAlwaysV2: false
codeBaseAdmins: 'REDMOND\maagno;REDMOND\vsengxamarin'
instanceUrlForTsaV2: 'DEVDIV'
projectNameDEVDIV: 'DevDiv'
areaPath: 'DevDiv\Xamarin Tools\XamarinVS\XMA'
iterationPath: 'DevDiv\OneVS'
uploadAPIScan: true
uploadBinSkim: true
uploadCredScan: true
uploadFortifySCA: true
uploadFxCop: true
uploadModernCop: true
uploadPoliCheck: true
uploadPREfast: true
uploadRoslyn: true
uploadTSLint: true
uploadAsync: true
condition: succeededOrFailed()

37
build/stages/push.yml Normal file
Просмотреть файл

@ -0,0 +1,37 @@
# Upload Stage
stages:
- stage : Package
dependsOn:
- Test
- Compliance
condition: and(succeeded(), eq(variables['Build.SourceBranch'], variables['MainBranch']))
jobs:
- job: Push
displayName: Pack & Push
timeoutInMinutes: 10
pool:
name: $(WindowsPoolName)
steps:
- checkout: self
- task: DownloadBuildArtifacts@0
displayName: Download Packages
inputs:
artifactName: packages
downloadPath: '$(Build.ArtifactStagingDirectory)'
- task: NuGetCommand@2
displayName: 'NuGet Update'
inputs:
command: custom
arguments: 'update -self'
- task: NuGetCommand@2
displayName: Push Packages
continueOnError: true
inputs:
command: push
packagesToPush: '$(Build.ArtifactStagingDirectory)/packages/*.nupkg'
nuGetFeedType: external
publishFeedCredentials: '$(PackagesFeedCredentials)'

57
build/stages/test.yml Normal file
Просмотреть файл

@ -0,0 +1,57 @@
# Test Stage
stages:
- stage: Test
dependsOn: Build
jobs:
- job: Unit
timeoutInMinutes: 10
pool:
name: $(WindowsPoolName)
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
inputs:
artifactName: unit-tests
- task: VSTest@2
displayName: 'Unit Tests'
timeoutInMinutes: 10
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\Tests.dll
searchFolder: '$(Build.ArtifactStagingDirectory)\unit-tests'
testFiltercriteria: 'Flaky!=true'
codeCoverageEnabled: true
runInParallel: true
rerunFailedTests: true
rerunMaxAttempts: 5
- job: Integration
timeoutInMinutes: 10
pool:
name: $(WindowsPoolName)
steps:
- checkout: none
- task: DownloadBuildArtifacts@0
inputs:
artifactName: integration-tests
- task: VSTest@2
displayName: 'Integration Tests'
timeoutInMinutes: 10
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\IntegrationTests.dll
searchFolder: '$(Build.ArtifactStagingDirectory)\integration-tests'
codeCoverageEnabled: false
diagnosticsEnabled: false
runInParallel: false
rerunFailedTests: true
rerunMaxAttempts: 5

21
build/variables.yml Normal file
Просмотреть файл

@ -0,0 +1,21 @@
# Common Variables
variables:
- group: Xamarin Release
- group: Xamarin Signing
- group: Xamarin Notarization
- group: Xamarin-Secrets
- group: xamops-azdev-secrets
- group: akaxvs-secrets
- name: MSBUILDDISABLENODEREUSE
value: 1
- name: VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
value: $(ExternalFeedEndpoints)
- name: DotNetCoreVersion
value: '3.1.102'
- name: WindowsPoolName
value: $(PoolName)
- name: Configuration
value: Release
- name: MainBranch
value: refs/heads/main

24
pipeline.yml Normal file
Просмотреть файл

@ -0,0 +1,24 @@
resources:
repositories:
- repository: templates
type: github
name: xamarin/yaml-templates
ref: refs/heads/main
endpoint: xamarin
trigger:
batch: false
branches:
include:
- main
pr:
- main
variables:
- template: build/variables.yml
stages:
- template: build/stages/build.yml
- template: build/stages/compliance.yml
- template: build/stages/test.yml
- template: build/stages/push.yml

Просмотреть файл

@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<AssemblyName>System.Net.Mqtt</AssemblyName>
<RootNamespace>System.Net.Mqtt</RootNamespace>
<PackageId>$(AssemblyName)</PackageId>
<DocumentationFile>$(IntermediateOutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Label="NuGet">
<PackageId>$(AssemblyName)</PackageId>
<Description>A lightweight and simple MQTT client implementation written entirely in C#.</Description>
</PropertyGroup>
@ -26,5 +25,4 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

Просмотреть файл

@ -5,7 +5,7 @@
<ThisAssemblyNamespace>System.Net.Mqtt</ThisAssemblyNamespace>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup Label="NuGet">
<Authors>Microsoft</Authors>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://raw.githubusercontent.com/xamarin/mqtt/main/LICENSE</PackageLicenseUrl>
@ -14,13 +14,16 @@
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>m2m iot sockets mqtt</PackageTags>
<PackOnBuild Condition="'$(BuildingInsideVisualStudio)' != 'true'">true</PackOnBuild>
<PackageOutputPath Condition="'$(PackOnBuild)' == 'true' And '$(PackageOutputPath)' == ''">$(MSBuildThisFileDirectory)..\pack</PackageOutputPath>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<IncludeFrameworkReferencesInPackage>false</IncludeFrameworkReferencesInPackage>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Hermes.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Project>

Просмотреть файл

@ -7,6 +7,7 @@
<PackageReference Include="System.Diagnostics.Tracer" Version="2.0.8" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.1.1" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
<PackageReference Include="NuGetizer" Version="0.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(IncludeTesting)' == 'true'">

Просмотреть файл

@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<AssemblyName>System.Net.Mqtt.Server</AssemblyName>
<RootNamespace>System.Net.Mqtt.Server</RootNamespace>
<PackageId>$(AssemblyName)</PackageId>
<DocumentationFile>$(IntermediateOutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Label="NuGet">
<PackageId>$(AssemblyName)</PackageId>
<Description>A lightweight and simple MQTT Server implementation written entirely in C#.</Description>
</PropertyGroup>
@ -22,5 +21,4 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>