Skip to content

Commit 13fdb49

Browse files
committed
🔨 chore: add release workflow and script for packaging artifacts
1 parent 1726bef commit 13fdb49

4 files changed

Lines changed: 146 additions & 1 deletion

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: Semantic version bump for the release
8+
required: true
9+
default: patch
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
runtime:
16+
description: Windows release target(s)
17+
required: true
18+
default: win-x86
19+
type: choice
20+
options:
21+
- both
22+
- win-x64
23+
- win-x86
24+
25+
permissions:
26+
contents: write
27+
pull-requests: write
28+
29+
jobs:
30+
release:
31+
runs-on: windows-latest
32+
33+
steps:
34+
- name: Check out source
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Set up .NET 8
40+
uses: actions/setup-dotnet@v4
41+
with:
42+
dotnet-version: 8.0.x
43+
44+
- name: Install .NET Framework 4.5.2 Developer Pack
45+
shell: pwsh
46+
run: |
47+
$installer = Join-Path $env:TEMP 'netfx452-devpack.exe'
48+
49+
Invoke-WebRequest `
50+
-Uri 'https://go.microsoft.com/fwlink/?clcid=0x409&linkid=397673' `
51+
-OutFile $installer
52+
53+
$process = Start-Process `
54+
-FilePath $installer `
55+
-ArgumentList '/q', '/norestart' `
56+
-Wait `
57+
-PassThru
58+
59+
if ($process.ExitCode -notin 0, 3010) {
60+
throw "Developer Pack installation failed: $($process.ExitCode)"
61+
}
62+
63+
- name: Create GitHub release
64+
uses: hsayed21/release-action@v1
65+
with:
66+
version: ${{ inputs.version }}
67+
initial-version: '1.0.2'
68+
generate-changelog: true
69+
release-command-shell: pwsh
70+
release-command: |
71+
if ('${{ inputs.runtime }}' -eq 'both') {
72+
./scripts/New-ReleaseZip.ps1 -Version $env:RELEASE_VERSION -Runtime win-x64
73+
./scripts/New-ReleaseZip.ps1 -Version $env:RELEASE_VERSION -Runtime win-x86
74+
}
75+
else {
76+
./scripts/New-ReleaseZip.ps1 -Version $env:RELEASE_VERSION -Runtime "${{ inputs.runtime }}"
77+
}
78+
files-pattern: artifacts/*.zip
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,5 @@ MigrationBackup/
360360
.ionide/
361361

362362
# Fody - auto-generated XML schema
363-
FodyWeavers.xsd
363+
FodyWeavers.xsd
364+
.vscode/

‎global.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.422",
4+
"rollForward": "latestFeature",
5+
"allowPrerelease": false
6+
}
7+
}

‎scripts/New-ReleaseZip.ps1‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[CmdletBinding()]
2+
param(
3+
[ValidatePattern('^\d+\.\d+\.\d+([-.][0-9A-Za-z.-]+)?$')]
4+
[string]$Version = '1.0.0',
5+
6+
[ValidateSet('win-x64', 'win-x86')]
7+
[string]$Runtime = 'win-x64'
8+
)
9+
10+
$ErrorActionPreference = 'Stop'
11+
12+
$projectRoot = Split-Path -Parent $PSScriptRoot
13+
$projectFile = Join-Path $projectRoot 'SQLBakVersion.csproj'
14+
$artifactsDirectory = Join-Path $projectRoot 'artifacts'
15+
$releaseName = "SQLBakVersion"
16+
$publishDirectory = Join-Path $artifactsDirectory $releaseName
17+
$zipPath = Join-Path $artifactsDirectory "$releaseName.zip"
18+
19+
if (-not (Test-Path -LiteralPath $projectFile)) {
20+
throw "Project file was not found: $projectFile"
21+
}
22+
23+
New-Item -ItemType Directory -Path $artifactsDirectory -Force | Out-Null
24+
25+
if (Test-Path -LiteralPath $publishDirectory) {
26+
Remove-Item -LiteralPath $publishDirectory -Recurse -Force
27+
}
28+
if (Test-Path -LiteralPath $zipPath) {
29+
Remove-Item -LiteralPath $zipPath -Force
30+
}
31+
32+
Write-Host "Restoring packages for $Runtime..."
33+
dotnet restore $projectFile --runtime $Runtime
34+
35+
if ($LASTEXITCODE -ne 0) {
36+
throw "dotnet restore failed with exit code $LASTEXITCODE."
37+
}
38+
39+
Write-Host "Publishing $releaseName..."
40+
dotnet publish $projectFile `
41+
--configuration Release `
42+
--runtime $Runtime `
43+
--self-contained true `
44+
--no-restore `
45+
-p:PublishSingleFile=true `
46+
-p:IncludeNativeLibrariesForSelfExtract=true `
47+
-p:Version=$Version `
48+
--output $publishDirectory
49+
50+
if ($LASTEXITCODE -ne 0) {
51+
throw "dotnet publish failed with exit code $LASTEXITCODE."
52+
}
53+
54+
Copy-Item -LiteralPath (Join-Path $projectRoot 'README.md') -Destination $publishDirectory
55+
Compress-Archive -Path (Join-Path $publishDirectory '*') -DestinationPath $zipPath -CompressionLevel Optimal
56+
57+
Write-Host "Release ZIP created: $zipPath" -ForegroundColor Green

0 commit comments

Comments
 (0)