Skip to content

Commit 11ecfb3

Browse files
committed
[CI] Build only the relevant projects for Quarantined/Outerloop
.. workflows. These workflows have been running out of space on github runners while just building the solution, even though it is just the test projects. What we really need is a few test projects with the relevant attribute like `[OuterloopTest("..")]`, and generate the runsheet for them. So we add a new shell script which can find such projects, and then build only those. This makes it much faster too. Fixes #13210 .
1 parent e6cc8a5 commit 11ecfb3

File tree

5 files changed

+87
-14
lines changed

5 files changed

+87
-14
lines changed

.github/workflows/specialized-test-runner.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
required: true
99
type: string
1010
description: 'Arcade test runner name'
11+
attributeName:
12+
required: true
13+
type: string
14+
description: 'Attribute name to filter tests by like QuarantinedTest or OuterLoopTest'
1115
extraRunSheetBuilderArgs:
1216
required: false
1317
type: string
@@ -33,13 +37,12 @@ jobs:
3337
if: ${{ github.repository_owner == 'dotnet' }}
3438
outputs:
3539
runsheet: ${{ steps.generate_tests_matrix.outputs.runsheet }}
40+
requiresNugets: ${{ steps.check_nugets.outputs.requiresNugets }}
3641
steps:
3742
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3843

39-
- name: Show disk usage before build
40-
run: |-
41-
df -h
42-
du -sh ${{ github.workspace }}
44+
- name: Identify relevant test projects
45+
run: ./eng/scripts/generate-specialized-test-projects-list.sh ${{ inputs.attributeName }} ${{ github.workspace }}/artifacts/BeforeBuildProps.props
4346

4447
# We need to build test projects, so that we can interrogate each test project
4548
# and find out whether it contains any tests of the specified type.
@@ -50,9 +53,9 @@ jobs:
5053
--restore
5154
--build
5255
-c Release
53-
/p:BuildTestsOnly=true
5456
/p:GeneratePackageOnBuild=false
5557
/p:InstallBrowsersForPlaywright=false
58+
/p:BeforeBuildPropsPath=${{ github.workspace }}/artifacts/BeforeBuildProps.props
5659
5760
- name: Generate test runsheet
5861
id: generate_tests_matrix
@@ -67,30 +70,35 @@ jobs:
6770
/p:Restore=false
6871
/p:Build=false
6972
/p:InstallBrowsersForPlaywright=false
73+
/p:BeforeBuildPropsPath=${{ github.workspace }}/artifacts/BeforeBuildProps.props
7074
/bl:${{ github.workspace }}/artifacts/log/Release/runsheet.binlog
7175
72-
- name: Show disk usage after build
73-
if: ${{ always() }}
74-
run: |-
75-
df -h
76-
du -d 1 -h ~/.nuget/packages
77-
du -d 1 -h ${{ github.workspace }}
78-
du -d 1 -h ${{ github.workspace }}/artifacts
76+
- name: Check if any test requires NuGets
77+
id: check_nugets
78+
run: |
79+
RUNSHEET='${{ steps.generate_tests_matrix.outputs.runsheet }}'
80+
if echo "$RUNSHEET" | jq -e 'any(.[]; .requiresNugets == true)' > /dev/null 2>&1; then
81+
echo "requiresNugets=true" >> $GITHUB_OUTPUT
82+
else
83+
echo "requiresNugets=false" >> $GITHUB_OUTPUT
84+
fi
7985
8086
- name: Upload logs, and test results
8187
if: ${{ always() }}
8288
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
8389
with:
8490
name: logs-runsheet
8591
path: |
92+
${{ github.workspace }}/artifacts/BeforeBuildProps.props
8693
${{ github.workspace }}/artifacts/log/*/runsheet.binlog
8794
${{ github.workspace }}/artifacts/log/*/TestLogs/**
8895
${{ github.workspace }}/artifacts/tmp/*/combined_runsheet.json
8996
retention-days: 5
9097

9198
build_packages:
9299
name: Build packages
93-
if: ${{ github.repository_owner == 'dotnet' }}
100+
needs: [generate_tests_matrix]
101+
if: ${{ github.repository_owner == 'dotnet' && needs.generate_tests_matrix.outputs.requiresNugets == 'true' }}
94102
uses: ./.github/workflows/build-packages.yml
95103

96104
run_tests:
@@ -100,7 +108,7 @@ jobs:
100108
fail-fast: false
101109
matrix:
102110
tests: ${{ fromJson(needs.generate_tests_matrix.outputs.runsheet) }}
103-
if: ${{ github.repository_owner == 'dotnet' }}
111+
if: ${{ always() && github.repository_owner == 'dotnet' && needs.generate_tests_matrix.result == 'success' && (needs.build_packages.result == 'success' || needs.build_packages.result == 'skipped') }}
104112
uses: ./.github/workflows/run-tests.yml
105113
with:
106114
testShortName: ${{ matrix.tests.project }}

.github/workflows/tests-outerloop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
uses: ./.github/workflows/specialized-test-runner.yml
3636
with:
3737
testRunnerName: "OuterloopTestRunsheetBuilder"
38+
attributeName: "OuterloopTest"
3839
extraRunSheetBuilderArgs: "-p:RunOuterloopTests=true"
3940
extraTestArgs: "--filter-trait outerloop=true"
4041
enablePlaywrightInstall: true

.github/workflows/tests-quarantine.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
uses: ./.github/workflows/specialized-test-runner.yml
3636
with:
3737
testRunnerName: "QuarantinedTestRunsheetBuilder"
38+
attributeName: "QuarantinedTest"
3839
extraRunSheetBuilderArgs: "-p:RunQuarantinedTests=true"
3940
extraTestArgs: "--filter-trait quarantined=true"
4041
enablePlaywrightInstall: true

eng/Build.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
TargetRids - colon separated list of RIDs to build native projects for
1111
-->
1212

13+
<!-- Import custom props file if specified -->
14+
<Import Project="$(BeforeBuildPropsPath)" Condition="'$(BeforeBuildPropsPath)' != '' and Exists('$(BeforeBuildPropsPath)')" />
15+
1316
<PropertyGroup>
1417
<BuildRid>$([System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier)</BuildRid>
1518

@@ -62,6 +65,13 @@
6265
<ProjectToBuild Include="@(_NativeProjectToBuild->Exists())" />
6366
</ItemGroup>
6467

68+
<!-- Override ProjectToBuild items if specified -->
69+
<ItemGroup Condition="'@(OverrideProjectToBuild)' != ''">
70+
<ProjectToBuild Remove="@(ProjectToBuild)" />
71+
72+
<ProjectToBuild Include="@(OverrideProjectToBuild)" />
73+
</ItemGroup>
74+
6575
<!-- When building from source, we want to use the live repo contents as opposed to cloning the repo. -->
6676
<PropertyGroup Condition="'$(ArcadeBuildFromSource)' == 'true' or '$(DotNetBuildRepo)' == 'true'">
6777
<CopySrcInsteadOfClone>true</CopySrcInsteadOfClone>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# This script generates an MSBuild props file listing test projects that contain tests
4+
# marked with a specific attribute (e.g., QuarantinedTest).
5+
#
6+
# Usage: ./generate-specialized-test-projects-list.sh <attribute_name>
7+
# Example: ./generate-specialized-test-projects-list.sh QuarantinedTest
8+
9+
set -euo pipefail
10+
set -x
11+
12+
if [[ $# -ne 2 ]]; then
13+
echo "Usage: $0 <attribute_name> <output_file>"
14+
exit 1
15+
fi
16+
17+
ATTRIBUTE_NAME="${1:?Usage: $0 <attribute_name>}"
18+
REPO_ROOT="$(git rev-parse --show-toplevel)"
19+
OUTPUT_FILE="$2"
20+
21+
mkdir -p `dirname $OUTPUT_FILE`
22+
23+
# Find all test files with the attribute and extract unique top-level test directories
24+
PROJECTS=$(grep -rl "^ *\[${ATTRIBUTE_NAME}(\"[^\"]*\")\]" "$REPO_ROOT/tests" 2>/dev/null \
25+
| while read -r file; do
26+
# Extract the top-level test directory (e.g., tests/Aspire.Hosting.Tests)
27+
rel_path="${file#$REPO_ROOT/}"
28+
echo "$rel_path" | cut -d'/' -f1-2
29+
done \
30+
| sort -u || true)
31+
32+
# Generate the MSBuild props file
33+
cat > "$OUTPUT_FILE" << 'EOF'
34+
<Project>
35+
<ItemGroup>
36+
EOF
37+
38+
for project_dir in $PROJECTS; do
39+
# Find the .csproj file in the directory
40+
csproj=$(find "$REPO_ROOT/$project_dir" -maxdepth 1 -name "*.csproj" 2>/dev/null | head -1)
41+
if [[ -n "$csproj" ]]; then
42+
rel_csproj="${csproj#$REPO_ROOT/}"
43+
echo " <OverrideProjectToBuild Include=\"\$(RepoRoot)$rel_csproj\" />" >> "$OUTPUT_FILE"
44+
fi
45+
done
46+
47+
cat >> "$OUTPUT_FILE" << 'EOF'
48+
</ItemGroup>
49+
</Project>
50+
EOF
51+
52+
echo "Generated $OUTPUT_FILE"
53+
cat "$OUTPUT_FILE"

0 commit comments

Comments
 (0)