Skip to content

Commit 973b04b

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

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

.github/workflows/build.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,28 @@ jobs:
132132
with:
133133
vs-version: '[17.9,)'
134134

135+
# Get changed components
136+
- name: Get changed components
137+
run: |
138+
git fetch origin main
139+
git diff --name-only origin/main...${{ github.sha }} -- components/ > ${{ github.workspace }}/changed-files.txt
140+
$otherChanges = git diff --name-only origin/main...${{ github.sha }} | Select-String -NotMatch '^components/'
141+
if (-not $otherChanges) {
142+
$files = Get-Content "${{ github.workspace }}/changed-files.txt"
143+
$names = $files | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
144+
$uniqueNames = $names | Sort-Object -Unique
145+
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
146+
$changedComponentsList = $quotedNames -join ','
147+
echo "CHANGED_COMPONENTS_LIST=$changedComponentsList" >> $env:GITHUB_ENV
148+
}
149+
else {
150+
echo "CHANGED_COMPONENTS_LIST='all'" >> $env:GITHUB_ENV
151+
}
152+
135153
# Generate full solution with all projects (sample gallery heads, components, tests)
136154
- name: Generate solution with ${{ matrix.multitarget }} gallery, components and tests
137155
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
156+
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
139157

140158
# Build solution
141159
- name: MSBuild (With diagnostics)
@@ -257,9 +275,27 @@ jobs:
257275
with:
258276
vs-version: '[17.9,)'
259277

278+
# Get changed components
279+
- name: Get changed components
280+
run: |
281+
git fetch origin main
282+
git diff --name-only origin/main...${{ github.sha }} -- components/ > ${{ github.workspace }}/changed-files.txt
283+
$otherChanges = git diff --name-only origin/main...${{ github.sha }} | Select-String -NotMatch '^components/'
284+
if (-not $otherChanges) {
285+
$files = Get-Content "${{ github.workspace }}/changed-files.txt"
286+
$names = $files | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
287+
$uniqueNames = $names | Sort-Object -Unique
288+
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
289+
$changedComponentsList = $quotedNames -join ','
290+
echo "CHANGED_COMPONENTS_LIST=$changedComponentsList" >> $env:GITHUB_ENV
291+
}
292+
else {
293+
echo "CHANGED_COMPONENTS_LIST='all'" >> $env:GITHUB_ENV
294+
}
295+
260296
# Build and pack component nupkg
261297
- 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
298+
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
263299

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

0 commit comments

Comments
 (0)