Repository navigation
Add reproducibility validation test for SDK tarball - #6622
Conversation
|
@omajid - PTAL |
There was a problem hiding this comment.
Pull request overview
Adds a new CI pipeline + test suite to detect non-determinism by rebuilding the VMR twice in one run and comparing the resulting SDK tarballs against exclusion/baseline files.
Changes:
- Introduces
ReproducibilityTeststhat compares two SDK tarballs and validates diffs against recorded baselines with exclusion support. - Adds a new
unified-build-reproducibility-tests.ymlpipeline withBuild1,Build2, andComparestages plus a reusablereproducibility-testjob template. - Extends the baseline-update PR tooling to support a new
reproducibilitypipeline type and update the new baseline/exclusion assets.
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.DotNet.Tests/ReproducibilityTests.cs | New xUnit tests to compare two SDK tarballs and emit updated baseline/exclusion artifacts. |
| test/Microsoft.DotNet.Tests/Microsoft.DotNet.Tests.csproj | Plumbs tarball paths into runtime config so tests can locate build artifacts. |
| test/Microsoft.DotNet.Tests/Config.cs | Adds config switches for the two tarball paths per build type. |
| test/Microsoft.DotNet.Tests/assets/ReproducibilityTests/SourceBuiltReproducibilityExclusions.txt | New exclusions list for known Source-Built reproducibility diffs. |
| test/Microsoft.DotNet.Tests/assets/ReproducibilityTests/MsftReproducibilityExclusions.txt | New exclusions list for known Microsoft reproducibility diffs. |
| test/Microsoft.DotNet.Tests/assets/ReproducibilityTests/SourceBuiltReproducibilityBaseline.diff | Baseline file for remaining diffs after exclusions (currently empty). |
| test/Microsoft.DotNet.Tests/assets/ReproducibilityTests/MsftReproducibilityBaseline.diff | Baseline file for remaining diffs after exclusions (currently empty). |
| eng/pipelines/unified-build-reproducibility-tests.yml | New scheduled/triggered pipeline that runs the reproducibility validation. |
| eng/pipelines/templates/stages/reproducibility-tests.yml | New stage template defining Build1/Build2/Compare orchestration. |
| eng/pipelines/templates/jobs/reproducibility-test.yml | New job template to download both tarballs, run tests, publish logs/results, and open baseline update PRs. |
| eng/pipelines/templates/jobs/vmr-build.yml | Adds an extra dependsOn parameter to allow explicit job dependencies beyond artifact reuse. |
| eng/pipelines/templates/steps/create-baseline-update-pr.yml | Updates documentation comment to include the new reproducibility mode. |
| eng/tools/CreateBaselineUpdatePR/Program.cs | Adds reproducibility command entry point. |
| eng/tools/CreateBaselineUpdatePR/Pipelines.cs | Adds Reproducibility enum value. |
| eng/tools/CreateBaselineUpdatePR/PRCreator.cs | Adjusts exclusion update behavior for the new pipeline type (union behavior enabled). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collapses the separate restore + test steps into a single invocation that uses eng/common/dotnet.sh test. The dotnet SDK is installed by that script to its default location, which matches the default the create-baseline-update-pr template expects, so the explicit dotnetPath override is no longer needed. Co-authored-by: Copilot <[email protected]>
Includes /eng/common/templates-official/variables/pool-providers.yml so the DncEngInternalBuildPool variable is defined, then uses it for both the main pool and the SDL sourceAnalysisPool. The variable resolves to NetCore1ESPool-Svc-Internal on release branches and NetCore1ESPool-Internal on main, matching the cost-of-goods-sold pool routing used by other pipelines such as vmr-compare.yml, source-build-outer-loop.yml, and official.yml. Also switches the main pool image from 1es-ubuntu-2204 to build.azurelinux.3.amd64 to match source-build-sdk-diff-tests.yml and vmr-license-scan.yml. Co-authored-by: Copilot <[email protected]>
Splits ReproducibilityTests out of the general-purpose Microsoft.DotNet.Tests project into a dedicated Microsoft.DotNet.Reproducibility.Tests project. This avoids further overloading Microsoft.DotNet.Tests with reproducibility-specific RuntimeHostConfigurationOption entries and Config properties. Changes: - Add Microsoft.DotNet.Reproducibility.Tests.csproj with only the references and configuration knobs the reproducibility tests need (TestUtilities project ref + 5 RuntimeHostConfigurationOption items). - Add a project-local Config.cs scoped to the reproducibility-specific config keys. - Remove the four SDK-tarball-path Config properties and matching RuntimeHostConfigurationOption items from Microsoft.DotNet.Tests. - Move ReproducibilityTests.cs and its assets to the new project. The assets/ReproducibilityTests/ subdirectory is collapsed into assets/ since the project is now reproducibility-specific. - Add the new project to tests.proj. - Update the reproducibility-test pipeline to point at the new csproj and asset directory; drop the now-unnecessary Category filter. Co-authored-by: Copilot <[email protected]>
The test compares SHA256 of regular-file contents inside the SDK tarball; it does not compare tar metadata (mode/uid/gid/mtime/entry order/gzip header) or non-regular entries (symlinks, hardlinks, directories). Update the pipeline header, stage template, and method docstring to describe what the test actually validates instead of implying byte-for-byte tarball reproducibility. Co-authored-by: Copilot <[email protected]>
ExclusionsHelper.GenerateNewBaselineFile and the test's own File.WriteAllText call both write into Config.LogsDirectory. In CI the directory is created by the build harness, but local runs may not have created it yet, in which case the writes throw. Call Directory.CreateDirectory up front (idempotent) to make the test robust across environments. Co-authored-by: Copilot <[email protected]>
Skip the Build1 and Build2 stages and have Compare download the SDK
tarballs from a previously-completed run of this pipeline (build 2975877
in pipeline 1620, which produced all four expected Build1_*/Build2_*
artifact sets). This lets the Compare jobs iterate without paying the
cost of two full VMR builds on every push.
Revert before merging:
1. eng/pipelines/templates/stages/reproducibility-tests.yml
- Drop 'condition: false' from the Build1 stage.
- Drop 'condition: false' from the Build2 stage.
- Restore Compare's 'dependsOn: [Build1, Build2]'.
2. eng/pipelines/templates/jobs/reproducibility-test.yml
- In both DownloadPipelineArtifact@2 tasks, replace
buildType: specific
project: internal
pipeline: 1620
buildVersionToDownload: specific
buildId: 2975877
with
buildType: current
Co-authored-by: Copilot <[email protected]>
This reverts commit d767a70.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 16 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
eng/pipelines/templates/stages/reproducibility-tests.yml:66
Build2stage is also permanently disabled viacondition: false. Since the pipeline’s core intent is to build twice and compare, this will prevent the pipeline from ever validating reproducibility. Remove the hard-coded false condition (or gate it behind a parameter) to enable the second build leg.
- stage: Build2
dependsOn: []
condition: false
variables:
eng/pipelines/templates/jobs/reproducibility-test.yml:86
- Second tarball download is also hardcoded to a specific pipeline/build (
pipeline: 1620,buildId: 2975877). This will break reproducibility validation for new runs. Download the artifact from the current run’sBuild2stage (or parameterize the pipeline/buildId) to align with the intended design.
- task: DownloadPipelineArtifact@2
inputs:
buildType: specific
project: internal
pipeline: 1620
buildVersionToDownload: specific
buildId: 2975877
artifact: ${{ parameters.build2JobName }}_Artifacts
The log collection step searches under artifacts/log/ for ReproTests*.log, but the file logger was writing to artifacts/logs/ (with an 's'), so the .log file was never staged or published. Align the file logger's output path with what the collection step expects. Co-authored-by: Copilot <[email protected]>
The previous expansion of "- ${{ parameters.reuseBuildArtifactsFrom }}"
splatted the entire array as a single list item, which produced an
invalid "- []" entry when reuseBuildArtifactsFrom was empty but the new
dependsOn parameter had items. Iterate both lists with "each" so each
element becomes its own dependsOn entry, matching the pattern already
used for dependsOn.
Co-authored-by: Copilot <[email protected]>
Drop arguments that duplicate VMR defaults or csproj configuration: - "-c Release" matches the Release default set in the root Directory.Build.props. - "-clp:v=m" matches the MSBuild console logger default. - "--logger:trx;..." and "--logger:console;..." duplicate the VSTestLogger property already configured in the csproj. - "-flp:LogFile=..." is redundant with the binlog, which captures the same MSBuild output in a richer form. Keep only the binlog and the SDK-tarball path properties as CI-specific arguments. The log-collection step is updated accordingly to stop searching for the no-longer-produced .log files. Also align the binlog filename, testResultsFiles pattern, and testRunTitle prefix with vmr-build.yml's conventions: - Use a static ReproducibilityTests.binlog name rather than a timestamped one. - Tighten testResultsFiles from "**/*.trx" to "artifacts/TestResults/Release/*.trx". - Prefix testRunTitle with "Tests_". Co-authored-by: Copilot <[email protected]>
Add a setDeterministicTimestamp parameter to vmr-build.yml that, when true, exports SOURCE_DATE_EPOCH (Unix seconds derived from System.PipelineStartTime) on every build script invocation in the job. NuGet pack stamps that timestamp into every .nupkg ZIP envelope, so two independent builds in the same pipeline run get matching package envelopes. AzDO YAML expressions cannot compute Unix-epoch seconds from a date string, so the conversion is done in a cross-platform pwsh step at the start of the job, and the resulting value is stored in a SourceDateEpoch pipeline variable that the build script env: blocks reference. Both the compute step and the env: entries are conditional on the new parameter so the behavior is opt-in; pipelines that don't enable it see no change. The reproducibility test pipeline opts in for all four Build1/Build2 VMR build invocations. Co-authored-by: Copilot <[email protected]>
# Conflicts: # eng/pipelines/templates/jobs/vmr-build.yml
|
One thing that we have seen in the past is that rebuilding dotnet on different days produces artifacts with different versions (example from a while ago). Is it possible to move the clock forward by a few days between the two builds? |
…elineStartTime System.PipelineStartTime is set per-job, not per-run, so parallel jobs get different values. Build.BuildNumber (format YYYYMMDD.Revision) is consistent across all stages and jobs in the same pipeline run. Parse the date portion into Unix epoch seconds and add the revision offset, matching the approach in dotnet#5256. Co-authored-by: Copilot <[email protected]>
Add an initSteps parameter to vmr-build.yml that injects custom steps after checkout but before the build. The reproducibility pipeline uses this to advance the system clock by one day in Build2's jobs, so any code that derives values from the current wall-clock time (rather than from OfficialBuildId) will produce different output between Build1 and Build2, exposing date-dependent reproducibility issues like dotnet/source-build#2852. Build1 runs with the real date; Build2 runs one day ahead. Both stages still share the same OfficialBuildId (from Build.BuildNumber) so version strings derived from the official build ID are unaffected. Co-authored-by: Copilot <[email protected]>
…late Remove the setDeterministicTimestamp parameter and associated pwsh step and conditional env entries from vmr-build.yml. SOURCE_DATE_EPOCH is now set via a step template (set-source-date-epoch.yml) injected through the new initSteps parameter, keeping vmr-build.yml generic. The reproducibility pipeline passes this template through initSteps for all four Build1/Build2 job invocations. Co-authored-by: Copilot <[email protected]>
I've added that here: 112678d. It didn't produce any additional diffs. |
Gate the SOURCE_DATE_EPOCH environment variable behind a new setSourceDateEpoch parameter so it is only set for reproducibility builds. Previously the env var was set unconditionally, resolving to the literal string '$(SOURCE_DATE_EPOCH)' in normal CI builds and breaking emsdk (invalid integer) and CMake compiler detection. Co-authored-by: Copilot <[email protected]>
When neither setSourceDateEpoch nor sign is true, the env block would be empty, causing a YAML parse error at pipeline validation. Wrap the entire env block in a conditional so it is only emitted when at least one entry will be present. Co-authored-by: Copilot <[email protected]>
The runTests conditional wrapping the test step was accidentally dropped, leaving the test script step orphaned inside the build step's property mapping and causing a YAML parse error. Co-authored-by: Copilot <[email protected]>
|
Ready for another review |
Co-authored-by: Copilot <[email protected]>
Summary
Adds an automated test that validates the SDK tarball produced by the VMR build is byte-reproducible: building the same source twice should produce identical artifacts. The test fails the pipeline whenever a new non-deterministic file appears that isn't either a known root-cause-justified exclusion or already in the recorded baseline.
Architecture
The pipeline (eng/pipelines/unified-build-reproducibility-tests.yml) builds the VMR twice within a single pipeline run and compares the two SDK tarballs. Building twice inside the same pipeline run ensures both halves share the same pipeline-resolved container image digest (so the same clang/LLD toolchain), the same
Build.SourceVersion, and the sameBuild.BuildNumber- eliminating environmental drift as a source of false-positive diffs.The stage template (eng/pipelines/templates/stages/reproducibility-tests.yml) defines three stages:
Build1- source-build leg + Microsoft leg (Linux x64).Build2- identical toBuild1, runs in parallel.Compare- downloads both stages' SDK tarballs and runs the test job.The
reproducibility-testjob template (eng/pipelines/templates/jobs/reproducibility-test.yml) downloads the two SDK tarballs from the current pipeline'sBuild1andBuild2stages and runs the test against both tarballs.Test implementation
ReproducibilityTests.cs reads both tarballs, computes a
SHA256hash for each file in each tarball, and compares the two hash maps. Files matching patterns in the exclusions file are skipped before comparison; the remaining diffs are formatted as a sorted list and compared against a recorded baseline file. The test fails when the diff list doesn't match the baseline.Fixes dotnet/source-build#5486