diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 00000000..04c44a93 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,294 @@ +name: release + +# Tag-driven releases: pushing a `reVC-vX.Y.Z` tag (or running this workflow +# manually with a `version` input) builds the Linux x64 GL3+OpenAL binary, packages +# it with the gamefiles/ overlay and INSTALL.md, and publishes a Gitea release with +# the zip attached. Requires the runner's GITEA_TOKEN (or GITHUB_TOKEN) to have +# repository write access for tags/releases. + +on: + push: + tags: + - 'reVC-v*' + workflow_dispatch: + inputs: + version: + description: 'Version to release, e.g. 1.0.1 (creates the tag at the branch HEAD if missing)' + required: false + default: '' + +concurrency: + group: release-${{ gitea.ref }} + cancel-in-progress: false + +env: + GITEA_API: https://git.thetomie.com/api/v1 + REPO_FULL: rockstargames/re3 + +jobs: + release: + runs-on: ubuntu-latest + # Same pin as linux.yml: the runner's default image fails to extract on the + # runner host, and this image ships node20 (checkout@v4), python3 and zip. + container: + image: ghcr.io/catthehacker/ubuntu:act-24.04 + options: --user root + steps: + # Recursive submodules are required: vendor/librw, vendor/ogg, vendor/opus and + # vendor/opusfile are git submodules. fetch-depth: 0 keeps the full history and + # tags, which the changelog below needs. + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + # act_runner images run as root without sudo; install directly. `zip` and + # `python3` are added on top of the linux.yml list: zip builds the release + # archive, python3 builds/parses the JSON API payloads. Both are present in + # the catthehacker image but pinning them keeps the step self-contained. + - name: Install build deps + run: | + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ + cmake \ + ninja-build \ + pkg-config \ + file \ + zip \ + python3 \ + libglfw3-dev \ + libopenal-dev \ + libsndfile1-dev \ + libmpg123-dev \ + libgl-dev + + # Resolve TAG/VER from either the tag push or the manual version input and + # export them to later steps. The dispatch input is injected via step env so + # this script contains no `${{ }}` expressions and stays bash -n clean. + - name: Resolve tag + env: + DISPATCH_VERSION: ${{ gitea.event.inputs.version }} + run: | + set -euo pipefail + INPUT="${DISPATCH_VERSION:-}" + TAG="" + if [ -n "$INPUT" ]; then + if ! [[ "$INPUT" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "error: version input '$INPUT' is not X.Y.Z" >&2 + exit 1 + fi + TAG="reVC-v${INPUT}" + elif [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then + # GITHUB_REF_NAME may not be set by every act_runner version; fall back + # to stripping the prefix from GITHUB_REF. + TAG="${GITHUB_REF_NAME:-${GITHUB_REF#refs/tags/}}" + else + echo "error: release requires either a reVC-v* tag push or a version input" >&2 + exit 1 + fi + if [[ ! "$TAG" =~ ^reVC-v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "error: resolved tag '$TAG' does not match reVC-vX.Y.Z" >&2 + exit 1 + fi + VER="${TAG#reVC-v}" + echo "TAG=$TAG" >> "$GITHUB_ENV" + echo "VER=$VER" >> "$GITHUB_ENV" + echo "Releasing $TAG (version $VER)" + + # On a tag push the tag is already checked out, so this is a no-op. On a + # workflow_dispatch run the tag may not exist yet: create it via the API at + # the current HEAD, treat 409 (already exists) as success, then fetch it. + - name: Ensure tag exists + run: | + set -euo pipefail + AUTH="Authorization: token ${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" + if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then + echo "tag $TAG is already present locally" + else + echo "tag $TAG missing locally; creating it via the Gitea API" + CODE=$(curl -sS -o /tmp/tag.json -w '%{http_code}' -X POST \ + "$GITEA_API/repos/$REPO_FULL/tags" \ + -H "$AUTH" -H 'Content-Type: application/json' \ + -d "{\"tag_name\": \"$TAG\", \"target\": \"$(git rev-parse HEAD)\", \"message\": \"reVC v$VER\"}") + case "$CODE" in + 200|201) + echo "created tag $TAG" + ;; + 409) + echo "tag $TAG already exists on the server; continuing" + ;; + *) + echo "error: tag API returned $CODE" >&2 + cat /tmp/tag.json >&2 || true + exit 1 + ;; + esac + fi + # Workspace is disposable: force-fetch the tag so the checkout has it. + git fetch --force origin "refs/tags/$TAG:refs/tags/$TAG" + + # GL3 renderer via vendored librw + OpenAL audio = the documented Linux configuration. + - name: Configure + run: | + cmake -S . -B build -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DREVC_AUDIO=OAL \ + -DREVC_VENDORED_LIBRW=True \ + -DLIBRW_PLATFORM=GL3 \ + -DLIBRW_GL3_GFXLIB=GLFW + + # No -Werror: this legacy codebase warns, and warnings must not fail the build. + - name: Build + run: | + cmake --build build --parallel "$(nproc)" + + # Locate the binary (known path first, find fallback) and export it for the + # packaging step. + - name: Smoke check + run: | + set -euo pipefail + BIN=build/src/reVC + if [ ! -x "$BIN" ]; then + BIN="$(find build -type f -name reVC -perm -u+x | head -1 || true)" + fi + if [ -z "$BIN" ]; then + echo "error: no reVC executable found under build/" >&2 + find build -maxdepth 3 -type f | sort >&2 || true + exit 1 + fi + file "$BIN" + echo "BIN=$BIN" >> "$GITHUB_ENV" + + # Package: binary + the gamefiles/ overlay + an INSTALL.md, zipped at the root + # of the workspace so the next steps can attach it directly. + - name: Package + run: | + set -euo pipefail + mkdir -p pkg + cp "$BIN" pkg/reVC + cp -r gamefiles/. pkg/ + cat > pkg/INSTALL.md <<'EOF' + # reVC — Linux x64 (GL3 + OpenAL) + + This is reVC, a reverse-engineered source port of Grand Theft Auto: Vice City. + It is **not** a standalone game and ships **no game assets**. + + **No license.** The code is provided for educational, documentation and + modding purposes only. Do not sell it or any derivative; keep derivative + work open source and give proper credit. You must own GTA Vice City legally. + + ## Requirements + + * A legally-owned installation of **Grand Theft Auto: Vice City** (PC). + * An OpenGL 3 capable GPU/driver with GLFW. + * Runtime libraries (Debian/Ubuntu): + `sudo apt install libopenal1 libsndfile1 libmpg123-0 libglfw3 libgl1` + + ## Install + + 1. Extract this zip over your GTA Vice City installation directory, so the `reVC` + binary lands next to `data/`, `models/`, `audio/`, `TEXT/` and `movies/`. + The `gamefiles/` overlay is already merged into this archive. + 2. Run `./reVC` from that directory. + + ## Notes + + * Settings are written to `reVC.ini` next to the binary; saved games go to + the `userfiles/` directory created next to it. + * Ctrl+M opens the debug menu; the build's version string is shown there. + EOF + cd pkg + zip -r "../reVC-v$VER-linux-x64-gl3-oal.zip" . + + # Compose release notes from the tag range and create-or-update the Gitea + # release. JSON is produced by python3 so the changelog is escaped safely. + - name: Release notes + publish + run: | + set -euo pipefail + AUTH="Authorization: token ${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" + PREV=$(git tag -l 'reVC-v*' --sort=-v:refname | grep -vx "$TAG" | head -n1 || true) + if [ -z "$PREV" ]; then + PREV="reVC_1.0" + fi + CHANGELOG=$(git log --oneline --no-decorate "$PREV..$TAG" 2>/dev/null | head -n 200 || echo "(first release under this scheme)") + + { + echo "reVC v$VER — stable continuation of the upstream reVC_1.0 baseline" + echo + echo "## Changes since $PREV" + echo + printf '%s\n' "$CHANGELOG" + echo + echo "## Install" + echo + echo "You need a legally-owned Grand Theft Auto: Vice City installation." + echo "Extract \`reVC-v$VER-linux-x64-gl3-oal.zip\` over your GTA VC directory (the \`reVC\` binary lands next to the game data), then run \`./reVC\`." + echo + echo "Runtime deps (Debian/Ubuntu): \`sudo apt install libopenal1 libsndfile1 libmpg123-0 libglfw3 libgl1\`." + echo + echo "Settings go to \`reVC.ini\` next to the binary; saves go to \`userfiles/\`. Ctrl+M opens the debug menu (version string there)." + } > notes.md + + python3 - "$TAG" "$(git rev-parse HEAD)" "reVC v$VER" notes.md > payload.json <<'PY' + import json + import sys + + tag, target, name, notes_path = sys.argv[1:5] + with open(notes_path, encoding="utf-8") as f: + body = f.read() + + json.dump({ + "tag_name": tag, + "target_commitish": target, + "name": name, + "body": body, + "draft": False, + "prerelease": False, + }, sys.stdout) + PY + + RID=$(curl -sS "$GITEA_API/repos/$REPO_FULL/releases/tags/$TAG" -H "$AUTH" \ + | python3 -c 'import json, sys; print(json.load(sys.stdin).get("id", ""))' 2>/dev/null || true) + if [ -n "$RID" ]; then + curl -fsS -X PATCH "$GITEA_API/repos/$REPO_FULL/releases/$RID" \ + -H "$AUTH" -H 'Content-Type: application/json' -d @payload.json -o /dev/null + echo "updated existing release $RID" + else + curl -fsS -X POST "$GITEA_API/repos/$REPO_FULL/releases" \ + -H "$AUTH" -H 'Content-Type: application/json' -d @payload.json -o /tmp/release.json + RID=$(python3 -c 'import json; print(json.load(open("/tmp/release.json"))["id"])') + echo "created release $RID" + fi + echo "RID=$RID" >> "$GITHUB_ENV" + + # Attach the zip. If a same-named asset already exists (release re-run), + # delete it and retry once so re-runs are idempotent. + - name: Attach zip + run: | + set -euo pipefail + AUTH="Authorization: token ${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" + ASSET="reVC-v$VER-linux-x64-gl3-oal.zip" + URL="$GITEA_API/repos/$REPO_FULL/releases/$RID/assets?name=$ASSET" + CODE=$(curl -sS -o /tmp/asset.json -w '%{http_code}' -X POST "$URL" \ + -H "$AUTH" -F "attachment=@$ASSET") + if [ "$CODE" = "200" ] || [ "$CODE" = "201" ]; then + echo "uploaded asset $ASSET" + else + echo "asset upload returned $CODE; looking for an existing asset to replace" + AID=$(curl -sS "$GITEA_API/repos/$REPO_FULL/releases/$RID/assets" -H "$AUTH" \ + | python3 -c 'import json, sys; print(next((a["id"] for a in json.load(sys.stdin) if a.get("name") == sys.argv[1]), ""))' "$ASSET" 2>/dev/null || true) + if [ -z "$AID" ]; then + echo "error: could not upload asset (HTTP $CODE)" >&2 + cat /tmp/asset.json >&2 || true + exit 1 + fi + curl -fsS -X DELETE "$GITEA_API/repos/$REPO_FULL/releases/$RID/assets/$AID" -H "$AUTH" + curl -fsS -X POST "$URL" -H "$AUTH" -F "attachment=@$ASSET" -o /dev/null + echo "replaced existing asset $ASSET" + fi + + - name: Done + run: | + echo "Release published: https://git.thetomie.com/rockstargames/re3/releases/tag/$TAG"