Files
2026-10-19 18:19:14 -07:00

74 lines
3.4 KiB
YAML

# Every push and pull request: build the library and both arenas and run the tests, all in Docker (Dockerfile,
# target dist, which runs the test stage first). A v* tag adds the release: one Gitea release named after the
# tag, the CHANGELOG section for that version as the body, and
#
# bots-lib.zip YGOLegacy.Bots.dll, YGOLegacy.Bots.pdb, bots.json (what the game references)
# bot-arena-linux-x64.tar.gz bot-arena-linux-x64/: BotArena (self-contained), libygol-engine.so, the binding, bots.json
# bot-arena-win-x64.zip bot-arena-win-x64/: BotArena.exe (self-contained), ygol-engine.dll, the binding, bots.json
# bots.json { version, engine }: this release and the engine release it was built and tested on
#
# A failing build or test means no release. The token is the run's own GITHUB_TOKEN; the release is in this repo.
name: CI
on:
push:
branches: ['**']
tags: ['v*']
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: false
env:
API: https://gitea.dev.blueoceanswim.com/api/v1/repos/donny/yugioh-legacy-bots
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build, test and pack (library, linux-x64 and win-x64 arenas, the tests)
run: |
set -eu
version=local
case "$GITHUB_REF" in refs/tags/v*) version="$GITHUB_REF_NAME";; esac
DOCKER_BUILDKIT=1 docker build --progress=plain --target release --build-arg "BOTS_VERSION=$version" -o dist .
ls -l dist
cat dist/bots.json
- name: The CHANGELOG section for this version is the release body
if: startsWith(github.ref, 'refs/tags/v')
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 assets
if: startsWith(github.ref, 'refs/tags/v')
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"
for f in dist/bots-lib.zip dist/bot-arena-linux-x64.tar.gz dist/bot-arena-win-x64.zip dist/bots.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-bots/releases/tag/$tag"