ci: release workflow (TICKET-390)
.gitea/workflows/release.yml: every push and pull request runs the three builds with their gates (windows on the self-hosted unity-windows runner through build/windows.ps1; linux and android in Docker on ubuntu-latest through build/linux.sh and build/android.sh) and publishes nothing. A v* tag adds the release job: every platform's engine.json must name the tag and agree on protocol and capabilities, the Windows DLL's ygol_engine_version() must return the tag, the release must not exist yet; then one release named after the tag with ygol-engine-win64.zip, ygol-engine-linux-x64.tar.gz, ygoserver-linux-x64.tar.gz, ygol-engine-android-arm64.tar.gz and engine.json, the CHANGELOG section for the tag as its body. The Windows runner runs no JavaScript action (the Unity repo's pipeline never did): its bundle is staged on the runner's disk and attached by the last job; its engine.json travels as a job output. The token is the run's own GITHUB_TOKEN (the release is in this repo). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DJUFwdiGCHipsxLkgxssSR
This commit is contained in:
1 parent
3f2e2c3e72
commit
5f25c6de7a
1 file changed
+208
@@ -0,0 +1,208 @@
|
||||
# Every push and pull request: the three builds and their gates (Windows on the self-hosted
|
||||
# unity-windows runner, Linux + Android in Docker on ubuntu-latest). A v* tag adds the release:
|
||||
# one Gitea release named after the tag with the per-platform bundles, engine.json and the
|
||||
# CHANGELOG section for that version as the body. A gate failure in any build means no release.
|
||||
#
|
||||
# ygol-engine-win64.zip ygol-engine.dll, ygol-engine.pdb, engine.json
|
||||
# ygol-engine-linux-x64.tar.gz libygol-engine.so, engine.json
|
||||
# ygoserver-linux-x64.tar.gz ygoserver, engine.json
|
||||
# ygol-engine-android-arm64.tar.gz libygol-engine.so, engine.json
|
||||
# engine.json the same content as in every bundle
|
||||
#
|
||||
# The Windows runner runs no JavaScript action (the Unity repo's pipeline never did): its build
|
||||
# stays on the runner's disk and is attached by the last job; its engine.json travels as a job
|
||||
# output. The token is the run's own GITHUB_TOKEN; the release is in this repo.
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['**']
|
||||
tags: ['v*']
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
CHECKOUT_DIR: C:\gitea-runner\checkout\yugioh-legacy-engine
|
||||
OUT_DIR: C:\gitea-runner\release-out\ygol-engine
|
||||
API: https://gitea.dev.blueoceanswim.com/api/v1/repos/donny/yugioh-legacy-engine
|
||||
|
||||
jobs:
|
||||
windows:
|
||||
runs-on: unity-windows
|
||||
defaults:
|
||||
run:
|
||||
shell: powershell
|
||||
outputs:
|
||||
engine: ${{ steps.build.outputs.engine }}
|
||||
steps:
|
||||
- name: Sync checkout
|
||||
run: |
|
||||
$url = "https://gitea-actions:${{ secrets.GITHUB_TOKEN }}@gitea.dev.blueoceanswim.com/donny/yugioh-legacy-engine.git"
|
||||
if (-not (Test-Path "$env:CHECKOUT_DIR\.git")) {
|
||||
git clone $url $env:CHECKOUT_DIR
|
||||
if ($LASTEXITCODE -ne 0) { git clone $url $env:CHECKOUT_DIR }
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
}
|
||||
Set-Location $env:CHECKOUT_DIR
|
||||
git remote set-url origin $url
|
||||
git fetch --force --tags origin
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
git checkout --force $env:GITHUB_SHA
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
git clean -fdx -e out
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
|
||||
- name: Build (contract check, export gate 334, engine.json)
|
||||
id: build
|
||||
run: |
|
||||
$version = "local"
|
||||
if ($env:GITHUB_REF -like "refs/tags/v*") { $version = $env:GITHUB_REF_NAME }
|
||||
try { & "$env:CHECKOUT_DIR\build\windows.ps1" -Version $version }
|
||||
catch { Write-Host "##[error]$_"; exit 1 }
|
||||
$out = "$env:CHECKOUT_DIR\out\win64"
|
||||
# the DLL must answer the tag
|
||||
$got = python -c "import ctypes; l = ctypes.CDLL(r'$out\ygol-engine.dll'); l.ygol_engine_version.restype = ctypes.c_char_p; print(l.ygol_engine_version().decode())"
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
Write-Host "ygol_engine_version() = $got"
|
||||
if ($got -ne $version) { Write-Host "##[error]ygol_engine_version() returned '$got', expected '$version'"; exit 1 }
|
||||
$engine = (Get-Content "$out\engine.json" -Raw | ConvertFrom-Json | ConvertTo-Json -Compress)
|
||||
"engine=$engine" | Out-File -Append -Encoding ascii $env:GITHUB_OUTPUT
|
||||
# stage the bundle on the runner's disk for the attach job
|
||||
$stage = "$env:OUT_DIR\$version"
|
||||
if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
|
||||
New-Item -ItemType Directory -Force -Path $stage | Out-Null
|
||||
Copy-Item "$out\ygol-engine.dll", "$out\ygol-engine.pdb", "$out\engine.json" $stage
|
||||
tar.exe -a -cf "$stage\ygol-engine-win64.zip" -C $stage ygol-engine.dll ygol-engine.pdb engine.json
|
||||
if ($LASTEXITCODE -ne 0) { exit 1 }
|
||||
Get-ChildItem $stage | Format-Table Name, Length
|
||||
|
||||
linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build (contract check, export gate 855, engine.json)
|
||||
run: |
|
||||
version=local
|
||||
case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac
|
||||
./build/linux.sh "$version"
|
||||
cd out/linux-x64
|
||||
tar czf ygol-engine-linux-x64.tar.gz libygol-engine.so engine.json
|
||||
tar czf ygoserver-linux-x64.tar.gz ygoserver engine.json
|
||||
ls -l
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: linux-x64
|
||||
path: |
|
||||
out/linux-x64/ygol-engine-linux-x64.tar.gz
|
||||
out/linux-x64/ygoserver-linux-x64.tar.gz
|
||||
out/linux-x64/engine.json
|
||||
if-no-files-found: error
|
||||
|
||||
android:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build (contract check, export gate 849, engine.json)
|
||||
run: |
|
||||
version=local
|
||||
case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac
|
||||
./build/android.sh "$version"
|
||||
cd out/android-arm64
|
||||
tar czf ygol-engine-android-arm64.tar.gz libygol-engine.so engine.json
|
||||
ls -l
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android-arm64
|
||||
path: |
|
||||
out/android-arm64/ygol-engine-android-arm64.tar.gz
|
||||
out/android-arm64/engine.json
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
needs: [windows, linux, android]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
id: ${{ steps.create.outputs.id }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: dist
|
||||
- name: engine.json agrees on every platform and names the tag
|
||||
env:
|
||||
WINDOWS_ENGINE: ${{ needs.windows.outputs.engine }}
|
||||
run: |
|
||||
set -eu
|
||||
tag="$GITHUB_REF_NAME"
|
||||
for f in dist/linux-x64/engine.json dist/android-arm64/engine.json; do
|
||||
v=$(jq -r .version "$f"); [ "$v" = "$tag" ] || { echo "::error::$f says version $v, tag is $tag"; exit 1; }
|
||||
done
|
||||
echo "$WINDOWS_ENGINE" | jq -c . > dist/engine-windows.json
|
||||
[ "$(jq -r .version dist/engine-windows.json)" = "$tag" ] || { echo "::error::Windows engine.json does not say $tag"; exit 1; }
|
||||
# the export count is per platform; protocol and capabilities must agree everywhere
|
||||
for f in dist/engine-windows.json dist/linux-x64/engine.json dist/android-arm64/engine.json; do
|
||||
jq -c '{version, protocol, capabilities}' "$f"
|
||||
done | sort -u | tee dist/agree.txt
|
||||
[ "$(wc -l < dist/agree.txt)" -eq 1 ] || { echo "::error::the platforms disagree on version / protocol / capabilities"; exit 1; }
|
||||
cp dist/linux-x64/engine.json dist/engine.json
|
||||
- name: The CHANGELOG section for this version is the release body
|
||||
run: |
|
||||
set -eu
|
||||
tag="$GITHUB_REF_NAME"
|
||||
awk -v tag="$tag" '
|
||||
/^## / { on = ($2 == tag); next }
|
||||
on { print }' CHANGELOG.md > dist/body.md
|
||||
[ -s dist/body.md ] || { echo "::error::CHANGELOG.md has no '## $tag' section"; exit 1; }
|
||||
cat dist/body.md
|
||||
- name: Create the release (refused if it already exists) and attach the Linux and Android assets
|
||||
id: create
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
tag="$GITHUB_REF_NAME"
|
||||
code=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: token $TOKEN" "$API/releases/tags/$tag")
|
||||
[ "$code" = "404" ] || { echo "::error::release $tag already exists (http $code); a bad release gets a new patch tag, never a re-upload"; exit 1; }
|
||||
jq -n --arg tag "$tag" --rawfile body dist/body.md \
|
||||
'{tag_name: $tag, target_commitish: env.GITHUB_SHA, name: $tag, body: $body, draft: false, prerelease: false}' > dist/release.json
|
||||
curl -sS -f -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary @dist/release.json "$API/releases" > dist/created.json
|
||||
id=$(jq -r .id dist/created.json)
|
||||
echo "release id $id"
|
||||
echo "id=$id" >> "$GITHUB_OUTPUT"
|
||||
for f in dist/linux-x64/ygol-engine-linux-x64.tar.gz dist/linux-x64/ygoserver-linux-x64.tar.gz \
|
||||
dist/android-arm64/ygol-engine-android-arm64.tar.gz dist/engine.json; do
|
||||
name=$(basename "$f")
|
||||
echo "uploading $name"
|
||||
curl -sS -f -o /dev/null -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" "$API/releases/$id/assets?name=$name"
|
||||
done
|
||||
echo "https://gitea.dev.blueoceanswim.com/donny/yugioh-legacy-engine/releases/tag/$tag"
|
||||
|
||||
attach-windows:
|
||||
needs: [windows, release]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: unity-windows
|
||||
defaults:
|
||||
run:
|
||||
shell: powershell
|
||||
steps:
|
||||
- name: Attach ygol-engine-win64.zip
|
||||
run: |
|
||||
$tag = $env:GITHUB_REF_NAME
|
||||
$zip = "$env:OUT_DIR\$tag\ygol-engine-win64.zip"
|
||||
if (-not (Test-Path $zip)) { Write-Host "##[error]$zip is missing"; exit 1 }
|
||||
$id = "${{ needs.release.outputs.id }}"
|
||||
$respFile = Join-Path $env:TEMP "ygol-engine-upload.txt"
|
||||
$status = & curl.exe -s -o $respFile -w "%{http_code}" -X POST `
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -F "attachment=@$zip" `
|
||||
"$env:API/releases/$id/assets?name=ygol-engine-win64.zip"
|
||||
if ($LASTEXITCODE -ne 0 -or [int]$status -ge 400) {
|
||||
Write-Host "curl exit=$LASTEXITCODE http=$status"
|
||||
if (Test-Path $respFile) { Get-Content $respFile -TotalCount 20 }
|
||||
exit 1
|
||||
}
|
||||
Write-Host "attached ygol-engine-win64.zip to release $id ($tag)"
|
||||
Reference in new issue
Block a user