-
Notifications
You must be signed in to change notification settings - Fork 20
228 lines (191 loc) · 8.3 KB
/
build.yml
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Scheduled Build
on:
schedule:
- cron: '0 4 * * *'
workflow_dispatch:
# push:
# branches: [ "master" ]
# pull_request:
# branches: [ "master" ]
env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: .
# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Release
permissions:
contents: write
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'true'
- name: Check Existing Release
id: check_release
uses: actions/github-script@v6
with:
script: |
const releaseTag = "nightly";
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: releaseTag,
});
core.setOutput("release_exists", true);
core.setOutput("release_id", release.data.id);
core.setOutput("upload_url", release.data.upload_url);
} catch (error) {
if (error.status === 404) {
core.setOutput("release_exists", false);
} else {
throw error;
}
}
- name: Create Nightly Release (if not exists)
id: create_release
if: steps.check_release.outputs.release_exists == 'false'
uses: actions/github-script@v6
with:
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "nightly",
name: "Nightly Builds",
body: "This is an automated nightly build release.",
draft: false,
prerelease: true,
});
core.setOutput("release_id", release.data.id);
core.setOutput("upload_url", release.data.upload_url);
- name: Extract OptiScaler Version
id: get_version
working-directory: ${{ github.workspace }}
shell: powershell
run: |
# Ensure the file exists before proceeding
$resourceFile = ".\OptiScaler\resource.h"
if (-Not (Test-Path $resourceFile)) {
Write-Error "File not found: $resourceFile"
exit 1
}
# Helper function to extract the first matching line for a version component
function Get-Version-Component {
param (
[string]$pattern,
[string]$replacement
)
# Use Select-String and take only the first match
$line = Get-Content $resourceFile | Select-String -Pattern $pattern | Select-Object -First 1
if ($line) {
return ($line.Line -replace $replacement).Trim()
} else {
Write-Error "Pattern not found: $pattern"
exit 1
}
}
# Extract version components (only the first match for each pattern)
$majorVersion = Get-Version-Component 'VER_MAJOR_VERSION' '#define VER_MAJOR_VERSION\s+'
$minorVersion = Get-Version-Component 'VER_MINOR_VERSION' '#define VER_MINOR_VERSION\s+'
$hotfixVersion = Get-Version-Component 'VER_HOTFIX_VERSION' '#define VER_HOTFIX_VERSION\s+'
$buildVersion = Get-Version-Component 'VER_BUILD_NUMBER' '#define VER_BUILD_NUMBER\s+'
# Merge into a single version string
$version = "v$majorVersion.$minorVersion.$hotfixVersion-pre$buildVersion"
# Get the current date in a specific format (e.g., YYYYMMDD)
$date = Get-Date -Format "yyyyMMdd"
# Construct the output filename with version and date
$outputFileName = "OptiScaler_${version}_${date}"
# Output the generated filename
Write-Output "Generated Filename: $outputFileName"
# Write outputs to GITHUB_OUTPUT
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"filename=$outputFileName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
continue-on-error: false
- name: Debug Outputs
run: |
echo "Version: ${{ steps.get_version.outputs.version }}"
echo "Filename: ${{ steps.get_version.outputs.filename }}"
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} /verbosity:minimal
- name: Compress the artifact
run: |
$zipName = "${{ steps.get_version.outputs.filename }}.7z"
7z a ${{ github.workspace }}\$zipName ${{ github.workspace }}\x64\Release\a\*.*
continue-on-error: false
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.get_version.outputs.filename }}
path: ${{ github.workspace }}\${{ steps.get_version.outputs.filename }}.7z
compression-level: 0
if-no-files-found: error
- name: Remove Previous Artifacts
if: steps.check_release.outputs.release_exists == 'true'
uses: actions/github-script@v6
with:
script: |
const releaseId = ${{ steps.check_release.outputs.release_id }};
const assets = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
});
for (const asset of assets.data) {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id,
});
console.log(`Deleted asset: ${asset.name}`);
}
- name: Upload Artifact to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.check_release.outputs.release_exists == 'true' && steps.check_release.outputs.upload_url || steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}\${{ steps.get_version.outputs.filename }}.7z
asset_name: ${{ steps.get_version.outputs.filename }}.7z
asset_content_type: application/x-7z-compressed
- name: Get Commit Messages From Last Day and Update the Release
id: commit_messages
working-directory: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: powershell
run: |
Write-Output "Fetching commits from the last 24 hours..."
# Get commit messages excluding .yml file commits
$commits = git log --since="1 day ago" --pretty=format:"%h %s (%an)" --abbrev-commit --grep=".yml" --invert-grep --no-merges --first-parent
$commits = $commits -split "`n"
# If no commits are found, cancel the workflow
if (-not $commits) {
Write-Output "No relevant commits in the last 24 hours. Cancelling workflow."
$ReleaseTag = "nightly"
Write-Output "Updating existing release: $ReleaseTag"
gh release edit $ReleaseTag --notes "### Changes in the Last 24 Hours`n`nNo changes..."
}
else {
# Join commits into a newline-separated string
$formattedCommits = $commits -join "`n"
Write-Output "Commits: $formattedCommits`n"
# Generate release notes
$releaseNotes = "### Changes in the Last 24 Hours`n`n$formattedCommits"
$ReleaseTag = "nightly"
Write-Output "Updating existing release: $ReleaseTag"
gh release edit $ReleaseTag --notes "$ReleaseNotes"
}
continue-on-error: false