Merge branch 'main' of https://github.com/symonxdd/epic-games-account… #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --self-contained false /p:PublishSingleFile=true | |
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" |