Skip to content

Commit 45abb7e

Browse files
committed
Added automatic build
1 parent 53b17c3 commit 45abb7e

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

.github/workflows/release.yml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# GitHub Actions workflow for building and releasing a DLL
2+
name: Build and Release DLL
3+
4+
on:
5+
push:
6+
branches:
7+
- 'stable' # Trigger on push to any branch
8+
9+
permissions:
10+
contents: write # Grant write permissions to contents
11+
12+
13+
env:
14+
SLN_NAME: TSafe.sln # Solution file name
15+
DLL_NAME: TSafe.dll # DLL file name
16+
LIBRARY_PATH: ./TSafe/bin/Release/net48/TLibrary.dll # Path to the library DLL
17+
DLL_PATH: ./TSafe/bin/Release/net48/TSafe.dll # Path to the main DLL
18+
COMMIT_EXTRA_DESC: |
19+
Libraries can be found [here](https://github.com/TavstalDev/TLibrary/releases/tag/VERSION_PLACEHOLDER).
20+
21+
jobs:
22+
# Job 1.
23+
build:
24+
runs-on: windows-latest # Use the latest Windows runner
25+
steps:
26+
# Step 1: Checkout the code
27+
- name: Checkout Code
28+
uses: actions/checkout@v3
29+
30+
# Step 2: Setup MSBuild for building .NET Framework
31+
- name: Setup MSBuild
32+
uses: microsoft/setup-msbuild@v1
33+
34+
# Step 3: Setup NuGet
35+
- name: Setup NuGet
36+
uses: nuget/setup-nuget@v1
37+
with:
38+
nuget-version: latest # Use the latest version of NuGet
39+
40+
# Step 4: Restore dependencies using NuGet
41+
- name: Restore Dependencies
42+
run: nuget restore ${{ env.SLN_NAME }}
43+
44+
# Step 5: Build the solution using MSBuild
45+
- name: Build Solution
46+
run: msbuild ${{ env.SLN_NAME }} /p:Configuration=Release
47+
48+
# Step 6: Extract DLL Version
49+
- name: Extract DLL Version
50+
id: extract_version
51+
run: |
52+
if (Test-Path ${{ env.DLL_PATH }}) {
53+
Write-Output "DLL found: ${{ env.DLL_PATH }}"
54+
$version = (Get-Item ${{ env.DLL_PATH }}).VersionInfo.FileVersion
55+
56+
if ($version) {
57+
Write-Output "Extracted version: $version"
58+
echo "Setting DLL_VERSION=$version in GITHUB_ENV"
59+
Add-Content -Path $env:GITHUB_ENV -Value "DLL_VERSION=$version"
60+
} else {
61+
Write-Output "FileVersion not found in the DLL metadata."
62+
exit 1
63+
}
64+
} else {
65+
Write-Output "DLL not found at path: $dllPath"
66+
exit 1
67+
}
68+
69+
if (Test-Path ${{ env.LIBRARY_PATH }}) {
70+
Write-Output "Library DLL found: ${{ env.LIBRARY_PATH }}"
71+
$libraryVersion = (Get-Item ${{ env.LIBRARY_PATH }}).VersionInfo.FileVersion
72+
73+
if ($libraryVersion) {
74+
Write-Output "Extracted library version: $libraryVersion"
75+
echo "Setting LIBRARY_VERSION=$libraryVersion in GITHUB_ENV"
76+
77+
$commitDesc="${{ env.COMMIT_EXTRA_DESC }}"
78+
echo "Debug 1: $commitDesc"
79+
# Replace the placeholder
80+
$updatedCommitDesc=$(echo "$commitDesc" | sed "s/VERSION_PLACEHOLDER/$libraryVersion/")
81+
echo "Debug 2: $updatedCommitDesc"
82+
echo "Debug 3: $COMMIT_EXTRA_DESC"
83+
Add-Content -Path $env:GITHUB_ENV -Value "COMMIT_EXTRA_DESC=$updatedCommitDesc"
84+
}
85+
}
86+
shell: powershell
87+
88+
# Step 7: Get the latest tag
89+
- name: Get latest tag
90+
id: get_latest_tag
91+
run: |
92+
try {
93+
git fetch --tags
94+
$latest_tag = git tag -l | sort -V | tail -n 1
95+
if (-not $latest_tag) {
96+
$latest_tag = "none"
97+
}
98+
} catch {
99+
$latest_tag = "none"
100+
}
101+
Write-Output "Latest tag: $latest_tag"
102+
Add-Content -Path $env:GITHUB_ENV -Value "LATEST_TAG=$latest_tag"
103+
# Force the step to exit with a success status (0)
104+
exit 0
105+
shell: powershell
106+
107+
# Step 8: Get commit logs since the latest tag
108+
- name: Get commit logs since the latest tag
109+
id: get_commits
110+
run: |
111+
# Fetch all history
112+
git fetch --unshallow
113+
114+
if ($env:LATEST_TAG -eq "none") {
115+
Write-Output "No previous tag found, listing all commits."
116+
$commits = git log HEAD --pretty=format:"- [%h](https://github.com/${{ github.repository }}/commit/%h) - %s"
117+
} else {
118+
Write-Output "Getting commits since tag: $env:LATEST_TAG"
119+
# Fetch commits since the latest tag, and format them properly
120+
$commits = @()
121+
git log "$env:LATEST_TAG..HEAD" --pretty=format:"- [%h](https://github.com/${{ github.repository }}/commit/%h) - %s" | ForEach-Object { $commits += "$_" }
122+
}
123+
124+
# Log the full output of the git log command
125+
Write-Output "Full commit log:"
126+
Write-Output $commits
127+
Write-Output "commits=$commits" >> $GITHUB_ENV
128+
$localCommit = $commits -join "`n"
129+
Add-Content -Path $env:GITHUB_ENV -Value @"
130+
COMMITS<<EOF
131+
$localCommit
132+
EOF
133+
"@
134+
exit 0
135+
136+
# Step 9: Create a GitHub release (or update an existing one)
137+
- name: Create GitHub Release
138+
id: create_release
139+
uses: actions/create-release@v1
140+
env:
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
with:
143+
tag_name: ${{ env.DLL_VERSION }} # Use the extracted DLL version
144+
release_name: Build ${{ env.DLL_VERSION }}
145+
draft: false
146+
prerelease: true
147+
body: |
148+
## Changelog
149+
${{ env.COMMIT_EXTRA_DESC }}
150+
Changes pushed to branch `${{ github.ref_name }}`
151+
${{ env.COMMITS}}
152+
153+
# Step 10: Upload the DLL to the release
154+
- name: Upload DLL to Release
155+
uses: actions/upload-release-asset@v1
156+
env:
157+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
with:
159+
upload_url: ${{ steps.create_release.outputs.upload_url }}
160+
asset_path: ${{ env.DLL_PATH }}
161+
asset_name: ${{ env.DLL_NAME }}
162+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)