-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (126 loc) · 6.03 KB
/
release.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
name: Push Me Deep, Release Me Hard
on:
push:
tags:
- "v*" # Trigger workflow on (new) tags, e.g., v1.0.0
permissions:
contents: write # Ensure GITHUB_TOKEN has write permissions
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: get_version
shell: powershell
run: |
$version = "${{ github.ref }}" -replace "refs/tags/v", ""
echo "VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8
- name: Extract release notes from CHANGELOG.md
id: extract_notes
shell: powershell
run: |
$changelogPath = "CHANGELOG.md"
$version = "${{ github.ref }}" -replace "refs/tags/v", ""
Write-Output "Looking for release notes for version: $version"
# Check if CHANGELOG.md exists
if (-Not (Test-Path $changelogPath)) {
Write-Error "CHANGELOG.md file not found at $changelogPath"
exit 1
}
# Read the content of CHANGELOG.md using UTF-8 without BOM
$content = Get-Content $changelogPath -Raw -Encoding utf8
# Regex pattern to extract notes for the current version
$pattern = "(?s)(## \[$version\].*?)(?=## \[|\Z)"
$matches = [regex]::Matches($content, $pattern)
if ($matches.Count -eq 0) {
Write-Output "No release notes found for version $version."
echo "RELEASE_NOTES=" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8
} else {
# Extract the release notes
$releaseNotes = $matches[0].Groups[1].Value.Trim()
# Remove the first line containing the version and date (e.g. "[2.0.18] - 2024-11-24")
$lines = $releaseNotes -split "`n" # Split the string by new lines
$lines = $lines[1..($lines.Length - 1)] # Remove the first line
$releaseNotes = $lines -join "`n" # Join the remaining lines back
# Debug output to confirm extraction
Write-Output "Extracted Release Notes:"
Write-Output $releaseNotes
# Ensure UTF-8 encoding without BOM when setting the environment variable
[System.Text.Encoding]::UTF8.GetBytes("RELEASE_NOTES<<EOF`n$releaseNotes`nEOF") |
Set-Content -Path $Env:GITHUB_ENV -NoNewline -Encoding Byte
}
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: Install NSIS
shell: powershell
run: choco install nsis -y
- name: Update AssemblyVersion and FileVersion in .csproj
shell: powershell
run: |
$csprojPath = "AccountSwitcher.csproj"
$newVersion = $Env:VERSION # The version extracted from GitHub tag
# Update AssemblyVersion and FileVersion in .csproj
Write-Output "Updating AssemblyVersion and FileVersion to $newVersion"
# Update AssemblyVersion (set it as <version>.0 for compatibility reasons)
(Get-Content $csprojPath) -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$newVersion.0</AssemblyVersion>" |
Set-Content $csprojPath
# Update FileVersion
(Get-Content $csprojPath) -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$newVersion.0</FileVersion>" |
Set-Content $csprojPath
- name: Build project
run: dotnet publish -c Release -r win-x64
env:
VERSION: ${{ env.VERSION }}
- name: Generate installer
run: makensis installer_script.nsi
- name: Rename installer with tag
shell: powershell
run: |
$tag = $env:GITHUB_REF -replace '^refs/tags/', ''
$tag = $tag -replace '^v', '' # Remove leading 'v' if necessary
Rename-Item -Path "EpicSwitcherSetup.exe" -NewName "EpicSwitcherSetup-$tag.exe"
- name: Create a GitHub Release and upload the installer
uses: softprops/action-gh-release@v2
with:
files: EpicSwitcherSetup-${{ env.VERSION }}.exe
name: "Epic Switcher ${{ env.VERSION }}"
tag_name: "v${{ env.VERSION }}"
body: ${{ env.RELEASE_NOTES }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Construct installer download link
id: construct_link
shell: powershell
run: |
$repo = "${{ github.repository }}"
$version = "${{ env.VERSION }}"
$url = "https://github.com/$repo/releases/latest/download/EpicSwitcherSetup-$version.exe"
echo "DOWNLOAD_URL=$url" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8
- name: Update README.md
shell: powershell
run: |
# Define the path to the README.md file
$readmePath = "README.md"
# Read the content of README.md
$readme = Get-Content $readmePath
# Define the download URL (you can dynamically fetch this or hardcode it)
$downloadUrl = "${{ env.DOWNLOAD_URL }}"
# Replace href attributes that contain "#link_to_be_inserted" or ".exe"
$updated = $readme -replace "href='[^']*(#link_to_be_inserted|\.exe)[^']*'", "href='$downloadUrl'"
# Replace markdown links containing `#link_to_be_inserted` or `.exe` in the URL part and where the display text is 'here'
$updated = $updated -replace '\[here\]\([^\)]*(#link_to_be_inserted|\.exe)[^\)]*\)', "[here]($downloadUrl)"
# Save the updated content back to README.md
$updated | Set-Content $readmePath
# Output to confirm the script worked
Write-Host "README.md has been updated with the download link."
- name: Commit & push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
author_name: "github-actions[bot]"
author_email: "github-actions[bot]@users.noreply.github.com"
message: "Update README.md with latest release URL"