Repository navigation
142 lines (126 loc) · 5.35 KB
/
Copy pathci.yml
File metadata and controls
142 lines (126 loc) · 5.35 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: CI
on:
push:
branches: [main, develop, 'ge*']
tags: ['v*']
pull_request:
branches: [main, develop, 'ge*']
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Determine version
id: version
shell: pwsh
run: |
if ($env:GITHUB_REF -match '^refs/tags/v(.+)$') {
$ver = $Matches[1]
echo "package_version=$ver" >> $env:GITHUB_OUTPUT
echo "version_args=-p:Version=$ver" >> $env:GITHUB_OUTPUT
} else {
[xml]$proj = Get-Content src/GitExtensions.AITools/GitExtensions.AITools.csproj
$prefix = $proj.Project.PropertyGroup[0].VersionPrefix
$suffix = "ci.${{ github.run_number }}"
echo "package_version=$prefix-$suffix" >> $env:GITHUB_OUTPUT
echo "version_args=-p:VersionSuffix=$suffix" >> $env:GITHUB_OUTPUT
}
- name: Extract release notes
id: notes
shell: pwsh
run: |
$changelog = Get-Content CHANGELOG.md -Raw
# For tag builds, find the [version] section; otherwise use [Unreleased]
$heading = if ($env:GITHUB_REF -match '^refs/tags/v') { '${{ steps.version.outputs.package_version }}' } else { 'Unreleased' }
if ($changelog -match "(?ms)^## \[$heading\].*?\n(.*?)(?=\n## \[|$)") {
$notes = $Matches[1].Trim()
} else {
$notes = 'See https://github.com/JBTremblay/gitextensions.aitools/releases'
}
# Escape for MSBuild property
$notes = $notes -replace '%','%25' -replace ';','%3B' -replace '\r\n|\r|\n','%0A'
echo "notes=$notes" >> $env:GITHUB_OUTPUT
- name: Build
run: dotnet build -c Release ${{ steps.version.outputs.version_args }}
- name: Test cancellation
shell: pwsh
run: |
dotnet build tests/GitExtensions.AITools.Tests -c Release ${{ steps.version.outputs.version_args }}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
dotnet run --project tests/GitExtensions.AITools.Tests -c Release --no-build
- name: Pack
run: >-
dotnet pack -c Release
${{ steps.version.outputs.version_args }}
-p:PackageReleaseNotes="${{ steps.notes.outputs.notes }}"
--no-build
- name: Validate package contents
shell: pwsh
run: |
$nupkg = Get-ChildItem src/GitExtensions.AITools/bin/Release/*.nupkg | Select-Object -First 1
Write-Host "Package: $($nupkg.Name)"
$archive = [System.IO.Compression.ZipFile]::OpenRead($nupkg.FullName)
try {
$entries = $archive.Entries | Select-Object -ExpandProperty FullName
$entries | ForEach-Object { Write-Host " $_" }
$required = @('lib/GitExtensions.AITools.dll', 'lib/Translation/French.xlf', 'icon-128x128.png', 'docs/README.md')
foreach ($file in $required) {
if ($file -notin $entries) {
throw "Missing required file: $file"
}
}
$reader = [System.IO.StreamReader]::new($archive.GetEntry('GitExtensions.AITools.nuspec').Open())
try { [xml]$nuspec = $reader.ReadToEnd() } finally { $reader.Dispose() }
$dependency = $nuspec.package.metadata.dependencies.dependency
if ($dependency.id -ne 'GitExtensions.Extensibility' -or $dependency.version -ne '[7.0.0, 8.0.0)') {
throw 'The package must declare compatibility with GitExtensions.Extensibility 7.x.'
}
$dlls = @($entries | Where-Object { $_ -like '*.dll' })
if ($dlls.Count -ne 1 -or $dlls[0] -ne 'lib/GitExtensions.AITools.dll') {
throw 'The package must not bundle Git Extensions host assemblies.'
}
} finally {
$archive.Dispose()
}
Write-Host "Package validation passed."
- name: Upload NuGet package
uses: actions/upload-artifact@v4
with:
name: nupkg
path: src/GitExtensions.AITools/bin/Release/*.nupkg
publish:
runs-on: windows-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: nupkg
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Push to NuGet
run: dotnet nuget push *.nupkg -k ${{ secrets.NUGET_PUSH_TOKEN }} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Extract release notes from CHANGELOG
id: notes
shell: pwsh
run: |
$tag = $env:GITHUB_REF -replace '^refs/tags/'
$version = $tag -replace '^v'
$changelog = Get-Content CHANGELOG.md -Raw
if ($changelog -match "(?ms)^## \[$version\].*?\n(.*?)(?=\n## \[|$)") {
$Matches[1].Trim() | Set-Content release-notes.md
} else {
"Release $tag" | Set-Content release-notes.md
}
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create ${{ github.ref_name }} --title "${{ github.ref_name }}" --notes-file release-notes.md