TPVToggle - Version Bump and Release #58
This file contains hidden or 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: TPVToggle - Version Bump and Release | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
inputs: | |
version_part: | |
description: "Version part to bump" | |
required: true | |
default: "patch" | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
version_title: | |
description: "Version title (e.g., 'Feature Update')" | |
required: false | |
type: string | |
prerelease: | |
description: "Is this a pre-release?" | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
bump-and-release: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
submodules: "recursive" | |
token: ${{ secrets.PAT }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Read changelog from file | |
id: read-changelog | |
run: | | |
# Check if the NEXT_CHANGELOG.md file exists | |
if (Test-Path "TPVToggle\docs\NEXT_CHANGELOG.md") { | |
$content = Get-Content "TPVToggle\docs\NEXT_CHANGELOG.md" -Raw | |
# Extract title from first line (removing ## prefix) | |
$title = ($content -split "`r?`n")[0] -replace "^##\s+", "" | |
# Get the rest as changelog content (skip first line, handle Windows/Unix newlines) | |
$changelogLines = ($content -split "`r?`n" | Select-Object -Skip 1) -join "%0A" | |
echo "SUGGESTED_TITLE=$title" >> $env:GITHUB_OUTPUT | |
echo "CHANGELOG=$changelogLines" >> $env:GITHUB_OUTPUT | |
echo "Using changelog from NEXT_CHANGELOG.md with suggested title: $title" | |
} else { | |
echo "No NEXT_CHANGELOG.md file found. Please create one before running this workflow." | |
exit 1 | |
} | |
shell: pwsh | |
- name: Determine version title | |
id: determine-title | |
run: | | |
# Use the input title if provided, otherwise use the suggested title from the changelog | |
$titleToUse = "${{ inputs.version_title }}" | |
if ([string]::IsNullOrEmpty($titleToUse)) { | |
$titleToUse = "${{ steps.read-changelog.outputs.SUGGESTED_TITLE }}" | |
echo "Using title from changelog: $titleToUse" | |
} else { | |
echo "Using provided title: $titleToUse" | |
} | |
# Trim potential whitespace/newlines from title | |
$trimmedTitle = $titleToUse.Trim() | |
echo "TITLE=$trimmedTitle" >> $env:GITHUB_OUTPUT | |
echo "Final Title: $trimmedTitle" # Added for debugging | |
shell: pwsh | |
- name: Bump version and update changelog | |
id: bump | |
run: | | |
# Create a temporary file for the changelog to avoid command line escaping issues | |
# Replace %0A with actual newlines using PowerShell's backtick escape | |
$changelogContent = "${{ steps.read-changelog.outputs.CHANGELOG }}" -replace '%0A', "`n" | |
Set-Content -Path "temp_changelog.txt" -Value $changelogContent | |
# Ensure the title passed doesn't have unwanted characters | |
$safeTitle = "${{ steps.determine-title.outputs.TITLE }}" | |
# Run the version updater script with changelog from file | |
echo "Running Python script with title: $safeTitle" # Debugging line | |
python TPVToggle/scripts/version_updater.py bump ${{ inputs.version_part }} --title "$safeTitle" --changelog (Get-Content -Path "temp_changelog.txt" -Raw) | |
# Extract the new version from version.h | |
$version_h = Get-Content TPVToggle\src\version.h -Raw | |
$major = [regex]::Match($version_h, '#define\s+VERSION_MAJOR\s+(\d+)').Groups[1].Value | |
$minor = [regex]::Match($version_h, '#define\s+VERSION_MINOR\s+(\d+)').Groups[1].Value | |
$patch = [regex]::Match($version_h, '#define\s+VERSION_PATCH\s+(\d+)').Groups[1].Value | |
$new_version = "$major.$minor.$patch" | |
echo "NEW_VERSION=$new_version" >> $env:GITHUB_ENV | |
echo "VERSION_TAG=v$new_version" >> $env:GITHUB_ENV | |
echo "ARTIFACT_NAME=KCD2_TPVToggle_v${new_version}.zip" >> $env:GITHUB_ENV | |
# Clean up temp file | |
Remove-Item -Path "temp_changelog.txt" | |
shell: pwsh | |
- name: Cache MinGW | |
id: cache-mingw | |
uses: actions/cache@v3 | |
with: | |
path: C:\ProgramData\chocolatey\lib\mingw | |
key: ${{ runner.os }}-mingw-11.2.0 | |
- name: Install MinGW | |
if: steps.cache-mingw.outputs.cache-hit != 'true' | |
run: | | |
choco install mingw --version=11.2.0 -y | |
shell: powershell | |
- name: Set MinGW path | |
run: | | |
echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
shell: powershell | |
- name: Build ASI plugin | |
run: | | |
# Verify submodules checked out by actions/checkout@v4 | |
echo "--- Verifying submodule checkout ---" | |
ls -l TPVToggle/external/minhook/include/MinHook.h # Check specific crucial file | |
ls -l TPVToggle/external/minhook # List directory | |
ls -l TPVToggle/external/simpleini # List directory | |
echo "--- Changing to TPVToggle directory ---" | |
cd TPVToggle | |
pwd # Confirm current directory | |
echo "--- Running make clean ---" | |
make clean | |
echo "--- Running make ---" | |
make | |
shell: bash | |
- name: Display build output | |
run: | | |
dir TPVToggle\build | |
shell: cmd # cmd is fine for dir | |
- name: Create ZIP archive | |
run: | | |
cd TPVToggle\build | |
Remove-Item -LiteralPath "obj" -Force -Recurse | |
7z a ..\..\${{ env.ARTIFACT_NAME }} * | |
shell: pwsh # Use PowerShell as it's good with paths/env vars | |
# Only commit changes if this is NOT a pre-release | |
- name: Commit version changes | |
if: ${{ !inputs.prerelease }} | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add TPVToggle/src/version.h TPVToggle/CHANGELOG.md TPVToggle/build/KCD2_TPVToggle_Readme.txt | |
git status | |
git commit -m "Bump version to ${{ env.NEW_VERSION }}" | |
git tag -a TPVToggle-${{ env.VERSION_TAG }} -m "Release ${{ env.VERSION_TAG }}" | |
# Get current branch name - for GitHub Actions environments | |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
echo "Current branch: $BRANCH_NAME" | |
# Push to the appropriate branch | |
if [ "$BRANCH_NAME" = "main" ]; then | |
git push origin main | |
else | |
# We're on a feature branch | |
git push origin $BRANCH_NAME | |
fi | |
# Always push the tag | |
git push origin TPVToggle-${{ env.VERSION_TAG }} | |
shell: bash | |
# For pre-releases, just create the tag without committing changes | |
- name: Create tag for pre-release | |
if: ${{ inputs.prerelease }} | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git tag -a TPVToggle-${{ env.VERSION_TAG }} -m "Pre-release ${{ env.VERSION_TAG }}" | |
git push origin TPVToggle-${{ env.VERSION_TAG }} | |
shell: bash | |
- name: Prepare release body | |
id: prepare-release | |
run: | | |
# Write the changelog to a file first to avoid any issues with special characters | |
"${{ steps.read-changelog.outputs.CHANGELOG }}" -replace '%0A', "`n" | Out-File -FilePath "changelog_content.txt" -Encoding utf8 | |
# Read the changelog from file | |
$changelog = Get-Content -Path "changelog_content.txt" -Raw | |
# Create the release body | |
$releaseBody = @' | |
# Kingdom Come: Deliverance II - Third Person View Toggle | |
## Release {0} - {1} | |
This mod enables toggling between first-person and third-person views in Kingdom Come: Deliverance II using customizable hotkeys. | |
## Changelog | |
{2} | |
### Installation | |
1. Simply extract all files to your game directory: | |
`<KC:D 2 installation folder>/Bin/Win64MasterMasterSteamPGO/` | |
2. Launch the game and press F3 (default) to toggle the camera view | |
### Note | |
This package includes everything you need: | |
- KCD2_TPVToggle.asi (the mod itself) | |
- KCD2_TPVToggle.ini (configuration file) | |
- dinput8.dll (Ultimate ASI Loader) | |
- Documentation and license information | |
### Configuration | |
Edit the `KCD2_TPVToggle.ini` file to customize hotkeys and other settings. | |
See the [README](https://github.com/{3}/blob/main/TPVToggle/README.md) for detailed instructions. | |
'@ | |
# Format the release body with the values | |
$releaseBody = $releaseBody -f $env:VERSION_TAG, "${{ steps.determine-title.outputs.TITLE }}", $changelog, "${{ github.repository }}" | |
# Add pre-release notice if applicable | |
if ('${{ inputs.prerelease }}' -eq 'true') { | |
$preReleaseNotice = @' | |
## ⚠️ PRE-RELEASE VERSION ⚠️ | |
This is a pre-release build for testing purposes. It may contain bugs or incomplete features. | |
'@ | |
$releaseBody = $preReleaseNotice + $releaseBody | |
} | |
# Write to file for the release action | |
Set-Content -Path "release_body.txt" -Value $releaseBody -Encoding UTF8 | |
echo "RELEASE_BODY_PATH=release_body.txt" >> $env:GITHUB_OUTPUT | |
shell: pwsh | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: ${{ env.ARTIFACT_NAME }} | |
name: KCD2 TPVToggle ${{ env.VERSION_TAG }} # Release name | |
tag_name: TPVToggle-${{ env.VERSION_TAG }} # The unique tag name created earlier | |
body_path: ${{ steps.prepare-release.outputs.RELEASE_BODY_PATH }} | |
draft: false | |
prerelease: ${{ inputs.prerelease }} | |
# Only archive the changelog if this is NOT a pre-release | |
- name: Archive NEXT_CHANGELOG.md | |
if: ${{ !inputs.prerelease && success() }} | |
run: | | |
# Get current branch name - for GitHub Actions environments | |
$branchName = $env:GITHUB_HEAD_REF | |
if ([string]::IsNullOrEmpty($branchName)) { | |
if ($env:GITHUB_REF -match "refs/heads/(.+)") { | |
$branchName = $matches[1] | |
} | |
} | |
Write-Output "Current branch for archiving: $branchName" | |
# Pull latest changes from the correct branch | |
git pull origin $branchName | |
$archiveDir = "TPVToggle\docs\archive" | |
$nextChangelogPath = "TPVToggle\docs\NEXT_CHANGELOG.md" | |
# Check if NEXT_CHANGELOG.md exists before trying to archive | |
if (-not (Test-Path $nextChangelogPath)) { | |
echo "$nextChangelogPath not found, cannot archive." | |
exit 1 # Or just warn and proceed | |
} | |
# Create archive directory if it doesn't exist | |
if (-not (Test-Path $archiveDir)) { | |
New-Item -Path $archiveDir -ItemType Directory | |
} | |
# Move the changelog to archive with a versioned name for clarity | |
$archiveFileName = "CHANGELOG_${{ env.VERSION_TAG }}.md" # Use version tag | |
Move-Item $nextChangelogPath "$archiveDir\$archiveFileName" | |
echo "Archived changelog to $archiveDir\$archiveFileName" | |
# Create an empty NEXT_CHANGELOG.md template for the next update | |
$template = @' | |
## [Title for next release] | |
- New feature | |
- Bug fix | |
- Improvement | |
'@ | |
Set-Content -Path $nextChangelogPath -Value $template | |
echo "Created new $nextChangelogPath template." | |
# Commit the changes to the current branch | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add "$nextChangelogPath" "$archiveDir\$archiveFileName" | |
git status | |
git commit -m "Chore: Archive changelog for ${{ env.VERSION_TAG }} and prepare for next release" | |
git push origin $branchName | |
shell: pwsh |