-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (66 loc) · 2.96 KB
/
Copy pathrelease.yml
File metadata and controls
76 lines (66 loc) · 2.96 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
name: Release
on:
push:
tags:
- "v*"
jobs:
build-and-release:
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: "go.mod"
- name: Run tests
run: go test ./... -v
- name: Build executables
run: |
$VERSION = "${{ github.ref_name }}"
$COMMIT = "${{ github.sha }}"
$BUILD_DATE = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ")
$LDFLAGS = "-X github.com/smitstech/AzureAutoHibernate/internal/version.Version=$VERSION -X github.com/smitstech/AzureAutoHibernate/internal/version.GitCommit=$COMMIT -X github.com/smitstech/AzureAutoHibernate/internal/version.BuildDate=$BUILD_DATE"
go build -ldflags="$LDFLAGS" -o AzureAutoHibernate.exe ./cmd/autohibernate
go build -ldflags="-H=windowsgui $LDFLAGS" -o AzureAutoHibernate.Notifier.exe ./cmd/notifier
go build -ldflags="$LDFLAGS" -o AzureAutoHibernate.Updater.exe ./cmd/updater
- name: Package binaries
run: |
New-Item -ItemType Directory -Force -Path dist
Copy-Item AzureAutoHibernate.exe dist/
Copy-Item AzureAutoHibernate.Notifier.exe dist/
Copy-Item AzureAutoHibernate.Updater.exe dist/
Copy-Item config.json dist/
Compress-Archive -Path dist\* -DestinationPath AzureAutoHibernate-${{ github.ref_name }}-windows-amd64.zip
- name: Extract release notes from CHANGELOG
run: |
$changelog = Get-Content CHANGELOG.md -Raw
$version = "${{ github.ref_name }}"
# Remove 'v' prefix if present for matching
$versionNumber = $version -replace '^v', ''
# Try to extract the specific version section
$pattern = "(?s)## \[$versionNumber\][^\n]*\s*(.*?)\s*(?=---\s*##|\z)"
if ($changelog -match $pattern) {
$releaseNotes = $matches[1].Trim()
if ($releaseNotes -ne "" -and $releaseNotes -ne "- (nothing yet)") {
# Add header
$releaseNotes = "## What's Changed`n`n" + $releaseNotes
$releaseNotes | Out-File -FilePath release-notes.md -Encoding utf8
Write-Host "Release notes extracted successfully for $version"
Write-Host "---"
Write-Host $releaseNotes
Write-Host "---"
} else {
"No changes documented for this release." | Out-File -FilePath release-notes.md -Encoding utf8
}
} else {
Write-Host "Warning: Could not find version $versionNumber in CHANGELOG.md"
"Release $version" | Out-File -FilePath release-notes.md -Encoding utf8
}
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
files: AzureAutoHibernate-${{ github.ref_name }}-windows-amd64.zip
body_path: release-notes.md