TPVToggle - Version Bump and Release #40
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 | |
# Ensure 7z is available (it usually is on windows runners) or install it | |
# Example using PowerShell's built-in Compress-Archive if 7z isn't guaranteed | |
# run: Compress-Archive -Path TPVToggle\build\* -DestinationPath ${{ env.ARTIFACT_NAME }} -Force | |
run: | | |
cd TPVToggle\build | |
7z a ..\..\${{ env.ARTIFACT_NAME }} * | |
shell: pwsh # Use PowerShell as it's good with paths/env vars | |
- name: Commit version changes | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
# Ensure submodule changes are also staged if they occurred (less likely now) | |
# git add TPVToggle/external/* # Be cautious with this, usually not needed if just building | |
git add TPVToggle/src/version.h TPVToggle/CHANGELOG.md TPVToggle/build/KCD2_TPVToggle_Readme.txt | |
# Check git status before committing | |
git status | |
git commit -m "Bump version to ${{ env.NEW_VERSION }}" | |
git tag -a TPVToggle-${{ env.VERSION_TAG }} -m "Release ${{ env.VERSION_TAG }}" # Use unique tag name | |
git push origin main # Push main branch first | |
git push origin TPVToggle-${{ env.VERSION_TAG }} # Push the specific tag | |
shell: bash | |
- name: Prepare release body | |
id: prepare-release | |
run: | | |
# Replace the placeholder '%0A' correctly for multiline body | |
$changelog = '${{ steps.read-changelog.outputs.CHANGELOG }}' -replace '%0A', "`n" | |
# Trim title just in case | |
$releaseTitle = '${{ steps.determine-title.outputs.TITLE }}' | |
$releaseBody = @" | |
# Kingdom Come: Deliverance II - Third Person View Toggle | |
## Release ${{ env.VERSION_TAG }} - $releaseTitle | |
This mod enables toggling between first-person and third-person views in Kingdom Come: Deliverance II using customizable hotkeys. | |
## Changelog | |
$changelog | |
### 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/${{ github.repository }}/blob/main/TPVToggle/README.md) for detailed instructions. | |
"@ | |
# Escape characters that might interfere with JSON or downstream processing? Unlikely here, but good practice. | |
# For action-gh-release, raw multiline text is fine for body_path. | |
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 }} # Explicitly pass token if needed, though often inferred | |
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 }} | |
- name: Archive NEXT_CHANGELOG.md | |
# This step assumes the push in "Commit version changes" completed successfully and main is updated | |
if: success() # Only run if previous steps succeeded | |
run: | | |
git pull origin main # Ensure we have the absolute latest main before modifying/archiving | |
$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." | |
# Optionally create a new template anyway or exit | |
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 | |
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" | |
# Check status before committing | |
git status | |
git commit -m "Chore: Archive changelog for ${{ env.VERSION_TAG }} and prepare for next release" | |
git push origin main | |
shell: pwsh |