-
Notifications
You must be signed in to change notification settings - Fork 159
102 lines (96 loc) · 3.52 KB
/
build-code-snippets.yml
File metadata and controls
102 lines (96 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Build WinForms Solutions
on:
push:
paths:
- '**/*.md'
- 'snippets/**'
pull_request:
paths:
- '**/*.md'
- 'snippets/**'
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect snippet or folder changes
id: snippet_check
shell: pwsh
run: |
git fetch --no-tags --prune --depth=0 origin
# Determine comparison base (works for push + PR)
if ("${{ github.event_name }}" -eq "pull_request") {
$base = "${{ github.event.pull_request.base.sha }}"
} else {
$base = "${{ github.event.before }}"
}
Write-Host "Comparing against $base"
$changedFiles = git diff --name-only $base HEAD
if (-not $changedFiles) {
echo "should_build=false" >> $env:GITHUB_OUTPUT
exit 0
}
$shouldBuild = $false
foreach ($file in $changedFiles) {
Write-Host "Changed: $file"
# CONDITION 1:
# Any change inside /snippets folder
if ($file -like "snippets/*") {
Write-Host "Change inside snippets folder detected."
$shouldBuild = $true
break
}
# CONDITION 2:
# .md file with snippet tag added/modified
if ($file -like "*.md") {
$diff = git diff $base HEAD -- $file
if ($diff -match "<snippet") {
Write-Host "Snippet tag change detected in markdown."
$shouldBuild = $true
break
}
}
}
echo "should_build=$shouldBuild" >> $env:GITHUB_OUTPUT
- name: Setup .NET 10
if: steps.snippet_check.outputs.should_build == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Add Telerik NuGet source
if: steps.snippet_check.outputs.should_build == 'true'
shell: pwsh
run: |
dotnet nuget add source "https://nuget.telerik.com/v3/index.json" --name "Telerik NuGet Server" --username "api-key" --password $env:TELERIK_API_KEY --store-password-in-clear-text
env:
TELERIK_API_KEY: ${{ secrets.TELERIK_API_KEY }}
- name: Debug Telerik NuGet
if: steps.snippet_check.outputs.should_build == 'true'
shell: pwsh
run: |
Write-Host "TELERIK_API_KEY length: $($env:TELERIK_API_KEY.Length)"
dotnet nuget list source
- name: Restore & Build all solutions
if: steps.snippet_check.outputs.should_build == 'true'
shell: pwsh
run: |
# Find both .sln and .slnx files
$solutions = Get-ChildItem "./snippets" -Recurse -Include *.sln,*.slnx -File
if (-not $solutions) {
Write-Error "No solution files (.sln or .slnx) found!"
exit 1
}
foreach ($sln in $solutions) {
Write-Host ""
Write-Host "=============================="
Write-Host "Building $($sln.FullName)"
Write-Host "=============================="
dotnet restore "$($sln.FullName)"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
dotnet build "$($sln.FullName)" `
--configuration Release `
--no-restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}