forked from daiplusplus/codealignment
-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (171 loc) · 7.56 KB
/
Copy pathbuild.yaml
File metadata and controls
201 lines (171 loc) · 7.56 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Build CodeAlignment
on:
# push:
# branches: [ release, main, master ]
# tags: [ 'v*' ]
# pull_request:
# branches: [ release, main, master ]
workflow_dispatch:
inputs:
manual_tag:
description: 'Tag name for the release (for example: v14.1.0). If left blank it will be: manual-build'
required: false
default: 'manual-build'
permissions:
contents: write
jobs:
build_windows:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
build_configuration: [ Release ]
# If build Any CPU, build the entire solution (including VSIX)
# If building x64, force to build ONLY the Notepad++ plugin
build_platform: [ "x64" ] # "Any CPU",
toolset: [ v143 ]
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup NuGet
uses: nuget/setup-nuget@v2
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v3
- name: Restore NuGet Packages
run: |
nuget restore CodeAlignment.VisualStudio\packages.config -PackagesDirectory packages
if (Test-Path "Test\CodeAlignment.Common.Test\packages.config") {
nuget restore Test\CodeAlignment.Common.Test\packages.config -PackagesDirectory packages
}
msbuild code-alignment.sln /t:Restore
- name: Update Assembly Versions
shell: pwsh
run: |
$buildVersion = "14.1.${{ github.run_number }}.0"
Write-Output "Target build version: $buildVersion"
function Safe-Replace($filePath, $pattern, $replacement) {
if (Test-Path $filePath) {
$content = Get-Content $filePath | Foreach-Object { $_ -replace $pattern, $replacement }
$content | Set-Content $filePath -Encoding UTF8
}
}
$assemblyFiles = @(
"./CodeAlignment.Common/Properties/AssemblyInfo.cs",
"./CodeAlignment.Common.WinForms/Properties/AssemblyInfo.cs",
"./CodeAlignment.VisualStudio/Properties/AssemblyInfo.cs",
"./CodeAlignment.Npp/Properties/AssemblyInfo.cs",
"./Test/CodeAlignment.Common.Test/Properties/AssemblyInfo.cs"
)
foreach ($file in $assemblyFiles) {
Safe-Replace $file "AssemblyVersion\s*\([^\)]+\)" "AssemblyVersion(`"$buildVersion`")"
Safe-Replace $file "AssemblyFileVersion\s*\([^\)]+\)" "AssemblyFileVersion(`"$buildVersion`")"
}
Safe-Replace "./CodeAlignment.VisualStudio/CodeAlignmentPackage.cs" `
"\[InstalledProductRegistration\(`"#110`", `"#112`", `"[^`"]+`", IconResourceID = 400\)\]" `
"[InstalledProductRegistration(`"#110`", `"#112`", `"$buildVersion`", IconResourceID = 400)]"
Safe-Replace "./CodeAlignment.VisualStudio/source.extension.vsixmanifest" `
"Id=`"2adcbb11-89c4-451e-97f2-14049154ccad`"\s+Version=`"[^`"]+`"" `
"Id=`"2adcbb11-89c4-451e-97f2-14049154ccad`" Version=`"$buildVersion`""
echo "BUILD_VERSION=$buildVersion" >> $env:GITHUB_ENV
- name: Run MSBuild
run: |
if ("${{ matrix.build_platform }}" -eq "Any CPU") {
msbuild code-alignment.sln /m /p:configuration="${{ matrix.build_configuration }}" /p:platform="${{ matrix.build_platform }}" /verbosity:minimal
} else {
echo "Build x64: We compile only the plugin from the solution file..."
msbuild code-alignment.sln /t:CodeAlignment_Npp /m /p:configuration="${{ matrix.build_configuration }}" /p:platform="${{ matrix.build_platform }}" /verbosity:minimal
}
- name: Prepare and Pack Artifacts
shell: pwsh
run: |
. .\buildhelpers.ps1
$env:CONFIGURATION = "${{ matrix.build_configuration }}"
$isTag = "${{ github.ref_type }}" -eq "tag"
$isManual = "${{ github.event_name }}" -eq "workflow_dispatch"
$isReleaseBranch = "${{ github.ref_name }}" -eq "release"
$tagName = "manual-build"
if ($isTag) { $tagName = "${{ github.ref_name }}" }
elseif ($isManual) {
$inputTag = "${{ github.event.inputs.manual_tag }}".Trim()
$tagName = if ($inputTag) { $inputTag } else { "manual-build" }
}
$env:APPVEYOR_REPO_TAG_NAME = $tagName
function Push-AppveyorArtifact ($path, $FileName) {
Copy-Item $path -Destination "$origin/" -Force
}
$is64 = "${{ matrix.build_platform }}" -eq "x64"
if (Test-Path "CodeAlignment.Npp") {
CollectNpp $is64
$zipSuffix = if ($is64) { "x64.zip" } else { "x86.zip" }
$expectedZipName = "CodeAlignmentNpp_$($tagName)_$zipSuffix"
echo "ZIP_FILE_NAME=$expectedZipName" >> $env:GITHUB_ENV
echo "HAS_ZIP=true" >> $env:GITHUB_ENV
} else {
echo "HAS_ZIP=false" >> $env:GITHUB_ENV
}
if ("${{ matrix.build_platform }}" -eq "Any CPU") {
$vsixSrc = "CodeAlignment.VisualStudio\bin\$env:CONFIGURATION\CodeAlignment.vsix"
if (Test-Path $vsixSrc) {
$platformClean = "${{ matrix.build_platform }}".Replace(" ", "_")
$vsixDest = "CodeAlignment_$($tagName)_$platformClean.vsix"
Copy-Item $vsixSrc -Destination $vsixDest -Force
echo "VSIX_FILE=$vsixDest" >> $env:GITHUB_ENV
echo "HAS_VSIX=true" >> $env:GITHUB_ENV
} else {
echo "HAS_VSIX=false" >> $env:GITHUB_ENV
}
} else {
echo "HAS_VSIX=false" >> $env:GITHUB_ENV
}
echo "RELEASE_TAG=$tagName" >> $env:GITHUB_ENV
- name: Upload VSIX Artifact
if: env.HAS_VSIX == 'true'
uses: actions/upload-artifact@v4
with:
name: CodeAlignment-VSIX-${{ matrix.build_platform }}
path: ${{ env.VSIX_FILE }}
retention-days: 5
- name: Upload Zip Artifact
if: env.HAS_ZIP == 'true'
uses: actions/upload-artifact@v4
with:
name: CodeAlignment-Plugin-Zip-${{ matrix.build_platform }}
path: ${{ env.ZIP_FILE_NAME }}
retention-days: 5
publish:
needs: build_windows
if: github.ref_type == 'tag' || github.ref_name == 'release' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
pattern: CodeAlignment-*
merge-multiple: true
- name: Set Release Tag
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "RELEASE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
INPUT_TAG=$(echo "${{ github.event.inputs.manual_tag }}" | xargs)
if [[ -n "$INPUT_TAG" ]]; then
echo "RELEASE_TAG=$INPUT_TAG" >> $GITHUB_ENV
else
echo "RELEASE_TAG=manual-build" >> $GITHUB_ENV
fi
else
echo "RELEASE_TAG=release-branch-build" >> $GITHUB_ENV
fi
- name: GitHub Release
uses: softprops/action-gh-release@v3.0.2
with:
tag_name: ${{ env.RELEASE_TAG }}
files: |
*.zip
*.vsix
prerelease: ${{ env.RELEASE_TAG == 'manual-build' }}
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}