Repository navigation
207 lines (171 loc) · 7.71 KB
/
Copy pathbuild.yml
File metadata and controls
207 lines (171 loc) · 7.71 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
202
203
204
205
206
207
name: Build AnotherMarkdown
on:
push:
branches: [release]
pull_request:
branches: []
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get last artifact version and increment
id: version
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$repo = "${{ github.repository }}"
$workflow = "${{ github.workflow }}"
$branch = "${{ github.ref_name }}"
Write-Host "Repository: $repo"
Write-Host "Branch: $branch"
$lastCommit = git log -1 --pretty=%B
Write-Host "Last commit message: $lastCommit"
$headers = @{
Authorization = "Bearer $env:GITHUB_TOKEN"
Accept = "application/vnd.github+json"
}
$url = "https://api.github.com/repos/$repo/actions/artifacts?per_page=20"
$response = Invoke-RestMethod -Uri $url -Headers $headers
write-host (ConvertTo-Json $response);
$artefacts = $response.artifacts |
Where-Object { $_.name -like "AnotherMarkdown-*" } |
Sort-Object created_at -Descending
$newVersion = "0.1";
foreach($entry in $artefacts) {
write-host "artefact: $($entry.name)"
if ("$($entry.name)" -match '\-(\d+)\.(\d+)(\.\d+)?(\.\d+)?\-') {
Write-Host "Last artifact created: $($entry.created_at) - $($entry.name)"
$major = [int]$matches[1];
$minor = [int]$matches[2];
$patch = 0;
if ($matches[3] -ne $null) {
$patch = [int] ($matches[3].Substring(1));
}
$revision = 0;
if ($matches[4] -ne $null) {
$revision = [int] ($matches[4].Substring(1));
}
if ($branch -eq "master") {
if ($lastCommit -imatch '^feat[\(\:]') {
$newVersion = "$major.$($minor + 1).0"
}
else {
$newVersion = "$major.$minor.$($patch + 1)"
}
}
else {
$newVersion = "$major.$minor.$patch.$($revision + 1)"
}
break;
}
}
Write-Host "New version: $newVersion"
$file = "AnotherMarkdown/Properties/AssemblyInfo.cs"
$content = Get-Content $file -Raw
$content = $content `
-replace 'AssemblyVersion\(".*?"\)', "AssemblyVersion(`"$newVersion`")" `
-replace 'AssemblyFileVersion\(".*?"\)', "AssemblyFileVersion(`"$newVersion`")"
$copyright = [regex]::Match($content, 'AssemblyCopyright\("(.*?)"\)');
$copyrightText = $copyright.Groups[1].Value;
$match = [regex]::Match($copyrightText, '^(.*\s)(20\d\d)$');
if ($match.Success -and (([int]::Parse($match.Groups[2].Value)) -lt [datetime]::UtcNow.Year)) {
$copyrightText += "-" + [datetime]::UtcNow.Year.ToString();
$content = $content.Replace($copyright.Groups[0].Value, 'AssemblyCopyright("' + $copyrightText + '")');
}
Set-Content $file $content -Encoding UTF8
"APP_VERSION=$newVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
- name: Restore NuGet packages
shell: pwsh
run: |
nuget restore AnotherMarkdown.sln
- name: Build x86
shell: pwsh
run: |
msbuild AnotherMarkdown.sln `
/target:Clean,Build `
/p:Configuration=Release `
/p:Platform=x86
- name: Build x64
shell: pwsh
run: |
msbuild AnotherMarkdown.sln `
/target:Clean,Build `
/p:Configuration=Release `
/p:Platform=x64
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
cache-dependency-path: PluginPack/yarn.lock
- name: Install dependencies
working-directory: PluginPack
run: yarn install --frozen-lockfile
- name: Build PluginPack
working-directory: PluginPack
run: yarn build:all
- name: Create release ZIPs
id: create-release
shell: pwsh
run: |
$branch = "${{ github.ref_name }}"
$prefix = ""
if ($branch -ne "master") {
$prefix = "dev-"
}
$version = "${{ steps.version.outputs.APP_VERSION }}"
function Make-ReleaseFolder($sourceDir, $targetPlatform) {
$name = "AnotherMarkdown-$($version)-$($prefix)$($targetPlatform)";
$targetDir = "Release/$name"
New-Item -ItemType Directory -Path "$targetDir" | Out-Null
New-Item -ItemType Directory -Path "$targetDir/lib" | Out-Null
New-Item -ItemType Directory -Path "$targetDir/lib/runtimes" | Out-Null
Copy-Item -Force -Recurse -Path "$sourceDir/*.dll" -Destination "$targetDir/lib"
Copy-Item -Force -Recurse -Path "$sourceDir/runtimes/win-$($targetPlatform)" -Destination "$targetDir/lib/runtimes/win-$($targetPlatform)"
Get-ChildItem "$targetDir/lib" -Recurse -Filter "AnotherMarkdown.*" | Move-Item -Destination "$targetDir" -Force
Copy-Item -Force -Recurse -Path "README.md","CHANGELOG.md","help","assets","License.txt" -Destination "$targetDir"
Copy-Item -Force -Recurse -Path "PluginPack/dist/js/*.js" -Destination "$targetDir/assets/markdown"
return $name;
}
$name = Make-ReleaseFolder "AnotherMarkdown\bin\Release" "x86"
"X86_NAME=$name" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
$name = Make-ReleaseFolder "AnotherMarkdown\bin\Release-x64" "x64"
"X64_NAME=$name" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Upload x86 release
uses: actions/upload-artifact@v4
with:
name: ${{ steps.create-release.outputs.X86_NAME }}
path: Release\${{ steps.create-release.outputs.X86_NAME }}
- name: Upload x64 release
uses: actions/upload-artifact@v4
with:
name: ${{ steps.create-release.outputs.X64_NAME }}
path: Release\${{ steps.create-release.outputs.X64_NAME }}
- name: Create ZIPs for release
if: github.ref_name == 'master' # <-- выполняется только на master
shell: pwsh
run: |
Compress-Archive -Path "Release\${{ steps.create-release.outputs.X86_NAME }}\*" -DestinationPath "Release\${{ steps.create-release.outputs.X86_NAME }}.zip" -Force
Compress-Archive -Path "Release\${{ steps.create-release.outputs.X64_NAME }}\*" -DestinationPath "Release\${{ steps.create-release.outputs.X64_NAME }}.zip" -Force
- name: Create GitHub Release (master only)
if: github.ref_name == 'master' # <-- выполняется только на master
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.APP_VERSION }}
name: NppAnotherMarkdown ${{ steps.version.outputs.APP_VERSION }}
draft: false
prerelease: false
files: |
Release/${{ steps.create-release.outputs.X86_NAME }}.zip
Release/${{ steps.create-release.outputs.X64_NAME }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}