Release Build #16
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: Release Build | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: 'Release type' | |
| required: true | |
| type: choice | |
| options: | |
| - stable | |
| - prerelease | |
| - development | |
| default: 'stable' | |
| permissions: | |
| contents: write | |
| jobs: | |
| prepare_release: | |
| name: Prepare Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| is_prerelease: ${{ steps.version.outputs.is_prerelease }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Generate Version | |
| id: version | |
| run: python .github/scripts/generate_release_version.py --type ${{ github.event.inputs.release_type }} | |
| - name: Update Version in Files | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| echo "Updating version to $VERSION" | |
| # Update pyproject.toml | |
| sed -i "s/version = \".*\"/version = \"$VERSION\"/" pyproject.toml | |
| # Update __init__.py | |
| sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" src/switchcraft/__init__.py | |
| # Update file_version_info.txt | |
| python .github/scripts/update_version_info.py "$VERSION" | |
| - name: Generate Changelog | |
| id: changelog | |
| run: | | |
| python .github/scripts/generate_changelog.py --output changelog.md | |
| # Read changelog content into a variable safely (multiline) | |
| { | |
| echo 'CHANGELOG_BODY<<EOF' | |
| cat changelog.md | |
| echo "" | |
| echo 'EOF' | |
| } >> "$GITHUB_ENV" | |
| - name: Commit and Tag | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml src/switchcraft/__init__.py file_version_info.txt | |
| # Only commit if there are changes | |
| if ! git diff --cached --quiet; then | |
| echo "Changes detected, committing version bump..." | |
| git commit -m "chore(release): bump version to $VERSION [skip ci]" | |
| git push origin main | |
| else | |
| echo "No changes detected, version files are already up to date." | |
| fi | |
| # Always tag and push the tag | |
| git tag "v$VERSION" | |
| git push origin "v$VERSION" | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: ${{ github.event.inputs.release_type == 'stable' && format('Release v{0}', steps.version.outputs.version) || github.event.inputs.release_type == 'prerelease' && format('Pre-release v{0}', steps.version.outputs.version) || format('Development Build v{0}', steps.version.outputs.version) }} | |
| body: | | |
|  | |
| ${{ env.CHANGELOG_BODY }} | |
| draft: false | |
| prerelease: ${{ github.event.inputs.release_type != 'stable' }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update Main Branch to Dev Version | |
| if: ${{ github.event.inputs.release_type == 'stable' }} | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| # Calculate next dev version (increment patch and add -dev) | |
| MAJOR=$(echo $VERSION | cut -d. -f1) | |
| MINOR=$(echo $VERSION | cut -d. -f2) | |
| PATCH=$(echo $VERSION | cut -d. -f3) | |
| NEXT_PATCH=$((PATCH + 1)) | |
| DEV_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-dev" | |
| echo "Setting development version to $DEV_VERSION" | |
| # Update version files | |
| sed -i "s/version = \".*\"/version = \"$DEV_VERSION\"/" pyproject.toml | |
| sed -i "s/__version__ = \".*\"/__version__ = \"$DEV_VERSION\"/" src/switchcraft/__init__.py | |
| python .github/scripts/update_version_info.py "$DEV_VERSION" | |
| # Commit | |
| git add pyproject.toml src/switchcraft/__init__.py file_version_info.txt | |
| git commit -m "chore: bump version to $DEV_VERSION for development [skip ci]" | |
| git push origin main | |
| build: | |
| name: Build using PyInstaller | |
| needs: prepare_release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| artifact_name: SwitchCraft.exe | |
| asset_name: SwitchCraft-windows.exe | |
| - os: ubuntu-latest | |
| artifact_name: SwitchCraft | |
| asset_name: SwitchCraft-linux | |
| - os: macos-latest | |
| artifact_name: SwitchCraft | |
| asset_name: SwitchCraft-macos | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: v${{ needs.prepare_release.outputs.version }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| pip install pyinstaller customtkinter tkinterdnd2 pillow | |
| - name: Build with PyInstaller | |
| run: | | |
| pyinstaller switchcraft.spec | |
| - name: Rename to Platform Name | |
| run: | | |
| cp dist/${{ matrix.artifact_name }} dist/${{ matrix.asset_name }} | |
| shell: bash | |
| - name: Upload Release Asset | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.prepare_release.outputs.version }} | |
| files: dist/${{ matrix.asset_name }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build Windows Installer | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| # Install Inno Setup | |
| choco install innosetup -y | |
| # Install ImageMagick for PNG to ICO conversion | |
| choco install imagemagick -y | |
| # Convert PNG to ICO with multiple sizes | |
| magick images/switchcraft_logo.png -define icon:auto-resize=256,128,64,48,32,16 switchcraft_logo.ico | |
| # Update version in ISS file | |
| $version = "${{ needs.prepare_release.outputs.version }}" | |
| # Clean version for VersionInfoVersion (remove -beta, -dev, etc.) | |
| $cleanVersion = $version -replace '[^0-9.]', '' | |
| # Update both display version and numeric version | |
| (Get-Content switchcraft.iss) -replace '#define MyAppVersion ".*"', "#define MyAppVersion `"$version`"" | Set-Content switchcraft.iss | |
| (Get-Content switchcraft.iss) -replace '#define MyAppVersionNumeric ".*"', "#define MyAppVersionNumeric `"$cleanVersion`"" | Set-Content switchcraft.iss | |
| # Build installer | |
| iscc switchcraft.iss | |
| shell: pwsh | |
| - name: Upload Windows Installer | |
| if: matrix.os == 'windows-latest' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.prepare_release.outputs.version }} | |
| files: dist/SwitchCraft-Setup.exe | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |