forked from xesdoog/YLP
-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (223 loc) · 8.28 KB
/
build_cpp_release.yml
File metadata and controls
255 lines (223 loc) · 8.28 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
name: YLP Weekly
on:
schedule:
- cron: '0 4 * * 0'
workflow_dispatch:
jobs:
check_changes:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.changes.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
- id: changes
uses: actions/github-script@v7
with:
script: |
if (context.eventName === "workflow_dispatch") {
core.setOutput("has_changes", "true");
return;
}
const { owner, repo } = context.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
if (tags.data.length === 0) {
core.setOutput("has_changes", "true");
return;
}
const lastTag = tags.data[0].name;
const compare = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "HEAD"
});
core.setOutput(
"has_changes",
compare.data.total_commits > 0 ? "true" : "false"
);
build:
needs: check_changes
if: needs.check_changes.outputs.has_changes == 'true'
runs-on: windows-latest
name: Build YLP CPP
env:
BUILD_TYPE: Release
outputs:
full_sha: ${{ steps.var.outputs.full_sha }}
new_tag: ${{ steps.get_version.outputs.new_tag }}
ffi_tag: ${{ steps.get_version.outputs.ffi_tag }}
old_tag: ${{ steps.get_version.outputs.old_tag }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Get Version Number
id: get_version
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
let newTag;
let oldTag;
let ffiTag;
let latestTag = tags.data.length ? tags.data[0].name : "2.0.0.0";
const versionParts = latestTag.split('.').map(Number);
if (versionParts[0] < 2) {
versionParts[0] = 2;
versionParts[1] = 0;
versionParts[2] = 0;
versionParts[3] = 0;
} else if (versionParts[1] === 9 && versionParts[2] === 9 && versionParts[3] === 9) {
versionParts[0] += 1;
versionParts[1] = 0;
versionParts[2] = 0;
versionParts[3] = 0;
} else if (versionParts[2] === 9) {
versionParts[1] += 1;
versionParts[2] = 0;
versionParts[3] = 0;
} else if (versionParts[3] === 9) {
versionParts[2] += 1;
versionParts[3] = 0;
} else {
versionParts[3] += 1;
}
newTag = versionParts.join('.');
oldTag = latestTag;
ffiTag = newTag.replaceAll(".", ",");
core.setOutput("new_tag", newTag);
core.setOutput("ffi_tag", ffiTag);
core.setOutput("old_tag", oldTag);
- name: Update Version Resource
shell: pwsh
run: |
$versionNumber = "${{ steps.get_version.outputs.ffi_tag }}"
$versionString = "${{ steps.get_version.outputs.new_tag }}"
$commit = git rev-parse --short HEAD
$file = "./src/resources/version.rc"
$content = @"
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION $versionNumber
PRODUCTVERSION $versionNumber
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "github.com/xesdoog\0"
VALUE "FileDescription", "YLP\0"
VALUE "FileVersion", "$versionString"
VALUE "InternalName", "YLP\0"
VALUE "LegalCopyright", "Copyright (c) SAMURAI - 2025\0"
VALUE "OriginalFilename", "YLP.exe\0"
VALUE "ProductName", "YLP\0"
VALUE "ProductVersion", "$versionString"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
"@
Set-Content -Path $file -Value $content -Encoding UTF8
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Generate CMake Files
run: cmake -D CMAKE_BUILD_TYPE=Release -D OPTIMIZE=YES -S. -Bbuild -G Ninja
- name: Build x64 Executable
run: cmake --build ./build --config Release --target YLP
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: binary
path: build/YLP.exe
if-no-files-found: warn
- name: Generate Build Info
id: var
run: |
echo "full_sha=$(git rev-parse HEAD)" >> $env:GITHUB_OUTPUT
echo "short_sha=$(git rev-parse --short HEAD)" >> $env:GITHUB_OUTPUT
create_release:
runs-on: ubuntu-latest
name: Create Release
needs: build
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Generate Changelog
id: changelog
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const lastTag = "${{ needs.build.outputs.old_tag }}";
const { data: tagRefs } = await github.rest.git.getRef({ owner, repo, ref: `tags/${lastTag}` });
const tagSha = tagRefs.object.sha;
const { data: tagCommit } = await github.rest.repos.getCommit({ owner, repo, ref: tagSha });
const lastTagDate = new Date(tagCommit.commit.committer.date);
const { data: pulls } = await github.rest.pulls.list({
owner, repo, state: "closed", sort: "updated", direction: "asc", per_page: 100
});
let changelog = "";
const mergedPRs = pulls.filter(pr => pr.merged_at && new Date(pr.merged_at) > lastTagDate);
if (mergedPRs.length > 0) {
for (const pr of mergedPRs) {
changelog += `## PR #${pr.number}: ${pr.title}\n`;
const body = pr.body || "";
changelog += `${body.trim()}\n\n`;
}
} else {
const compared = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "main"
});
const commits = compared.data.commits;
for (const commit of commits) {
const msg = commit.commit.message;
const body = commit.commit.body;
if (msg.toLowerCase().startsWith("merge pull"))
continue;
changelog += `## ${msg}\n\n`;
if (body)
changelog += `${body}\n\n`;
}
}
core.setOutput("changelog", changelog);
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: binary
- name: Calculate SHA256
id: build_sha
run: |
sha256sum YLP.exe > sha256.checksum
echo "build_sha=$(cat sha256.checksum)" >> $GITHUB_OUTPUT
cat sha256.checksum
- name: Upload Release
uses: softprops/action-gh-release@v2
with:
name: YLP v${{ needs.build.outputs.new_tag }}
tag_name: ${{ needs.build.outputs.new_tag }}
body: |
>[!NOTE]
>**This automatic release was built by Github Actions**
>| [Link to build](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
>| ------------- |
### Build SHA256:
${{ steps.build_sha.outputs.build_sha }}
# Changelog
${{ steps.changelog.outputs.changelog }}
files: |
YLP.exe