a8551b5c28
build / mod (push) Successful in 3m24s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
153 lines
7.5 KiB
YAML
153 lines
7.5 KiB
YAML
# Сборки игры-форка для macOS и Windows: запускаются вручную (Actions → desktop → Run workflow)
|
||
# с тегом готового релиза (build-N) и дописывают свои архивы в него. Нужны раннеры с метками
|
||
# macos-latest / windows-latest (например, act_runner в режиме host на своём Маке или ПК).
|
||
name: desktop
|
||
|
||
on:
|
||
workflow_dispatch:
|
||
inputs:
|
||
tag:
|
||
description: Тег релиза, например build-3
|
||
required: true
|
||
os:
|
||
description: macos, windows или both
|
||
required: true
|
||
default: both
|
||
|
||
env:
|
||
CARGO_TERM_COLOR: never
|
||
|
||
jobs:
|
||
game-macos:
|
||
if: inputs.os == 'macos' || inputs.os == 'both'
|
||
runs-on: macos-latest
|
||
steps:
|
||
- name: Проверка релиза
|
||
env:
|
||
TOKEN: ${{ secrets.RELEASE_TOKEN || gitea.token }}
|
||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||
TAG: ${{ inputs.tag }}
|
||
run: |
|
||
set -e
|
||
if ! [[ "$TAG" =~ ^build-[0-9]+$ ]]; then echo "::error::тег '$TAG' не похож на build-N"; exit 1; fi
|
||
REL_JSON=$(mktemp)
|
||
CODE=$(curl -s -o "$REL_JSON" -w '%{http_code}' -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG")
|
||
if [ "$CODE" != "200" ]; then echo "::error::релиза с тегом $TAG нет (HTTP $CODE): сначала дождись сборки build.yml на main"; exit 1; fi
|
||
python3 - "$TAG" "$REL_JSON" <<'PY'
|
||
import json, os, sys
|
||
tag, path = sys.argv[1], sys.argv[2]
|
||
r = json.load(open(path))
|
||
assets = [a.get('name') for a in (r.get('assets') or [])]
|
||
if r.get('tag_name') != tag or r.get('name') != tag or 'airdef.hmod' not in assets:
|
||
print('::error::релиз %s не создан build.yml (нужны имя = тег и вложение airdef.hmod): чужой релиз не трогаем' % tag)
|
||
sys.exit(1)
|
||
with open(os.environ['GITHUB_ENV'], 'a') as f:
|
||
f.write('RELEASE_ID=%s\nRELEASE_SHA=%s\n' % (r['id'], r.get('target_commitish', '')))
|
||
PY
|
||
- uses: actions/checkout@v4
|
||
with:
|
||
ref: refs/tags/${{ inputs.tag }}
|
||
- name: Проверка коммита
|
||
env:
|
||
TAG: ${{ inputs.tag }}
|
||
run: |
|
||
set -e
|
||
HEAD_SHA=$(git rev-parse HEAD)
|
||
if [[ "$RELEASE_SHA" =~ ^[0-9a-f]{40}$ ]] && [ "$HEAD_SHA" != "$RELEASE_SHA" ]; then echo "::error::тег $TAG указывает на $HEAD_SHA, а релиз создан из $RELEASE_SHA"; exit 1; fi
|
||
echo "собираю $TAG = $HEAD_SHA"
|
||
- name: Rust
|
||
run: |
|
||
command -v cargo || curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
|
||
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||
- name: Форк Horizon
|
||
run: python3 tools/airdef.py fork
|
||
- name: Игра
|
||
run: python3 tools/airdef.py game
|
||
- name: Мод
|
||
run: |
|
||
rustup target add wasm32-unknown-unknown
|
||
python3 tools/airdef.py mod
|
||
mkdir -p out
|
||
cp airdef-mod/target/horizon-mod/airdef.hmod out/
|
||
- name: Архив
|
||
run: |
|
||
D=airdef-macos-arm64
|
||
mkdir -p "$D"
|
||
cp horizon/target/fast/horizon-client horizon/target/fast/horizon-ctl out/airdef.hmod dist/play.sh docs/INSTALL.md "$D/"
|
||
tar czf "out/$D.tar.gz" "$D"
|
||
- name: В релиз
|
||
env:
|
||
TOKEN: ${{ secrets.RELEASE_TOKEN || gitea.token }}
|
||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||
run: |
|
||
set -e
|
||
# RELEASE_ID взят в шаге «Проверка релиза» (релиз build-N, созданный build.yml)
|
||
curl -sf -X POST -H "Authorization: token $TOKEN" -F "attachment=@out/airdef-macos-arm64.tar.gz" "$API/releases/$RELEASE_ID/assets?name=airdef-macos-arm64.tar.gz" > /dev/null
|
||
|
||
game-windows:
|
||
if: inputs.os == 'windows' || inputs.os == 'both'
|
||
runs-on: windows-latest
|
||
defaults:
|
||
run:
|
||
shell: pwsh
|
||
steps:
|
||
- name: Проверка релиза
|
||
env:
|
||
TOKEN: ${{ secrets.RELEASE_TOKEN || gitea.token }}
|
||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||
TAG: ${{ inputs.tag }}
|
||
run: |
|
||
$ErrorActionPreference = 'Stop'
|
||
if ($env:TAG -notmatch '^build-\d+$') { Write-Output "::error::тег '$env:TAG' не похож на build-N"; exit 1 }
|
||
$h = @{ Authorization = "token $env:TOKEN" }
|
||
try { $r = Invoke-RestMethod -Headers $h "$env:API/releases/tags/$env:TAG" }
|
||
catch { Write-Output "::error::релиза с тегом $env:TAG нет: сначала дождись сборки build.yml на main"; exit 1 }
|
||
$assets = @($r.assets | ForEach-Object { $_.name })
|
||
if ($r.tag_name -ne $env:TAG -or $r.name -ne $env:TAG -or ($assets -notcontains 'airdef.hmod')) {
|
||
Write-Output "::error::релиз $env:TAG не создан build.yml (нужны имя = тег и вложение airdef.hmod): чужой релиз не трогаем"; exit 1
|
||
}
|
||
"RELEASE_ID=$($r.id)" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
|
||
"RELEASE_SHA=$($r.target_commitish)" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
|
||
- uses: actions/checkout@v4
|
||
with:
|
||
ref: refs/tags/${{ inputs.tag }}
|
||
- name: Проверка коммита
|
||
env:
|
||
TAG: ${{ inputs.tag }}
|
||
run: |
|
||
$ErrorActionPreference = 'Stop'
|
||
$head = git rev-parse HEAD
|
||
if ($env:RELEASE_SHA -match '^[0-9a-f]{40}$' -and $head -ne $env:RELEASE_SHA) { Write-Output "::error::тег $env:TAG указывает на $head, а релиз создан из $env:RELEASE_SHA"; exit 1 }
|
||
Write-Output "собираю $env:TAG = $head"
|
||
- name: Rust
|
||
run: |
|
||
if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
|
||
Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile rustup-init.exe
|
||
.\rustup-init.exe -y --profile minimal
|
||
}
|
||
"$env:USERPROFILE\.cargo\bin" | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
|
||
- name: Форк Horizon
|
||
run: python tools/airdef.py fork
|
||
- name: Игра
|
||
run: python tools/airdef.py game
|
||
- name: Мод
|
||
run: |
|
||
rustup target add wasm32-unknown-unknown
|
||
python tools/airdef.py mod
|
||
New-Item -ItemType Directory -Force out | Out-Null
|
||
Copy-Item airdef-mod\target\horizon-mod\airdef.hmod out\
|
||
- name: Архив
|
||
run: |
|
||
$D = "airdef-windows-x86_64"
|
||
New-Item -ItemType Directory -Force $D | Out-Null
|
||
Copy-Item horizon\target\fast\horizon-client.exe, horizon\target\fast\horizon-ctl.exe, out\airdef.hmod, dist\play.bat, docs\INSTALL.md $D
|
||
Compress-Archive -Path $D -DestinationPath "out\$D.zip" -Force
|
||
- name: В релиз
|
||
env:
|
||
TOKEN: ${{ secrets.RELEASE_TOKEN || gitea.token }}
|
||
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||
run: |
|
||
# RELEASE_ID взят в шаге «Проверка релиза» (релиз build-N, созданный build.yml)
|
||
curl.exe -sf -X POST -H "Authorization: token $env:TOKEN" -F "attachment=@out\airdef-windows-x86_64.zip" "$env:API/releases/$env:RELEASE_ID/assets?name=airdef-windows-x86_64.zip"
|
||
|