Skip to content

feat(actions): support prepare for next changelog #16

feat(actions): support prepare for next changelog

feat(actions): support prepare for next changelog #16

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@v3
with:
fetch-depth: 0
- 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 "\n")[0] -replace "^##\s+", ""
# Get the rest as changelog content (skip first line)
$changelogLines = ($content -split "\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"
}
echo "TITLE=$titleToUse" >> $env:GITHUB_OUTPUT
shell: pwsh
- name: Bump version and update changelog
id: bump
run: |
# Run the version updater script with changelog from file
python TPVToggle/scripts/version_updater.py bump ${{ inputs.version_part }} --title "${{ steps.determine-title.outputs.TITLE }}" --changelog "${{ steps.read-changelog.outputs.CHANGELOG }}"
# Extract the new version from version.h
$version_h = Get-Content TPVToggle\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
shell: pwsh
- name: Cache MinGW
id: cache-mingw
uses: actions/cache@v3
with:
path: C:\ProgramData\chocolatey\lib\mingw
key: ${{ runner.os }}-mingw-8.1.0
- name: Install MinGW
if: steps.cache-mingw.outputs.cache-hit != 'true'
run: |
choco install mingw --version=8.1.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: |
cd TPVToggle
g++ -shared -o build/KCD2_TPVToggle.asi dllmain.cpp logger.cpp config.cpp toggle_thread.cpp aob_scanner.cpp exception_handler.cpp version.cpp -static -lpsapi "-Wl,--add-stdcall-alias" -O2 -Wall -Wextra
shell: bash
- name: Display build output
run: |
dir TPVToggle\build
shell: cmd
- name: Create ZIP archive
run: |
cd TPVToggle\build
7z a ..\..\${{ env.ARTIFACT_NAME }} *
shell: pwsh
- 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]"
git add TPVToggle/version.h TPVToggle/CHANGELOG.md TPVToggle/build/README.txt
git commit -m "Bump version to ${{ env.NEW_VERSION }}"
git tag -a TPVToggle-${{ env.VERSION_TAG }} -m "Release ${{ env.VERSION_TAG }}"
git push origin main --tags
shell: bash
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.ARTIFACT_NAME }}
name: KCD2 TPVToggle ${{ env.VERSION_TAG }}
tag_name: TPVToggle-${{ env.VERSION_TAG }}
body: |
# Kingdom Come: Deliverance II - Third Person View Toggle
## Release ${{ env.VERSION_TAG }}
This mod enables toggling between first-person and third-person views in Kingdom Come: Deliverance II using customizable hotkeys.
## Changelog
${{ steps.read-changelog.outputs.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/tkhquang/KDC2Tools/blob/main/TPVToggle/README.md) for detailed instructions.
draft: false
prerelease: ${{ inputs.prerelease }}
- name: Archive NEXT_CHANGELOG.md
if: success()
run: |
# Create archive directory if it doesn't exist
$archiveDir = "TPVToggle\docs\archive"
if (-not (Test-Path $archiveDir)) {
New-Item -Path $archiveDir -ItemType Directory
}
# Move the changelog to archive with a timestamped name
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
Move-Item "TPVToggle\docs\NEXT_CHANGELOG.md" "$archiveDir\CHANGELOG_$timestamp.md"
# Create an empty NEXT_CHANGELOG.md template for the next update
$template = @"
## [Title for next release]

Check failure on line 194 in .github/workflows/release-tpvtoggle.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/release-tpvtoggle.yml

Invalid workflow file

You have an error in your yaml syntax on line 194
-
-
-
"@
Set-Content -Path "TPVToggle\docs\NEXT_CHANGELOG.md" -Value $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 "TPVToggle\docs\NEXT_CHANGELOG.md" "$archiveDir\CHANGELOG_$timestamp.md"
git commit -m "Archive changelog and prepare for next release"
git push origin main
shell: pwsh