This commit is contained in:
+103
-100
@@ -8,8 +8,7 @@ on:
|
||||
|
||||
jobs:
|
||||
prerelease:
|
||||
runs-on: windows
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://git.daemonlord.ru/actions/checkout@v4
|
||||
@@ -17,127 +16,131 @@ jobs:
|
||||
fetch-depth: 0
|
||||
tags: true
|
||||
|
||||
- name: Ensure Python 3.13
|
||||
shell: powershell
|
||||
run: |
|
||||
if (Get-Command python -ErrorAction SilentlyContinue) {
|
||||
python --version
|
||||
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
|
||||
$pyExe = py -3.13 -c "import sys; print(sys.executable)"
|
||||
if (-not $pyExe) {
|
||||
throw "Python 3.13 launcher is available, but interpreter was not found."
|
||||
}
|
||||
Split-Path $pyExe | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
python --version
|
||||
} else {
|
||||
throw "Python is not installed on runner. Install Python 3.13 and restart runner service."
|
||||
}
|
||||
- name: Set up Python for tests
|
||||
uses: https://git.daemonlord.ru/actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.13"
|
||||
|
||||
- name: Install dependencies
|
||||
shell: powershell
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt pyinstaller
|
||||
|
||||
- name: Extract prerelease metadata
|
||||
- name: Read prerelease metadata
|
||||
id: meta
|
||||
shell: powershell
|
||||
shell: bash
|
||||
run: |
|
||||
$version = (python -c "from app_version import APP_VERSION; print(APP_VERSION)").Trim()
|
||||
$commit = (git rev-parse --short HEAD).Trim()
|
||||
$tag = "v$version-$commit"
|
||||
$archive = "AnabasisManager-$version-$commit"
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "version=$version`n", $utf8NoBom)
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "commit=$commit`n", $utf8NoBom)
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "tag=$tag`n", $utf8NoBom)
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "archive=$archive`n", $utf8NoBom)
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "CONTINUE=true`n", $utf8NoBom)
|
||||
Write-Host "Detected tag: $tag"
|
||||
set -euo pipefail
|
||||
test "$GITHUB_REF" = refs/heads/dev
|
||||
version="$(python -c 'from app_version import APP_VERSION; print(APP_VERSION)')"
|
||||
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
||||
commit="$(git rev-parse --short HEAD)"
|
||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||
echo "commit=$commit" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=v$version-$commit" >> "$GITHUB_OUTPUT"
|
||||
echo "archive=AnabasisManager-$version-$commit" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Stop if prerelease already exists
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
- name: Check prerelease does not exist
|
||||
id: check_release
|
||||
shell: bash
|
||||
env:
|
||||
API_TOKEN: ${{ secrets.API_TOKEN }}
|
||||
RELEASE_TAG: ${{ steps.meta.outputs.tag }}
|
||||
run: |
|
||||
$tag = "${{ steps.meta.outputs.tag }}"
|
||||
$apiUrl = "https://git.daemonlord.ru/api/v1/repos/${{ gitea.repository }}/releases?page=1&limit=100"
|
||||
$headers = @{ Authorization = "token ${{ secrets.API_TOKEN }}" }
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Get
|
||||
$found = $false
|
||||
foreach ($release in $response) {
|
||||
if ($release.tag_name -eq $tag) {
|
||||
$found = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
Write-Host "Pre-release $tag already exists, stopping job."
|
||||
[System.IO.File]::AppendAllText($env:GITHUB_ENV, "CONTINUE=false`n", $utf8NoBom)
|
||||
} else {
|
||||
Write-Host "Pre-release $tag not found, continuing workflow..."
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Failed to query releases list, continuing workflow..."
|
||||
}
|
||||
set -euo pipefail
|
||||
test -n "$API_TOKEN" || { echo 'API_TOKEN secret is missing'; exit 1; }
|
||||
status="$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
|
||||
--header "Authorization: token $API_TOKEN" \
|
||||
"https://git.daemonlord.ru/api/v1/repos/${{ gitea.repository }}/releases/tags/$RELEASE_TAG")"
|
||||
case "$status" in
|
||||
200) echo "Prerelease $RELEASE_TAG already exists; skipping."; echo 'publish=false' >> "$GITHUB_OUTPUT" ;;
|
||||
404) echo 'publish=true' >> "$GITHUB_OUTPUT" ;;
|
||||
*) echo "Cannot check prerelease: HTTP $status"; exit 1 ;;
|
||||
esac
|
||||
|
||||
- name: Check Linux Docker runner
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test "$(uname -m)" = x86_64
|
||||
if ! command -v docker > /dev/null; then
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
apt-get update && apt-get install -y docker.io
|
||||
else
|
||||
sudo apt-get update && sudo apt-get install -y docker.io
|
||||
fi
|
||||
fi
|
||||
docker info --format '{{.OSType}}' | grep -qx linux
|
||||
|
||||
- name: Install test dependencies
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python -m pip install -r requirements.txt
|
||||
|
||||
- name: Run tests
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
env:
|
||||
QT_QPA_PLATFORM: offscreen
|
||||
run: |
|
||||
python -m py_compile app_version.py main.py build.py updater_gui.py tests/test_auth_relogin_smoke.py tests/test_auto_update_service.py tests/test_chat_actions.py tests/test_token_store.py
|
||||
python -m unittest discover -s tests -p "test_*.py" -v
|
||||
set -euo pipefail
|
||||
python -m compileall -q app_version.py main.py build.py updater_gui.py services ui tests
|
||||
python -m unittest discover -s tests -p 'test_*.py' -v
|
||||
|
||||
- name: Build release zip
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
run: |
|
||||
python build.py
|
||||
- name: Build Windows application with PyInstaller
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
run: bash scripts/docker-build-windows.sh
|
||||
|
||||
- name: Prepare prerelease artifacts
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
- name: Prepare prerelease archive
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
env:
|
||||
APP_VERSION: ${{ steps.meta.outputs.version }}
|
||||
ARCHIVE_BASE: ${{ steps.meta.outputs.archive }}
|
||||
run: |
|
||||
$version = "${{ steps.meta.outputs.version }}"
|
||||
$archiveBase = "${{ steps.meta.outputs.archive }}"
|
||||
$srcZip = "dist/AnabasisManager-$version.zip"
|
||||
$dstZip = "dist/$archiveBase.zip"
|
||||
if (-not (Test-Path $srcZip)) {
|
||||
throw "Archive not found: $srcZip"
|
||||
}
|
||||
Copy-Item -Path $srcZip -Destination $dstZip -Force
|
||||
$hash = (Get-FileHash -Path $dstZip -Algorithm SHA256).Hash.ToLower()
|
||||
"$hash $archiveBase.zip" | Set-Content -Path "dist/$archiveBase.zip.sha256" -Encoding UTF8
|
||||
set -euo pipefail
|
||||
test -s "dist/AnabasisManager-$APP_VERSION.zip"
|
||||
cp "dist/AnabasisManager-$APP_VERSION.zip" "dist/$ARCHIVE_BASE.zip"
|
||||
python - "$ARCHIVE_BASE" "$APP_VERSION" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
- name: Configure git identity
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
run: |
|
||||
git config user.name "gitea-actions"
|
||||
git config user.email "gitea-actions@daemonlord.ru"
|
||||
archive = Path('dist') / f'{sys.argv[1]}.zip'
|
||||
with ZipFile(archive) as package:
|
||||
required = {'AnabasisManager.exe', 'AnabasisUpdater.exe', 'version.txt'}
|
||||
missing = required.difference(package.namelist())
|
||||
if missing:
|
||||
raise SystemExit(f'Archive is missing: {sorted(missing)}')
|
||||
if package.read('version.txt').decode('utf-8').strip() != sys.argv[2]:
|
||||
raise SystemExit('Archive version does not match APP_VERSION')
|
||||
PY
|
||||
(cd dist && sha256sum "$ARCHIVE_BASE.zip" > "$ARCHIVE_BASE.zip.sha256")
|
||||
(cd dist && sha256sum --check "$ARCHIVE_BASE.zip.sha256")
|
||||
|
||||
- name: Create git tag
|
||||
if: env.CONTINUE == 'true'
|
||||
shell: powershell
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
shell: bash
|
||||
env:
|
||||
RELEASE_TAG: ${{ steps.meta.outputs.tag }}
|
||||
run: |
|
||||
$tag = "${{ steps.meta.outputs.tag }}"
|
||||
$tagLine = (git ls-remote --tags origin "refs/tags/$tag" | Select-Object -First 1)
|
||||
if ([string]::IsNullOrWhiteSpace($tagLine)) {
|
||||
git tag "$tag"
|
||||
git push origin "$tag"
|
||||
} else {
|
||||
Write-Host "Tag $tag already exists on origin, skipping tag push."
|
||||
}
|
||||
set -euo pipefail
|
||||
if git ls-remote --exit-code --tags origin "refs/tags/$RELEASE_TAG" > /dev/null; then
|
||||
git fetch origin "refs/tags/$RELEASE_TAG:refs/tags/$RELEASE_TAG"
|
||||
test "$(git rev-parse "$RELEASE_TAG^{commit}")" = "$GITHUB_SHA"
|
||||
else
|
||||
git tag "$RELEASE_TAG" "$GITHUB_SHA"
|
||||
git push origin "$RELEASE_TAG"
|
||||
fi
|
||||
|
||||
- name: Create Gitea Pre-release
|
||||
if: env.CONTINUE == 'true'
|
||||
if: steps.check_release.outputs.publish == 'true'
|
||||
uses: https://git.daemonlord.ru/actions/gitea-release-action@v1
|
||||
with:
|
||||
server_url: https://git.daemonlord.ru
|
||||
repository: ${{ gitea.repository }}
|
||||
token: ${{ secrets.API_TOKEN }}
|
||||
tag_name: ${{ steps.meta.outputs.tag }}
|
||||
target_commitish: ${{ gitea.sha }}
|
||||
name: Anabasis Manager ${{ steps.meta.outputs.version }} (dev ${{ steps.meta.outputs.commit }})
|
||||
prerelease: true
|
||||
body: |
|
||||
|
||||
Reference in New Issue
Block a user