-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
929 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Pipeline documentation at https://github.com/dotnet/dotnet/blob/main/docs/license-scanning.md | ||
|
||
schedules: | ||
- cron: "0 7 * * 1-5" | ||
displayName: Run on weekdays at 7am UTC | ||
branches: | ||
include: | ||
- main | ||
- release/* | ||
|
||
pr: none | ||
trigger: none | ||
|
||
parameters: | ||
# Provides a way to scan a specific repo. If not provided, all repos of the VMR will be scanned. | ||
- name: specificRepoName | ||
type: string | ||
displayName: "Specific repo name to scan (e.g. runtime, sdk). If empty, scans all repos of the VMR." | ||
default: " " # Set it to an empty string to allow it be an optional parameter | ||
|
||
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="" | ||
# Trim leading/trailing spaces from the repo name | ||
specificRepoName=$(echo "${{ parameters.specificRepoName }}" | awk '{$1=$1};1') | ||
# If the repo name is provided, only scan that repo. | ||
if [ ! -z "$specificRepoName" ]; then | ||
matrix="\"$specificRepoName\": { \"repoPath\": \"$vmrSrcDir/$specificRepoName\" }" | ||
else | ||
for dir in $vmrSrcDir/*/ | ||
do | ||
if [ ! -z "$matrix" ]; then | ||
matrix="$matrix," | ||
fi | ||
repoName=$(basename $dir) | ||
matrix="$matrix \"$repoName\": { \"repoPath\": \"$dir\" }" | ||
done | ||
fi | ||
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: | ||
|
||
- script: $(Build.SourcesDirectory)/prep.sh --no-artifacts --no-bootstrap --no-prebuilts | ||
displayName: 'Install .NET SDK' | ||
|
||
- task: PipAuthenticate@1 | ||
displayName: 'Pip Authenticate' | ||
inputs: | ||
artifactFeeds: public/dotnet-public-pypi | ||
onlyAddExtraIndex: false | ||
|
||
- script: $(installerRoot)/eng/install-scancode.sh | ||
displayName: Install Scancode | ||
|
||
- script: > | ||
$(Build.SourcesDirectory)/.dotnet/dotnet test | ||
$(Build.SourcesDirectory)/test/Microsoft.DotNet.SourceBuild.SmokeTests/Microsoft.DotNet.SourceBuild.SmokeTests.csproj | ||
--filter "FullyQualifiedName=Microsoft.DotNet.SourceBuild.SmokeTests.LicenseScanTests.ScanForLicenses" | ||
--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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# License Scanning | ||
|
||
The VMR is regularly scanned for license references to ensure that only open-source license are used where relevant. | ||
|
||
License scanning pipline: https://dev.azure.com/dnceng/internal/_build?definitionId=1301 (internal only) | ||
|
||
License scanning test: https://github.com/dotnet/dotnet/blob/main/test/Microsoft.DotNet.SourceBuild.SmokeTests/LicenseScanTests.cs | ||
|
||
By default, running the pipeline will scan all repos within the VMR which takes several hours to run. | ||
The pipeline can be triggered manually to target a specific repo within the VMR by setting the `specificRepoName` parameter. | ||
This value should be the name of the repo within the VMR (i.e. a name of a directory within https://github.com/dotnet/dotnet/tree/main/src). | ||
To test source modifications intended to resolve a license issue, apply the change in an internal branch of the VMR. | ||
Run this pipeline, targeting your branch, and set the `specificRepoName` parameter to the name of the repo containing the change. | ||
|
||
The output of the pipeline is a set of test results and logs. | ||
The logs are published as an artifact and can be found at test/Microsoft.DotNet/SourceBuild.SmokeTests/bin/Release/netX.0/logs. | ||
It consists of the following: | ||
* `UpdatedLicenses.<repo-name>.json`: This is the output of that gets compared to the stored baseline. | ||
If they're the same, the test passes; if not, it fails. By comparing this file to the baseline, one can determine which new license | ||
references have been introduced. | ||
If everything is deemed to be acceptable, the developer can either update the allowed licenses, update the exclusions file, update the | ||
baseline, or any combination. | ||
* `scancode-results.json`: This is the raw output that comes from scancode. This file is useful for diagnostic purposes because it tells you | ||
the exact line number of where a license has been detected in a file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.