Skip to content

Commit 1dc4770

Browse files
committed
Building only changed components.
1 parent f8e015d commit 1dc4770

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ jobs:
109109
uses: actions/checkout@v4
110110
with:
111111
submodules: recursive
112+
fetch-depth: 0
112113

113114
# Restore Tools from Manifest list in the Repository
114115
- name: Restore dotnet tools
@@ -132,10 +133,28 @@ jobs:
132133
with:
133134
vs-version: '[17.9,)'
134135

136+
# Get changed components
137+
- name: Get changed components
138+
run: |
139+
git fetch origin main
140+
git diff --name-only origin/main...${{ github.sha }} -- components/ > ${{ github.workspace }}/changed-files.txt
141+
$otherChanges = git diff --name-only origin/main...${{ github.sha }} | Select-String -NotMatch '^components/'
142+
if (-not $otherChanges) {
143+
$files = Get-Content "${{ github.workspace }}/changed-files.txt"
144+
$names = $files | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
145+
$uniqueNames = $names | Sort-Object -Unique
146+
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
147+
$changedComponentsList = $quotedNames -join ','
148+
echo "CHANGED_COMPONENTS_LIST=$changedComponentsList" >> $env:GITHUB_ENV
149+
}
150+
else {
151+
echo "CHANGED_COMPONENTS_LIST='all'" >> $env:GITHUB_ENV
152+
}
153+
135154
# Generate full solution with all projects (sample gallery heads, components, tests)
136155
- name: Generate solution with ${{ matrix.multitarget }} gallery, components and tests
137156
working-directory: ./
138-
run: powershell -version 5.1 -command "./tooling/GenerateAllSolution.ps1 -MultiTargets ${{ matrix.multitarget }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && ' -UseDiagnostics' || '' }} -WinUIMajorVersion ${{ matrix.winui }}" -ErrorAction Stop
157+
run: powershell -version 5.1 -command "./tooling/GenerateAllSolution.ps1 -MultiTargets ${{ matrix.multitarget }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && ' -UseDiagnostics' || '' }} -Components ${{ env.CHANGED_COMPONENTS_LIST }} -WinUIMajorVersion ${{ matrix.winui }}" -ErrorAction Stop
139158

140159
# Build solution
141160
- name: MSBuild (With diagnostics)
@@ -233,6 +252,7 @@ jobs:
233252
uses: actions/checkout@v4
234253
with:
235254
submodules: recursive
255+
fetch-depth: 0
236256

237257
- name: Format Date/Time of Commit for Package Version
238258
run: |
@@ -257,9 +277,27 @@ jobs:
257277
with:
258278
vs-version: '[17.9,)'
259279

280+
# Get changed components
281+
- name: Get changed components
282+
run: |
283+
git fetch origin main
284+
git diff --name-only origin/main...${{ github.sha }} -- components/ > ${{ github.workspace }}/changed-files.txt
285+
$otherChanges = git diff --name-only origin/main...${{ github.sha }} | Select-String -NotMatch '^components/'
286+
if (-not $otherChanges) {
287+
$files = Get-Content "${{ github.workspace }}/changed-files.txt"
288+
$names = $files | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
289+
$uniqueNames = $names | Sort-Object -Unique
290+
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
291+
$changedComponentsList = $quotedNames -join ','
292+
echo "CHANGED_COMPONENTS_LIST=$changedComponentsList" >> $env:GITHUB_ENV
293+
}
294+
else {
295+
echo "CHANGED_COMPONENTS_LIST='all'" >> $env:GITHUB_ENV
296+
}
297+
260298
# Build and pack component nupkg
261299
- name: Build and pack component packages
262-
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release
300+
run: ./tooling/Build-Toolkit-Components.ps1 -MultiTargets all -Components ${{ env.CHANGED_COMPONENTS_LIST }} -WinUIMajorVersion ${{ matrix.winui }} -DateForVersion ${{ env.VERSION_DATE }} ${{ env.VERSION_PROPERTY != '' && format('-PreviewVersion "{0}"', env.VERSION_PROPERTY) || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-EnableBinlogs' || '' }} ${{ env.ENABLE_DIAGNOSTICS == 'true' && '-Verbose' || '' }} -BinlogOutput ./ -NupkgOutput ./ -Release
263301

264302
- name: Validate package names
265303
if: ${{ env.VERSION_PROPERTY != '' }}

0 commit comments

Comments
 (0)