Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

License scanning for VMR #17442

Merged
merged 21 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions eng/install-scancode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -euo pipefail

# https://scancode-toolkit.readthedocs.io/en/latest/getting-started/install.html#installation-as-a-library-via-pip

pyEnvPath="/tmp/scancode-env"
python3 -m venv $pyEnvPath
source $pyEnvPath/bin/activate
pip install scancode-toolkit
deactivate

# Setup a script which executes scancode in the virtual environment
cat > /usr/local/bin/scancode << EOF
#!/bin/bash
set -euo pipefail
source $pyEnvPath/bin/activate
scancode "\$@"
deactivate
EOF

chmod +x /usr/local/bin/scancode
124 changes: 124 additions & 0 deletions eng/pipelines/source-build-license-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
schedules:
- cron: "0 7 * * 1-5"
displayName: Run on weekdays at 7am UTC
branches:
include:
- main
- release/*

pr: none
trigger: none

variables:
installerRoot: '$(Build.SourcesDirectory)/src/installer'

jobs:
- job: Setup
pool:
name: NetCore1ESPool-Svc-Internal
demands: ImageOverride -equals 1es-ubuntu-2004
steps:
- script: |
vmrSrcDir="$(Build.SourcesDirectory)/src"

# Builds an Azure DevOps matrix definition. Each entry in the matrix is a path,
# allowing a job to be run for each src repo.
matrix=""
for dir in $vmrSrcDir/*/
do
if [ ! -z "$matrix" ]; then
matrix="$matrix,"
fi
repoName=$(basename $dir)
#matrix="$matrix{ \"$repoName\": { \"repoPath\": \"$dir\" } }"
matrix="$matrix \"$repoName\": { \"repoPath\": \"$dir\" }"
done

matrix="{ $matrix }"

echo "##vso[task.setvariable variable=matrix;isOutput=true]$matrix"
name: GetMatrix
displayName: Get Matrix

- job: LicenseScan
dependsOn: Setup
pool:
name: NetCore1ESPool-Svc-Internal
demands: ImageOverride -equals 1es-ubuntu-2004
timeoutInMinutes: 420
strategy:
matrix: $[ dependencies.Setup.outputs['GetMatrix.matrix'] ]
steps:

- task: UseDotNet@2
mthalman marked this conversation as resolved.
Show resolved Hide resolved
displayName: Install .NET
inputs:
packageType: 'sdk'
version: '8.0.x'
includePreviewVersions: true

- task: PipAuthenticate@1
displayName: 'Pip Authenticate'
inputs:
artifactFeeds: public/dotnet-public-pypi
onlyAddExtraIndex: false

- script: $(installerRoot)/eng/install-scancode.sh
displayName: Install Scancode

- script: >
dotnet test
$(Build.SourcesDirectory)/test/Microsoft.DotNet.SourceBuild.SmokeTests/Microsoft.DotNet.SourceBuild.SmokeTests.csproj
--filter "Category=LicenseScan"
mthalman marked this conversation as resolved.
Show resolved Hide resolved
--logger:'trx;LogFileName=$(Agent.JobName)_LicenseScan.trx'
--logger:'console;verbosity=detailed'
-c Release
-bl:$(Build.SourcesDirectory)/artifacts/log/Debug/BuildTests_$(date +"%m%d%H%M%S").binlog
-flp:LogFile=$(Build.SourcesDirectory)/artifacts/logs/BuildTests_$(date +"%m%d%H%M%S").log
-clp:v=m
-e SMOKE_TESTS_LICENSE_SCAN_PATH=$(repoPath)
-e SMOKE_TESTS_RUNNING_IN_CI=true
-e SMOKE_TESTS_WARN_LICENSE_SCAN_DIFFS=false
-e SMOKE_TESTS_TARGET_RID=linux-x64
-e SMOKE_TESTS_PORTABLE_RID=linux-x64
displayName: Run Tests
workingDirectory: $(Build.SourcesDirectory)

- script: |
set -x
targetFolder=$(Build.StagingDirectory)/BuildLogs/
mkdir -p ${targetFolder}
cd "$(Build.SourcesDirectory)"
find artifacts/ -type f -name "BuildTests*.binlog" -exec cp {} --parents -t ${targetFolder} \;
find artifacts/ -type f -name "BuildTests*.log" -exec cp {} --parents -t ${targetFolder} \;
echo "Updated:"
find test/ -type f -name "Updated*.json"
find test/ -type f -name "Updated*.json" -exec cp {} --parents -t ${targetFolder} \;
echo "Results:"
find test/ -type f -name "scancode-results*.json"
find test/ -type f -name "scancode-results*.json" -exec cp {} --parents -t ${targetFolder} \;
echo "All:"
ls -R test/
echo "BuildLogs:"
ls -R ${targetFolder}
displayName: Prepare BuildLogs staging directory
continueOnError: true
condition: succeededOrFailed()

- publish: '$(Build.StagingDirectory)/BuildLogs'
artifact: $(Agent.JobName)_BuildLogs_Attempt$(System.JobAttempt)
displayName: Publish BuildLogs
continueOnError: true
condition: succeededOrFailed()

- task: PublishTestResults@2
displayName: Publish Test Results
condition: succeededOrFailed()
continueOnError: true
inputs:
testRunner: vSTest
testResultsFiles: '*.trx'
searchFolder: $(Build.SourcesDirectory)/test/Microsoft.DotNet.SourceBuild.SmokeTests/TestResults
mergeTestResults: true
publishRunAttachments: true
testRunTitle: $(Agent.JobName)
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void CompareEntries(string baselineFileName, IOrderedEnumerable<st

public static void CompareBaselineContents(string baselineFileName, string actualContents, ITestOutputHelper outputHelper, bool warnOnDiffs = false)
{
string actualFilePath = Path.Combine(DotNetHelper.LogsDirectory, $"Updated{baselineFileName}");
string actualFilePath = Path.Combine(TestBase.LogsDirectory, $"Updated{baselineFileName}");
File.WriteAllText(actualFilePath, actualContents);

CompareFiles(GetBaselineFilePath(baselineFileName), actualFilePath, outputHelper, warnOnDiffs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;
/// <see cref="WebScenarioTests"/> for related web scenarios.
/// They are encapsulated in a separate testclass so that they can be run in parallel.
/// </summary>
public class BasicScenarioTests : SmokeTests
public class BasicScenarioTests : SdkTests
{
public BasicScenarioTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ internal static class Config
public const string SourceBuiltArtifactsPathEnv = "SMOKE_TESTS_SOURCEBUILT_ARTIFACTS_PATH";
public const string TargetRidEnv = "SMOKE_TESTS_TARGET_RID";
public const string WarnSdkContentDiffsEnv = "SMOKE_TESTS_WARN_SDK_CONTENT_DIFFS";
public const string WarnLicenseScanDiffsEnv = "SMOKE_TESTS_WARN_LICENSE_SCAN_DIFFS";
public const string RunningInCIEnv = "SMOKE_TESTS_RUNNING_IN_CI";
public const string LicenseScanPathEnv = "SMOKE_TESTS_LICENSE_SCAN_PATH";

public static string DotNetDirectory { get; } =
Environment.GetEnvironmentVariable(DotNetDirectoryEnv) ?? Path.Combine(Directory.GetCurrentDirectory(), ".dotnet");
Expand All @@ -31,15 +33,18 @@ internal static class Config
public static string? PrereqsPath { get; } = Environment.GetEnvironmentVariable(PrereqsPathEnv);
public static string? CustomPackagesPath { get; } = Environment.GetEnvironmentVariable(CustomPackagesPathEnv);
public static string? SdkTarballPath { get; } = Environment.GetEnvironmentVariable(SdkTarballPathEnv);
public static string SourceBuiltArtifactsPath { get; } = Environment.GetEnvironmentVariable(SourceBuiltArtifactsPathEnv) ??
throw new InvalidOperationException($"'{Config.SourceBuiltArtifactsPathEnv}' must be specified");
public static string? SourceBuiltArtifactsPath { get; } = Environment.GetEnvironmentVariable(SourceBuiltArtifactsPathEnv);
public static string TargetRid { get; } = Environment.GetEnvironmentVariable(TargetRidEnv) ??
throw new InvalidOperationException($"'{Config.TargetRidEnv}' must be specified");
public static string TargetArchitecture { get; } = TargetRid.Split('-')[1];
public static bool WarnOnSdkContentDiffs { get; } =
bool.TryParse(Environment.GetEnvironmentVariable(WarnSdkContentDiffsEnv), out bool warnOnSdkContentDiffs) && warnOnSdkContentDiffs;
public static bool WarnOnLicenseScanDiffs { get; } =
bool.TryParse(Environment.GetEnvironmentVariable(WarnLicenseScanDiffsEnv), out bool warnOnLicenseScanDiffs) && warnOnLicenseScanDiffs;

// Indicates whether the tests are being run in the context of a CI pipeline
public static bool RunningInCI { get; } =
bool.TryParse(Environment.GetEnvironmentVariable(RunningInCIEnv), out bool runningInCI) && runningInCI;

public static string? LicenseScanPath { get; } = Environment.GetEnvironmentVariable(LicenseScanPathEnv);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Microsoft.DotNet.SourceBuild.SmokeTests;

public class DebugTests : SmokeTests
public class DebugTests : SdkTests
{
private record ScanResult(string FileName, bool HasDebugInfo, bool HasDebugAbbrevs, bool HasFileSymbols, bool HasGnuDebugLink);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.DotNet.SourceBuild.SmokeTests;

public class DotNetFormatTests : SmokeTests
public class DotNetFormatTests : SdkTests
{
private const string TestFileName = "FormatTest.cs";
private const string UnformattedFileName = "FormatTestUnformatted.cs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -21,7 +19,6 @@ internal class DotNetHelper
private static readonly object s_lockObj = new();

public static string DotNetPath { get; } = Path.Combine(Config.DotNetDirectory, "dotnet");
public static string LogsDirectory { get; } = Path.Combine(Directory.GetCurrentDirectory(), "logs");
public static string PackagesDirectory { get; } = Path.Combine(Directory.GetCurrentDirectory(), "packages");
public static string ProjectsDirectory { get; } = Path.Combine(Directory.GetCurrentDirectory(), $"projects-{DateTime.Now:yyyyMMddHHmmssffff}");

Expand Down Expand Up @@ -56,11 +53,6 @@ public DotNetHelper(ITestOutputHelper outputHelper)
{
Directory.CreateDirectory(PackagesDirectory);
}

if (!Directory.Exists(LogsDirectory))
{
Directory.CreateDirectory(LogsDirectory);
}
}
}

Expand Down Expand Up @@ -261,7 +253,7 @@ private static string GetBinLogOption(string projectName, string command, string
fileName += $"-{differentiator}";
}

return $"/bl:{Path.Combine(LogsDirectory, $"{fileName}.binlog")}";
return $"/bl:{Path.Combine(TestBase.LogsDirectory, $"{fileName}.binlog")}";
}

private static bool DetermineIsMonoRuntime(string dotnetRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Microsoft.DotNet.SourceBuild.SmokeTests;

public class DotNetWatchTests : SmokeTests
public class DotNetWatchTests : SdkTests
{
public DotNetWatchTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

Expand Down
Loading