zapret-kvn/.github/workflows/build.yml
2026-07-11 21:01:15 +03:00

177 lines
5.9 KiB
YAML

name: Build & Release
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: windows-x64-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
PYTHON_VERSION: "3.12"
CORE_BUNDLE: .cache/core-bundle/core-windows-x64.7z
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Determine version
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
shell: pwsh
run: |
$tags = git tag --list "v*" --sort=-version:refname 2>$null
if ($tags) {
$latest = ($tags | Select-Object -First 1).Trim()
$clean = ($latest.TrimStart("v") -replace '-.*$','')
$parts = $clean.Split(".")
$major = [int]$parts[0]
$minor = [int]$parts[1]
$patch = [int]$parts[2] + 1
$version = "$major.$minor.$patch"
} else {
$version = "0.5.0"
}
echo "VERSION=$version" >> $env:GITHUB_ENV
echo "RELEASE_TAG=v$version" >> $env:GITHUB_ENV
Write-Host "Release version: $version (tag: v$version)"
- name: Update version in constants.py
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
shell: pwsh
run: |
$file = "xray_fluent/constants.py"
(Get-Content $file -Raw) -replace 'APP_VERSION = ".*?"', "APP_VERSION = `"$env:VERSION`"" | Set-Content $file -NoNewline
Write-Host "Updated APP_VERSION to $env:VERSION"
Get-Content $file | Select-String "APP_VERSION"
- name: Setup Python
id: setup-python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
cache-dependency-path: requirements.txt
- name: Cache Windows virtualenv
id: venv-cache
uses: actions/cache@v6
with:
path: .venv
key: venv-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}
- name: Prepare build environment
shell: pwsh
run: |
if (-not (Test-Path .venv/Scripts/python.exe)) {
python -m venv .venv
.venv/Scripts/python.exe -m pip install --upgrade pip
.venv/Scripts/python.exe -m pip install -r requirements.txt
}
.venv/Scripts/python.exe -m pip check
- name: Cache PyInstaller binary cache
uses: actions/cache@v6
with:
path: ~\AppData\Local\pyinstaller
key: pyinstaller-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('requirements.txt') }}
- name: Cache Windows x64 core bundle
id: core-cache
uses: actions/cache@v6
with:
path: ${{ env.CORE_BUNDLE }}
key: cores-windows-x64-${{ hashFiles('scripts/core-lock.windows-x64.json') }}
- name: Build Windows x64 core bundle
if: steps.core-cache.outputs.cache-hit != 'true'
shell: pwsh
run: ./scripts/build_core_bundle.ps1 -OutputArchive $env:CORE_BUNDLE
- name: Install and verify core bundle
shell: pwsh
run: ./scripts/install_core_bundle.ps1 -Archive $env:CORE_BUNDLE
- name: Run unit tests
shell: pwsh
run: .venv/Scripts/python.exe -m unittest discover -s tests -v
- name: Build with project builder
shell: pwsh
run: python build.py --no-zip
- name: Upload core bundle artifact
uses: actions/upload-artifact@v7
with:
name: ZapretKVN-cores-windows-x64
path: ${{ env.CORE_BUNDLE }}
compression-level: 0
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: ZapretKVN-portable
path: dist/ZapretKVN/
# ── Release on push to main ──
- name: Create release archives
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
shell: pwsh
run: |
cd dist/ZapretKVN
# Self-extracting exe for manual install
7z a -t7z -mx=5 -sfx "../ZapretKVN-v$env:VERSION-windows-x64.exe" *
# Zip for auto-updater
7z a -tzip -mx=5 "../ZapretKVN-v$env:VERSION-windows-x64.zip" *
$zipPath = "../ZapretKVN-v$env:VERSION-windows-x64.zip"
$zipHash = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLower()
Set-Content "$zipPath.sha256" -Value $zipHash -Encoding ASCII
# 7z archive
7z a -t7z -mx=5 "../ZapretKVN-v$env:VERSION-windows-x64.7z" *
cd ..
Copy-Item "../$env:CORE_BUNDLE" "ZapretKVN-cores-v$env:VERSION-windows-x64.7z"
Write-Host "Release archives:"
Get-ChildItem *.exe, *.zip, *.7z, *.sha256 | Format-Table Name, Length
- name: Create GitHub Release
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_TAG }}
name: "Zapret KVN ${{ env.RELEASE_TAG }}"
generate_release_notes: true
make_latest: true
files: |
dist/ZapretKVN-*-windows-x64.exe
dist/ZapretKVN-*-windows-x64.zip
dist/ZapretKVN-v*-windows-x64.7z
dist/ZapretKVN-*-windows-x64.zip.sha256
dist/ZapretKVN-cores-*-windows-x64.7z
- name: Commit version bump
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add xray_fluent/constants.py
if ! git diff --cached --quiet; then
git commit -m "v$VERSION [skip ci]"
git push
fi