Skip to content

Commit

Permalink
[Main] Make pipeline ymls work with the SDK repo (#40451)
Browse files Browse the repository at this point in the history
Co-authored-by: Viktor Hofer <[email protected]>
  • Loading branch information
ellahathaway and ViktorHofer authored Apr 26, 2024
1 parent e1922e8 commit 41b3287
Show file tree
Hide file tree
Showing 31 changed files with 310 additions and 170 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"microsoft.dotnet.darc": {
"version": "1.1.0-beta.24210.2",
"commands": [
"darc"
]
}
}
}
55 changes: 55 additions & 0 deletions .devcontainer/vmr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!--
######## ######## ### ######## ######## ## ## #### ######
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ##
######## ###### ## ## ## ## ## ######### ## ######
## ## ## ######### ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ######## ## ## ######## ## ## ## #### ######
-->

This Codespace can help you debug the source build of .NET. In case you have run this from a
`dotnet/sdk` PR branch, it will contain the VMR (`dotnet/dotnet`) checked out into
`/workspaces/dotnet` with the PR changes pulled into it. You can then attempt to source-build
the VMR which is what the VMR leg in the sdk PR build doing. This build takes about 45
minutes and, after completion, produces an archived .NET SDK located in
`/workspaces/dotnet/artifacts/assets/Release`.

## Build the SDK

To build the VMR, run following:
```bash
cd /workspaces/dotnet
./build.sh --online
```

> Please note that, at this time, the build modifies some of the checked-in sources so it might
be preferential to rebuild the Codespace between attempts (or reset the working tree changes).

For more details, see the instructions at https://github.com/dotnet/dotnet.

## Synchronize your changes in locally

When debugging the build, you have two options how to test your changes in this environment.

### Making changes to the VMR directly

You can make the changes directly to the local checkout of the VMR at `/workspaces/dotnet`. You
can then try to build the VMR and see if the change works for you.

### Pull changes into the Codespace from your fork

You can also make a fix in the individual source repository (e.g. `dotnet/runtime`) and push the
fix into a branch; can be in your fork too. Once you have the commit pushed, you can pull this
version of the repository into the Codespace by running:

```
/workspaces/synchronize-vmr.sh \
--repository <repo>:<commit, tag or branch> \
--remote <repo>:<fork URI>
```

You can now proceed building the VMR in the Codespace using instructions above. You can repeat
this process and sync a new commit from your fork. Only note that, at this time, Source-Build
modifies some of the checked-in sources so you'll need to revert the working tree changes
between attempts.
25 changes: 25 additions & 0 deletions .devcontainer/vmr/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Container suitable for investigating issues with source build
// Contains the VMR (dotnet/dotnet) with applied changes from the current PR
// The container supports source-building the SDK
{
"name": "VMR with PR changes",
"image": "mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-39",
"hostRequirements": {
// A completely source built .NET is >64 GB with all the repos/artifacts
"storage": "128gb"
},
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csharp"
]
},
"codespaces": {
"openFiles": [
"sdk/.devcontainer/vmr/README.md"
]
}
},
"onCreateCommand": "${containerWorkspaceFolder}/sdk/.devcontainer/vmr/init.sh",
"workspaceFolder": "/workspaces"
}
30 changes: 30 additions & 0 deletions .devcontainer/vmr/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -ex

source="${BASH_SOURCE[0]}"
script_root="$( cd -P "$( dirname "$source" )" && pwd )"

sdk_dir=$(realpath "$script_root/../..")
workspace_dir=$(realpath "$sdk_dir/../")
tmp_dir=$(realpath "$workspace_dir/tmp")
vmr_dir=$(realpath "$workspace_dir/dotnet")

cp "$sdk_dir/.devcontainer/vmr/synchronize-vmr.sh" "$workspace_dir"

mkdir -p "$tmp_dir"

# Codespaces performs a shallow fetch only
git -C "$sdk_dir" fetch --all --unshallow

# We will try to figure out, which branch is the current (PR) branch based off of
# We need this to figure out, which VMR branch to use
vmr_branch=$(git -C "$sdk_dir" log --pretty=format:'%D' HEAD^ \
| grep 'origin/' \
| head -n1 \
| sed 's@origin/@@' \
| sed 's@,.*@@')

"$workspace_dir/synchronize-vmr.sh" --branch "$vmr_branch" --debug

(cd "$vmr_dir" && ./prep-source-build.sh)
4 changes: 4 additions & 0 deletions .devcontainer/vmr/synchronize-vmr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

(cd /workspaces/sdk \
&& ./eng/vmr-sync.sh --vmr /workspaces/dotnet --tmp /workspaces/tmp $*)
9 changes: 9 additions & 0 deletions eng/Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<!-- VMR bootstrap -->
<ItemGroup Condition="'$(InitializeVMR)' == 'true'">
<ProjectToBuild Include="$(RepoRoot)src/VirtualMonoRepo/Tasks/VirtualMonoRepo.Tasks.csproj" BuildInParallel="false" />
<ProjectToBuild Include="$(RepoRoot)src/VirtualMonoRepo/InitializeVMR.proj" BuildInParallel="false" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions eng/install-scancode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -euo pipefail

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

# See latest release at https://github.com/nexB/scancode-toolkit/releases
SCANCODE_VERSION="32.1.0"

pyEnvPath="/tmp/scancode-env"
python3 -m venv $pyEnvPath
source $pyEnvPath/bin/activate
pip install scancode-toolkit==$SCANCODE_VERSION
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
6 changes: 3 additions & 3 deletions eng/pipelines/templates/jobs/vmr-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### This job builds https://github.com/dotnet/dotnet with given parameters
### If run in an installer PR, new changes are applied to a local copy of the VMR, then it is built and tested
### If run in an sdk PR, new changes are applied to a local copy of the VMR, then it is built and tested

parameters:
- name: architecture
Expand Down Expand Up @@ -86,7 +86,7 @@ parameters:
type: boolean
default: false

#### INSTALLER parameters ####
#### sdk parameters ####

- name: isBuiltFromVmr
displayName: True when build is running from dotnet/dotnet directly
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
parameters:
vmrPath: $(vmrPath)
vmrBranch: ${{ parameters.vmrBranch }}
targetRef: $(Build.SourceVersion) # Synchronize the current installer commit
targetRef: $(Build.SourceVersion) # Synchronize the current sdk commit

- ${{ if parameters.buildFromArchive }}:
- script: |
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/templates/jobs/vmr-synchronization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

parameters:
- name: targetRef
displayName: Target revision of dotnet/installer to synchronize
displayName: Target revision of dotnet/sdk to synchronize
type: string
default: $(Build.SourceVersion)

Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
--github-pat '$(BotAccount-dotnet-bot-repo-PAT)'
--verbose
displayName: Push changes to dotnet/dotnet (public)
workingDirectory: $(Agent.BuildDirectory)/installer
workingDirectory: $(Agent.BuildDirectory)/sdk
# Push internal/release branches to the internal VMR
- ${{ if startsWith(parameters.vmrBranch, 'internal/release/') }}:
Expand All @@ -86,4 +86,4 @@ jobs:
--azdev-pat '$(dn-bot-dnceng-build-rw-code-rw)'
--verbose
displayName: Push changes to dotnet-dotnet (internal)
workingDirectory: $(Agent.BuildDirectory)/installer
workingDirectory: $(Agent.BuildDirectory)/sdk
32 changes: 16 additions & 16 deletions eng/pipelines/templates/steps/vmr-pull-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
type: string

- name: targetRef
displayName: Target revision in dotnet/installer to synchronize
displayName: Target revision in dotnet/sdk to synchronize
type: string
default: $(Build.SourceVersion)

Expand All @@ -19,16 +19,16 @@ parameters:

steps:
- checkout: self
displayName: Clone dotnet/installer
path: installer
displayName: Clone dotnet/sdk
path: sdk

# This step is needed so that when we get a detached HEAD / shallow clone,
# we still pull the commit into the temporary installer clone to use it during the sync.
# we still pull the commit into the temporary sdk clone to use it during the sync.
- script: |
git branch installer-head
git branch sdk-head
git rev-parse HEAD
displayName: Label PR commit
workingDirectory: $(Agent.BuildDirectory)/installer
workingDirectory: $(Agent.BuildDirectory)/sdk

- script: |
git checkout -B ${{ parameters.vmrBranch }}
Expand All @@ -54,17 +54,17 @@ steps:
--tmp $(Agent.TempDirectory)
--azdev-pat '$(dn-bot-all-orgs-code-r)'
--branch ${{ parameters.vmrBranch }}
--repository "installer:${{ parameters.targetRef }}"
--repository "sdk:${{ parameters.targetRef }}"
--recursive
--remote "installer:$(Agent.BuildDirectory)/installer"
--component-template $(Agent.BuildDirectory)/installer/src/VirtualMonoRepo/Component.template.md
--tpn-template $(Agent.BuildDirectory)/installer/src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt
--remote "sdk:$(Agent.BuildDirectory)/sdk"
--component-template $(Agent.BuildDirectory)/sdk/src/VirtualMonoRepo/Component.template.md
--tpn-template $(Agent.BuildDirectory)/sdk/src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt
--debug
||
(echo "##vso[task.logissue type=error]Failed to synchronize the VMR" && exit 1)
displayName: Synchronize dotnet/dotnet (Unix)
condition: ne(variables['Agent.OS'], 'Windows_NT')
workingDirectory: $(Agent.BuildDirectory)/installer
workingDirectory: $(Agent.BuildDirectory)/sdk

- script: git config --global diff.astextplain.textconv echo
displayName: Disable astextplain in git diff (Windows)
Expand All @@ -76,12 +76,12 @@ steps:
-tmp $(Agent.TempDirectory) `
-azdevPat '$(dn-bot-all-orgs-code-r)' `
-branch ${{ parameters.vmrBranch }} `
-repository "installer:${{ parameters.targetRef }}" `
-repository "sdk:${{ parameters.targetRef }}" `
-recursive `
# passing remote fails for some reason, but it is the default anyway
# -remote "installer:$(Agent.BuildDirectory)/installer"
-componentTemplate $(Agent.BuildDirectory)/installer/src/VirtualMonoRepo/Component.template.md `
-tpnTemplate $(Agent.BuildDirectory)/installer/src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt `
# -remote "sdk:$(Agent.BuildDirectory)/sdk"
-componentTemplate $(Agent.BuildDirectory)/sdk/src/VirtualMonoRepo/Component.template.md `
-tpnTemplate $(Agent.BuildDirectory)/sdk/src/VirtualMonoRepo/THIRD-PARTY-NOTICES.template.txt `
-debugOutput
if ($LASTEXITCODE -ne 0) {
Expand All @@ -90,7 +90,7 @@ steps:
}
displayName: Synchronize dotnet/dotnet (Windows)
condition: eq(variables['Agent.OS'], 'Windows_NT')
workingDirectory: $(Agent.BuildDirectory)/installer
workingDirectory: $(Agent.BuildDirectory)/sdk

- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- publish: $(Agent.TempDirectory)
Expand Down
14 changes: 8 additions & 6 deletions eng/pipelines/vmr-build-pr.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# This YAML is used by these PR pipelines:
#
# - installer-source-build
# https://dev.azure.com/dnceng-public/public/_build?definitionId=233
# - installer-unified-build
# https://dev.azure.com/dnceng-public/public/_build?definitionId=277
# - installer-unified-build-full
# https://dev.azure.com/dnceng-public/public/_build?definitionId=279
# - sdk-source-build
# https://dev.azure.com/dnceng-public/public/_build?definitionId=286
# - sdk-unified-build
# https://dev.azure.com/dnceng-public/public/_build?definitionId=287
# - sdk-unified-build-full
# https://dev.azure.com/dnceng-public/public/_build?definitionId=288
# - dotnet-sdk-source-build-internal
# https://dev.azure.com/dnceng/internal/_build?definitionId=1378

trigger: none
pr:
Expand Down
2 changes: 1 addition & 1 deletion src/SourceBuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ For more information, see [dotnet/source-build](https://github.com/dotnet/source
When making changes to the source build infrastructure, devs would typically make and test the
changes in a local clone of [dotnet/dotnet](https://github.com/dotnet/dotnet). Once complete
you would copy the changed files here and make a PR. To validate the end to end experience, you
can synchronize the VMR with any changes made here by running [eng/vmr-sync.sh](https://github.com/dotnet/installer/blob/main/eng/vmr-sync.sh).
can synchronize the VMR with any changes made here by running [eng/vmr-sync.sh](https://github.com/dotnet/sdk/blob/main/eng/vmr-sync.sh).
2 changes: 1 addition & 1 deletion src/SourceBuild/content/.devcontainer/synchronize-vmr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

(cd /workspaces/dotnet/src/installer \
(cd /workspaces/dotnet/src/sdk \
&& ./eng/vmr-sync.sh --vmr /workspaces/dotnet --tmp /workspaces/tmp $*)
4 changes: 2 additions & 2 deletions src/SourceBuild/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ What this means:
In the VMR, you can find:
- source files of [each product repository](#list-of-components) which are mirrored inside of their respective directories under [`src/`](https://github.com/dotnet/dotnet/tree/main/src),
- tooling that enables [building the whole .NET product from source](https://github.com/dotnet/source-build) on Linux platforms,
- small customizations, in the form of [patches](https://github.com/dotnet/dotnet/tree/main/src/installer/src/SourceBuild/patches), applied on top of the original code to make the build possible,
- small customizations, in the form of [patches](https://github.com/dotnet/dotnet/tree/main/src/sdk/src/SourceBuild/patches), applied on top of the original code to make the build possible,
- *[in future]* E2E tests for the whole .NET product.

Just like the development repositories, the VMR will have a release branch for every feature band (e.g. `release/8.0.1xx`).
Expand Down Expand Up @@ -173,7 +173,7 @@ Alternatively, you can also provide a manifest file where this information can b

Sometimes you want to make a change in a repository and test that change in the VMR. You could of course make the change in the VMR directly (locally, as the VMR is read-only for now) but in case it's already available in your repository, you can synchronize it into the VMR (again locally).
To do this, you can either start a [dotnet/dotnet](https://github.com/dotnet/dotnet) Codespace - you will see instructions right after it starts. Alternatively, you can clone the repository locally and use the [vmr-sync.sh](src/installer/eng/vmr-sync.sh) or [vmr-sync.ps1](src/installer/eng/vmr-sync.ps1) script to pull your changes in. Please refer to the documentation in the script for more details.
To do this, you can either start a [dotnet/dotnet](https://github.com/dotnet/dotnet) Codespace - you will see instructions right after it starts. Alternatively, you can clone the repository locally and use the [vmr-sync.sh](src/sdk/eng/vmr-sync.sh) or [vmr-sync.ps1](src/sdk/eng/vmr-sync.ps1) script to pull your changes in. Please refer to the documentation in the script for more details.
## List of components
Expand Down
12 changes: 6 additions & 6 deletions src/SourceBuild/content/eng/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
# - dotnet-source-build (public)
# https://dev.azure.com/dnceng-public/public/_build?definitionId=240
# - PR: ultralite build
# - CI: release/* only, every batched commit, full build
# - CI: release/* and main-sdk only, every batched commit, full build
# - Schedule: main only, full build
#
# - dotnet-unified-build (public)
# https://dev.azure.com/dnceng-public/public/_build?definitionId=278
# - PR: lite build
# - CI: release/* only, every batched commit, full build
# - CI: release/* and main-sdk only, every batched commit, full build
# - Schedule: main only, full build
#
# - dotnet-source-build (internal)
# https://dev.azure.com/dnceng/internal/_build?definitionId=1219
# - PR: ultralite build
# - CI: release/* and internal/release/* only, every batched commit, full build
# - CI: release/*, internal/release/*, and main-sdk only, every batched commit, full build
# - Schedule: main only, full build
#
# - dotnet-source-build-lite (internal)
# https://dev.azure.com/dnceng/internal/_build?definitionId=1299
# - PR: release/* and main, lite build, on-demand trigger
# - PR: release/*, main, and main-sdk only, lite build, on-demand trigger
# - CI: main only, every batched commit, lite build
#
# - dotnet-unified-build (internal)
# https://dev.azure.com/dnceng/internal/_build?definitionId=1330
# - PR: lite build
# - CI: release/*, internal/release/* and main, every batched commit, full build
# - CI: release/*, internal/release/*, main, and main-sdk, every batched commit, full build

variables:
# enable source-only build for pipelines that contain the -source-build string
Expand Down Expand Up @@ -75,7 +75,7 @@ extends:
- ${{ if and(ne(variables.isPRTrigger, 'true'), eq(variables['System.TeamProject'], 'internal')) }}:
- template: /eng/pipelines/templates/stages/vmr-scan.yml@self

- template: /src/installer/eng/pipelines/templates/stages/vmr-build.yml@self
- template: /src/sdk/eng/pipelines/templates/stages/vmr-build.yml@self
parameters:
isBuiltFromVmr: true
isSourceOnlyBuild: ${{ variables.isSourceOnlyBuild }}
Expand Down
Loading

0 comments on commit 41b3287

Please sign in to comment.