diff --git a/.github/workflows/desktop-binaries.yml b/.github/workflows/desktop-binaries.yml index 45de621..f0f6bc1 100644 --- a/.github/workflows/desktop-binaries.yml +++ b/.github/workflows/desktop-binaries.yml @@ -7,8 +7,12 @@ name: Desktop binaries # Each job produces exactly the file GameAnalyticsExt.yy expects: # macos-universal libGameAnalytics.dylib (x86_64 + arm64) # linux-x64 libGameAnalytics.so -# windows-x64 GameAnalytics_x64.dll -# windows-x86 GameAnalytics.dll +# windows-x64 GameAnalytics.dll (64-bit) +# +# 32-bit Windows was dropped: it never built (the DLL's import library +# collided with the C++ SDK's GameAnalytics.lib, LNK1149) and GameMaker's +# Windows target is x64. The extension declares one Windows library, named +# GameAnalytics.dll, and this is it. # # Collect them with ./fetch_desktop_binaries.py, or by hand: # gh run download -n desktop-binaries -D sample/extensions/GameAnalyticsExt @@ -18,12 +22,9 @@ on: workflow_dispatch: inputs: sdk_ref: - description: "gameanalytics-sdk-cpp ref to build against" - required: true - # Pinned to the commit that builds the static library with -fPIC, which - # the Linux .so link needs. v5.4.1 predates it, so the tag will NOT - # work. Move this to a release tag once that change is merged. - default: "424a87d77c7d9cc9a686e0b2484f52005145e723" + description: "override the gameanalytics-sdk-cpp ref (default: dependencies.json)" + required: false + default: "" pull_request: paths: - "sample/extensions/GameAnalyticsExt/DesktopSource/**" @@ -34,12 +35,43 @@ on: - "sample/extensions/GameAnalyticsExt/DesktopSource/**" - ".github/workflows/desktop-binaries.yml" -env: - # Used when the workflow is triggered by push/PR, where inputs are unset. - DEFAULT_SDK_REF: "424a87d77c7d9cc9a686e0b2484f52005145e723" - jobs: + # The ref lives in dependencies.json so that CI, the local build and + # ./download_externals.py cannot disagree about which C++ SDK is being built. + # It is resolved once here rather than in each matrix job, so every + # library is guaranteed to come from the same source revision. + dependency: + name: resolve C++ SDK ref + runs-on: ubuntu-latest + outputs: + sdk_ref: ${{ steps.resolve.outputs.sdk_ref }} + steps: + - uses: actions/checkout@v4 + + - name: Read the pinned ref + id: resolve + shell: bash + run: | + OVERRIDE="${{ github.event.inputs.sdk_ref }}" + if [ -n "$OVERRIDE" ]; then + REF="$OVERRIDE" + ORIGIN="workflow_dispatch input" + else + # A 'ref' in dependencies.json wins over 'version': the tag + # v5.4.1 builds the static library without -fPIC and the Linux .so + # then fails to link, so the pin is currently a commit past it. + REF=$(python3 -c 'import json; d=json.load(open("dependencies.json")); c=next(x for x in d if x["name"]=="GA-SDK-CPP"); print(c.get("ref") or "v"+c["version"])') + ORIGIN="dependencies.json" + fi + if [ -z "$REF" ]; then + echo "::error::could not determine a GA-SDK-CPP ref" + exit 1 + fi + echo "sdk_ref=$REF" >> "$GITHUB_OUTPUT" + echo "Building against gameanalytics-sdk-cpp $REF (from $ORIGIN)" + build: + needs: dependency name: ${{ matrix.name }} runs-on: ${{ matrix.os }} strategy: @@ -59,11 +91,6 @@ jobs: os: windows-2022 cmake_arch: x64 vcpkg_triplet: x64-windows-static-md - artifact: GameAnalytics_x64.dll - - name: windows-x86 - os: windows-2022 - cmake_arch: Win32 - vcpkg_triplet: x86-windows-static-md artifact: GameAnalytics.dll steps: @@ -74,7 +101,7 @@ jobs: uses: actions/checkout@v4 with: repository: GameAnalytics/gameanalytics-sdk-cpp - ref: ${{ github.event.inputs.sdk_ref || env.DEFAULT_SDK_REF }} + ref: ${{ needs.dependency.outputs.sdk_ref }} path: sdk-cpp submodules: recursive @@ -181,8 +208,8 @@ jobs: with: path: staging - # One artifact holding all four libraries, laid out so it can be unzipped - # straight over sample/extensions/GameAnalyticsExt/. + # One artifact holding all three libraries, laid out so it can be + # unzipped straight over sample/extensions/GameAnalyticsExt/. - name: Flatten run: | mkdir -p desktop-binaries diff --git a/.gitignore b/.gitignore index 62a1463..0798a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,17 +16,21 @@ google-services.json GoogleService-Info.plist -# Internal release tooling and planning documents. The public SDK is built by -# the workflow in .github/workflows; the publishing script that pushes to the -# Marketplace and the sister repositories is not part of it. +# Internal release tooling and planning documents. The publishing script that +# pushed to the Marketplace and the sister repositories belonged to the +# development repo; ./publish_release.py replaces it here. publish_gamemaker_release.py + +# Unpublished write-ups. These now live in internal/docs/, which the rule below +# already covers — kept as explicit guards so a `docs/` directory reappearing +# at the root cannot pull them into the public tree. docs/release-readiness.md docs/superpowers/ # Working notes and agent context. `internal/` is scratch space that never -# ships; CLAUDE.md is the context file Claude Code loads on open. Both describe -# how this repo relates to the internal development repo, so neither belongs in -# a public tree. +# ships and holds the repo-wide Claude Code context, the binding checker, the +# unpublished write-ups and the release credentials. The bare CLAUDE.md entries +# stay so that a copy reappearing at the root is ignored too. internal/ CLAUDE.md CLAUDE.local.md @@ -77,6 +81,12 @@ CMakeFiles/ # Windows/vcpkg vcpkg_installed/ +# Upstream SDK sources fetched by ./download_externals.py. A checkout of +# another repository, at the version dependencies.json pins — not ours to +# track. Scoped to this one directory rather than a pattern, so it cannot +# catch a shipped library. +/external/ + # The extension's shipped native libraries are release artifacts and must always # be tracked. Kept explicit so a future build-output rule cannot silently drop # one — an extension missing a library still loads, and only fails when a game diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5e29e..d00227d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,15 +3,25 @@ All notable changes to the GameAnalytics GameMaker SDK. -**4.1.0** +**5.0.0** + +Breaking: +* 32-bit Windows is no longer supported, and `GameAnalytics_x64.dll` is gone — the Windows library is `GameAnalytics.dll` and is 64-bit +* the SDK is three resources, not two: `obj_gameanalytics` ships alongside the extension and the scripts + +Added: * rewrote the GML wrapper as a single `GameAnalytics.gml` that dispatches per platform * added `customFields` / `mergeFields` to every event function * added remote config and A/B testing getters: `ga_is_remote_configs_ready`, `ga_get_remote_configs_content`, `ga_get_ab_testing_id`, `ga_get_ab_testing_variant_id` * added `ga_get_user_id` and `ga_get_external_user_id` -* rebuilt the macOS native library from the current C++ SDK, fixing an out-of-bounds read in the `add*EventJson` entry points that could crash the game -* desktop uploads now go through GameMaker's own HTTP stack (`ga_http_pump` / `ga_http_handle_async` / `ga_http_abort`), removing the cURL and OpenSSL dependency * added a runnable sample project covering every event type -* added CI that builds and export-checks all four desktop libraries +* added CI that builds and export-checks every desktop library +* added `dependencies.json`, recording the upstream SDK version behind each shipped artifact + +Changed: +* rebuilt all three desktop libraries from the current C++ SDK, fixing an out-of-bounds read in the `add*EventJson` entry points that could crash the game — previously only macOS had been rebuilt +* desktop uploads go through GameMaker's own HTTP stack, removing the cURL and OpenSSL dependency +* `ga_initialize()` now starts the desktop HTTP bridge itself; `ga_http_pump`, `ga_http_handle_async` and `ga_http_abort` are no longer something you wire up, and remain public and safe to call -Releases before 4.1.0 were published from the previous repository and are not +Releases before 5.0.0 were published from the previous repository and are not reproduced here. diff --git a/README.md b/README.md index 4d75e10..52732b0 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ support team [here](https://gameanalytics.com/contact). |-------------|-----------------------------------------------------------| | Android | `com.gameanalytics.sdk:gameanalytics-android` (via Gradle) | | iOS | `libGameAnalytics.a` | -| Windows x86 | `GameAnalytics.dll` | -| Windows x64 | `GameAnalytics_x64.dll` | +| Windows x64 | `GameAnalytics.dll` | | macOS | `libGameAnalytics.dylib` | | Linux x64 | `libGameAnalytics.so` | | HTML5 | `GameAnalytics.js` | @@ -24,7 +23,7 @@ declares a Gradle dependency, so the Android SDK is fetched from `maven.gameanalytics.com` when your project builds. Not every call is implemented on every platform — see -[Platform support](#platform-support) and [Known issues](#known-issues). +[Platform support](#platform-support). ## Requirements @@ -33,19 +32,23 @@ Not every call is implemented on every platform — see ## Installation -The SDK is two resources inside the sample project: +The SDK is three resources inside the sample project: - `sample/extensions/GameAnalyticsExt` — the extension: native libraries, the platform bridges and the function declarations. - `sample/scripts/GameAnalytics` — `GameAnalytics.gml`, the cross-platform GML API that dispatches to whichever backend the current platform uses. +- `sample/objects/obj_gameanalytics` — drives the desktop HTTP bridge. + `ga_initialize()` creates it; you never reference it yourself. -Copy both into your own project, or open `sample/sample.yyp`, select the two -resources and use **Tools → Create Local Package** to make a `.yymps` you can -import elsewhere. +Copy all three into your own project, or open `sample/sample.yyp`, select them +and use **Tools → Create Local Package** to make a `.yymps` you can import +elsewhere. -You need both. The script calls the extension's declared functions directly, so -importing the extension on its own leaves you with raw per-platform bindings. +The script calls the extension's declared functions directly, so importing the +extension on its own leaves you with raw per-platform bindings. Leaving out +`obj_gameanalytics` costs you desktop uploads — the SDK logs a message saying +so at `ga_initialize()` rather than failing silently. ### Android @@ -74,27 +77,6 @@ ga_on_quit(); Your game key and secret are on your game's Settings page on [gameanalytics.com](https://gameanalytics.com). -### Desktop: you must pump the HTTP client - -On desktop the native library routes its uploads through GameMaker's own -`http_request` rather than linking cURL and OpenSSL. That needs driving from -GML — **without these two calls nothing your game records is ever submitted**: - -```gml -// Step event -ga_http_pump(); - -// Async HTTP event -ga_http_handle_async(); - -// Game End event, so shutdown doesn't wait out the request timeout -ga_http_abort(); -``` - -Both are no-ops on platforms whose native SDK does its own networking, so it is -safe to call them unconditionally. `sample/objects/obj_controller` shows the -wiring. - ## API reference All functions live in `scripts/GameAnalytics/GameAnalytics.gml`. @@ -214,12 +196,22 @@ ga_get_external_user_id() // String ### Desktop HTTP bridge +On desktop the native library routes its uploads through GameMaker's own +`http_request` rather than linking cURL and OpenSSL, which needs an instance to +receive the Async HTTP event. `ga_initialize()` creates `obj_gameanalytics` for +that, so there is nothing to wire up. + ```gml ga_http_pump() // Step event ga_http_handle_async() // Async HTTP event ga_http_abort() // Game End event ``` +These stay public so a game can drive the bridge from its own object instead, +for example to issue requests on a different schedule. Calling them as well as +`obj_gameanalytics` is harmless: whichever comes first in a step claims the +queued request and the other finds nothing. + ## Platform support Calls with no native implementation on a platform are safe no-ops — they log a @@ -230,12 +222,13 @@ supported everywhere. |----------|--------------| | `ga_add_ad_event`, `..._with_duration`, `..._with_reason` | Android, iOS, HTML5 | | `ga_set_error_reporting` | Windows, macOS, Linux | -| `ga_configure_external_user_id` | Android, iOS, HTML5, macOS | -| `ga_get_user_id`, `ga_get_external_user_id` | macOS | -| `ga_http_pump`, `ga_http_handle_async`, `ga_http_abort` | macOS | +| `ga_configure_external_user_id` | Android, iOS, HTML5, Windows, macOS, Linux | +| `ga_get_user_id`, `ga_get_external_user_id` | Windows, macOS, Linux | +| `ga_http_pump`, `ga_http_handle_async`, `ga_http_abort` (optional) | Windows, macOS, Linux | -The macOS-only rows are a consequence of [Known issues](#known-issues) — they -extend to Windows and Linux as soon as those libraries are rebuilt. +The last three are desktop-only by design: they exist because the desktop +extension routes the SDK's HTTP through GameMaker rather than linking cURL, and +the mobile and HTML5 SDKs do their own networking. ## Sample app @@ -288,25 +281,27 @@ Two source files: - **`GameAnalyticsHttpGM.cpp`** — a `GAHttpClient` that performs the SDK's requests with GameMaker's own HTTP stack. This is what removes the cURL and OpenSSL dependency and gives one implementation for every desktop target. It - is why `ga_http_pump()` and `ga_http_handle_async()` exist. + is why `ga_http_pump()` and `ga_http_handle_async()` exist, and why + `obj_gameanalytics` is created by `ga_initialize()` — GameMaker delivers + `async_load` only to instances that define the event, so the bridge cannot + live in a script or a time source. | Where | What | |-------|------| | SDK worker thread | `sendRequest()` queues the request and blocks | - | Game thread, per step | `ga_http_pump()` issues it via `http_request` | - | Async HTTP event | `ga_http_handle_async()` returns status and body to the SDK | - | Game end | `ga_http_abort()` so shutdown doesn't wait out the timeout | + | `obj_gameanalytics`, per step | `ga_http_pump()` issues it via `http_request` | + | `obj_gameanalytics`, Async HTTP | `ga_http_handle_async()` returns status and body to the SDK | + | `obj_gameanalytics`, Game End | `ga_http_abort()` so shutdown doesn't wait out the timeout | ### CI -`.github/workflows/desktop-binaries.yml` builds all four desktop libraries: +`.github/workflows/desktop-binaries.yml` builds every desktop library: | Job | Runner | Produces | |-----|--------|----------| | `macos-universal` | macos-14 | `libGameAnalytics.dylib` (x86_64 + arm64) | | `linux-x64` | ubuntu-22.04 | `libGameAnalytics.so` | -| `windows-x64` | windows-2022 | `GameAnalytics_x64.dll` | -| `windows-x86` | windows-2022 | `GameAnalytics.dll` | +| `windows-x64` | windows-2022 | `GameAnalytics.dll` | Each job checks the export table before uploading (`.github/workflows/required-exports.txt`), because GameMaker resolves extension @@ -329,29 +324,71 @@ Two things the workflow pins deliberately: - **ubuntu-22.04, not ubuntu-latest.** The runner's glibc becomes the minimum glibc of every game that ships this library. -## Known issues - -**The Windows and Linux libraries have not been rebuilt yet.** -`GameAnalytics.dll`, `GameAnalytics_x64.dll` and `libGameAnalytics.so` are still -the February 2022 builds, which contain an out-of-bounds read in the -`add*EventJson` entry points that can crash the game. macOS has been rebuilt and -is not affected. The cause, the reproduction and the fix are written up in -[docs/native-json-event-bindings-off-by-one.md](docs/native-json-event-bindings-off-by-one.md). - -Until those libraries are replaced, on Windows and Linux: - -- `ga_add_business_event`, `ga_add_resource_event` and - `ga_add_progression_event_with_score` can crash the game. The crash depends on - heap state, so it is intermittent — a call that works at startup can fail - later in the same session. -- `ga_http_pump()` and friends are inert, because the old libraries do their own - networking and do not export the entry points the bridge needs. -- `ga_get_user_id()`, `ga_get_external_user_id()` and - `ga_configure_external_user_id()` are unavailable for the same reason. - -Design events, error events, custom dimensions, sessions and remote configs go -through bindings whose declared signature matches the shipped binary and are -unaffected. +### Upstream SDK versions + +Each platform target binds to a different GameAnalytics SDK. +`dependencies.json` records which version of each one the shipped artifacts came +from, and `./download_externals.py` brings the tree back in line with it — bump +a version there to upgrade. + +| Dependency | Version | Where it lands | +|------------|---------|----------------| +| `GA-SDK-CPP` | 5.4.1 (a later commit, see above) | `external/gameanalytics-sdk-cpp`, the source tree `DesktopSource` builds | +| `GA-SDK-JAVASCRIPT` | 4.4.5 | `GameAnalytics.js`, a drop-in replacement | +| `GA-SDK-IOS` | 4.6.10 | `iOSSource/GameAnalyticsSDK/libGameAnalytics.a` | +| `GA-SDK-ANDROID` | 7.0.1 | a Maven coordinate in `GameAnalyticsExt.yy`, resolved by Gradle | + +```bash +./download_externals.py # every dependency +./download_externals.py GA-SDK-JAVASCRIPT # just one +``` + +The first two are fetched. The last two are reported on instead: the iOS +releases publish no static library (5.x ships an `.xcframework`, which the +extension's `.yy` would have to be reworked for), and the Android version is a +coordinate rather than a file — the script checks that coordinate against the +manifest and leaves the IDE-managed `.yy` alone. + +### Releasing + +`./publish_release.py` does the mechanical half of a release: + +```bash +./publish_release.py -v 4.2.0 -c "first line::second line" +./publish_release.py -v 4.2.0 -c "..." --dry-run # report every step, change nothing +``` + +In order, it refreshes the upstream dependencies, rebuilds the desktop +libraries on CI and collects them, checks every shipped artifact is present, +bumps both version strings, asks the backend whether it accepts the new +`sdk_version`, prepends the changelog entry, zips the extension and the GML +wrapper, then commits, tags and creates the GitHub release. + +The two Marketplace steps have no API and stay manual; the script prints them +when it finishes. + +It deliberately does **not** download the old prebuilt libraries from +`download.gameanalytics.com` the way the previous script did. Those are the +February 2022 builds, which carry an out-of-bounds read in the `add*EventJson` +entry points; taking them again would reintroduce that crash. + +The backend check needs a game key and secret, which are read from a file that +is never committed — `internal/` is gitignored, and the script refuses to run if +the file has somehow become tracked: + +```bash +./publish_release.py --init-credentials # writes internal/release-credentials.env, mode 600 +``` + +``` +GA_GAME_KEY=... +GA_GAME_SECRET=... +``` + +It is used for one thing: `_sdkVersion` identifies this SDK in every event a +game sends, and a version string the backend rejects is invisible until the data +stops arriving. Without the file the check is skipped; the values are never +printed. ## Contributing diff --git a/dependencies.json b/dependencies.json new file mode 100644 index 0000000..3757529 --- /dev/null +++ b/dependencies.json @@ -0,0 +1,23 @@ +[ + { + "name": "GA-SDK-CPP", + "version": "5.4.1", + "ref": "424a87d77c7d9cc9a686e0b2484f52005145e723", + "url": "https://github.com/GameAnalytics/gameanalytics-sdk-cpp/" + }, + { + "name": "GA-SDK-JAVASCRIPT", + "version": "4.4.5", + "url": "https://github.com/GameAnalytics/GA-SDK-JAVASCRIPT/" + }, + { + "name": "GA-SDK-IOS", + "version": "4.6.10", + "url": "https://github.com/GameAnalytics/GA-SDK-IOS/" + }, + { + "name": "GA-SDK-ANDROID", + "version": "7.0.1", + "url": "https://github.com/GameAnalytics/GA-SDK-ANDROID/" + } +] diff --git a/download_externals.py b/download_externals.py new file mode 100755 index 0000000..f6233e0 --- /dev/null +++ b/download_externals.py @@ -0,0 +1,251 @@ +#!/usr/bin/env python3 +""" +Fetches the upstream GameAnalytics SDKs this extension is built on, at the +versions recorded in dependencies.json. + +The GameMaker SDK is a wrapper: each platform target binds to a different +upstream SDK, and nothing in the tree recorded which version of each one the +shipped artifacts came from. dependencies.json is that record, and this script +brings the tree back in line with it. To upgrade a dependency, bump it there +and re-run this. + + ./download_externals.py # all dependencies + ./download_externals.py GA-SDK-JAVASCRIPT # just one + +Two of the four are fetched; two are reported on, because there is nothing to +download: + + GA-SDK-CPP desktop. Extracted to external/gameanalytics-sdk-cpp as a + source tree, not a prebuilt library: DesktopSource's + CMakeLists builds the SDK itself (add_subdirectory) so it + can force GA_HTTP_USE_CURL=OFF, and GameAnalyticsHttpGM.cpp + includes GAUtilities.h, which lives under source/ and is + not in the published static-no-deps release. + GA-SDK-JAVASCRIPT HTML5. dist/GameAnalytics.min.js replaces the extension's + GameAnalytics.js verbatim — this is a drop-in. + GA-SDK-IOS reported only. The shipped fat libGameAnalytics.a was + taken from the internal binaries repository; the public + releases carry no .a at all, and 5.x publishes an + .xcframework instead, which is a packaging change the + extension's .yy would have to follow. Upgrading is a + deliberate piece of work, not a download. + GA-SDK-ANDROID reported only. Gradle resolves it from Maven at build + time, so the version is a coordinate inside + GameAnalyticsExt.yy rather than a file in the tree. This + script checks that coordinate against dependencies.json + and leaves the .yy alone — it is IDE-managed. +""" + +import json +import os +import re +import shutil +import sys +import tarfile +import tempfile +import urllib.error +import urllib.request + +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) +EXTENSION_DIR = os.path.join(ROOT_DIR, "sample", "extensions", "GameAnalyticsExt") + + +def fetch(url, dest_path): + """Downloads url to dest_path, creating parent directories as needed.""" + print(f"Downloading {url}...") + os.makedirs(os.path.dirname(dest_path), exist_ok=True) + try: + with urllib.request.urlopen(url) as response, open(dest_path, "wb") as f: + shutil.copyfileobj(response, f) + except urllib.error.URLError as e: + print(f"Error downloading file: {e}") + sys.exit(1) + + +def resolve_tag(base_url, version): + """ + Returns the tag that exists upstream for this version. + + Tag spelling is not consistent across the GameAnalytics repositories, and + not even within one: GA-SDK-JAVASCRIPT tagged 4.4.6 bare and v4.4.7 with a + prefix. Rather than encode that per repository, try both and use whichever + the server has. + """ + archive_base = base_url.rstrip("/") + "/archive/refs/tags" + for tag in (f"v{version}", version): + request = urllib.request.Request(f"{archive_base}/{tag}.tar.gz", method="HEAD") + try: + with urllib.request.urlopen(request): + return tag + except urllib.error.HTTPError: + continue + except urllib.error.URLError as e: + print(f"Error reaching {base_url}: {e}") + sys.exit(1) + + print(f"Neither tag 'v{version}' nor '{version}' exists at {base_url}") + sys.exit(1) + + +def download_cpp_sdk(sdk_info): + """ + Extracts the C++ SDK source tree to external/gameanalytics-sdk-cpp, which is + what DesktopSource's build wants as -DGA_SDK_DIR. + + A 'ref' in dependencies.json wins over 'version': the desktop libraries are + currently built from a commit past v5.4.1, because the tag builds the static + library without -fPIC and the Linux .so then fails to link. Once that change + is in a release, drop the ref and this takes the tag instead. + """ + base_url = sdk_info["url"].rstrip("/") + ref = sdk_info.get("ref") + if ref: + archive_url = f"{base_url}/archive/{ref}.tar.gz" + print(f"Using ref {ref} (past v{sdk_info['version']}, for the -fPIC fix)") + else: + archive_url = f"{base_url}/archive/refs/tags/{resolve_tag(base_url, sdk_info['version'])}.tar.gz" + + dest_dir = os.path.join(ROOT_DIR, "external", "gameanalytics-sdk-cpp") + + with tempfile.TemporaryDirectory() as work_dir: + archive_path = os.path.join(work_dir, "sdk.tar.gz") + fetch(archive_url, archive_path) + + print(f"Extracting to {dest_dir}...") + extract_dir = os.path.join(work_dir, "extracted") + with tarfile.open(archive_path, "r:gz") as tar: + tar.extractall(extract_dir) + + # A GitHub source archive holds exactly one top-level directory, named + # after the repository and ref; its name is not worth predicting. + entries = [e for e in os.listdir(extract_dir) if not e.startswith(".")] + if len(entries) != 1: + print(f"Expected one directory in the archive, found: {entries}") + sys.exit(1) + unpacked = os.path.join(extract_dir, entries[0]) + + if not os.path.exists(os.path.join(unpacked, "CMakeLists.txt")): + print(f"No CMakeLists.txt in {unpacked} — not a C++ SDK source tree") + sys.exit(1) + + if os.path.exists(dest_dir): + shutil.rmtree(dest_dir) + os.makedirs(os.path.dirname(dest_dir), exist_ok=True) + shutil.move(unpacked, dest_dir) + + print("Build the desktop library against it with:") + print(" ./sample/extensions/GameAnalyticsExt/DesktopSource/build_macos.sh \\") + print(" external/gameanalytics-sdk-cpp") + print("Update complete.") + + +def download_js_sdk(sdk_info): + """ + Replaces the extension's GameAnalytics.js with the JavaScript SDK's + minified bundle. + + The minified build is the one to take: it wraps itself in (function(scope){ + and inlines CryptoJS, so GameMaker's HTML5 target can load it as a plain + extension file with no bundler and no second script to order before it. + """ + base_url = sdk_info["url"].rstrip("/") + tag = resolve_tag(base_url, sdk_info["version"]) + raw_base_url = base_url.replace("github.com", "raw.githubusercontent.com") + download_url = f"{raw_base_url}/{tag}/dist/GameAnalytics.min.js" + + dest_path = os.path.join(EXTENSION_DIR, "GameAnalytics.js") + fetch(download_url, dest_path) + print(f"Updated {dest_path}.") + print("Update complete.") + + +def report_ios_sdk(sdk_info): + """Reports the shipped iOS version; see the module docstring for why.""" + lib_path = os.path.join( + EXTENSION_DIR, "iOSSource", "GameAnalyticsSDK", "libGameAnalytics.a" + ) + print(f"Pinned at {sdk_info['version']}, shipped as {os.path.relpath(lib_path, ROOT_DIR)}.") + if not os.path.exists(lib_path): + print(" warning: that library is missing from the tree") + print(" Not downloadable: the public releases carry no static library, and") + print(" 5.x ships an .xcframework, which GameAnalyticsExt.yy would have to") + print(" be reworked for. Upgrade by hand, in the IDE.") + + +def report_android_sdk(sdk_info): + """ + Checks the Maven coordinate in GameAnalyticsExt.yy against the manifest. + + Read-only on purpose. The coordinate sits inside the .yy's + androidcodeinjection string, and that file is IDE-managed JSON with trailing + commas — editing it from a script is how the two drift out of step. + """ + yy_path = os.path.join(EXTENSION_DIR, "GameAnalyticsExt.yy") + expected = sdk_info["version"] + print(f"Pinned at {expected}, resolved from Maven by Gradle at build time.") + + try: + with open(yy_path, "r", encoding="utf-8") as f: + yy_source = f.read() + except FileNotFoundError: + print(f" warning: {os.path.relpath(yy_path, ROOT_DIR)} not found") + return + + match = re.search( + r"com\.gameanalytics\.sdk:gameanalytics-android:([0-9][^\"\\\s]*)", yy_source + ) + if not match: + print(" warning: no gameanalytics-android coordinate in GameAnalyticsExt.yy") + elif match.group(1) != expected: + print(f" MISMATCH: GameAnalyticsExt.yy declares {match.group(1)}") + print(" Change it in the GameMaker IDE, under the extension's Android properties.") + else: + print(" GameAnalyticsExt.yy agrees.") + + +HANDLERS = { + "GA-SDK-CPP": download_cpp_sdk, + "GA-SDK-JAVASCRIPT": download_js_sdk, + "GA-SDK-IOS": report_ios_sdk, + "GA-SDK-ANDROID": report_android_sdk, +} + + +def process_dependencies(only=None): + """ + Runs the handler for each dependency in dependencies.json, or for just the + ones named in `only`. + """ + dependencies_file = os.path.join(ROOT_DIR, "dependencies.json") + try: + with open(dependencies_file, "r", encoding="utf-8") as f: + dependencies = json.load(f) + except FileNotFoundError: + print(f"dependencies.json not found in {ROOT_DIR}") + sys.exit(1) + except json.JSONDecodeError as e: + print(f"Error parsing dependencies.json: {e}") + sys.exit(1) + + known = {sdk_info.get("name", "") for sdk_info in dependencies} + if only: + unknown = [name for name in only if name not in known] + if unknown: + print(f"Not in dependencies.json: {', '.join(unknown)}") + print(f"Known: {', '.join(sorted(known))}") + sys.exit(1) + + for sdk_info in dependencies: + sdk_name = sdk_info.get("name", "") + if only and sdk_name not in only: + continue + print(f"\nProcessing dependency: {sdk_name}") + handler = HANDLERS.get(sdk_name) + if handler: + handler(sdk_info) + else: + print(f"Dependency '{sdk_name}' is not implemented yet.") + + +if __name__ == "__main__": + process_dependencies(only=sys.argv[1:] or None) diff --git a/fetch_desktop_binaries.py b/fetch_desktop_binaries.py index 2752aa4..5bfecec 100755 --- a/fetch_desktop_binaries.py +++ b/fetch_desktop_binaries.py @@ -4,7 +4,7 @@ The extension's native libraries are built in CI (see .github/workflows/desktop-binaries.yml) because releasing them otherwise needs a Windows box, a Linux box and a Mac. This pulls the result of a run and drops the -four libraries into both GameMaker projects. +libraries into the extension. ./fetch_desktop_binaries.py # latest successful run on this branch ./fetch_desktop_binaries.py --branch master @@ -46,7 +46,6 @@ "libGameAnalytics.dylib", "libGameAnalytics.so", "GameAnalytics.dll", - "GameAnalytics_x64.dll", ] @@ -182,7 +181,7 @@ def main(): parser.add_argument("--token", help="GitHub token (else $GITHUB_TOKEN, else `gh auth token`)") parser.add_argument("--dest", action="append", help="extension directory to install into (repeatable; " - "default: both GameMaker projects)") + "default: the extension under sample/)") parser.add_argument("--list", action="store_true", help="list recent runs and exit") parser.add_argument("--dry-run", action="store_true", help="report without writing files") parser.add_argument("--allow-partial", action="store_true", diff --git a/publish_release.py b/publish_release.py new file mode 100755 index 0000000..98468d4 --- /dev/null +++ b/publish_release.py @@ -0,0 +1,573 @@ +#!/usr/bin/env python3 +""" +Publishes a GameAnalytics GameMaker SDK release. + +Replaces publish_gamemaker_release.py from the development repository. That +script was written when the SDK lived in two places and shipped from a third: +it maintained four version strings, pulled prebuilt libraries off +download.gameanalytics.com, packaged a GMS1 `.gmez`, and committed the result +into a separate public repository. None of that applies here — this repository +*is* the public SDK, the extension exists once under sample/, and the desktop +libraries are built by CI from source. + +So the shape is different: + + publish_gamemaker_release.py this script + ------------------------------------ ------------------------------------ + 4 version strings (.gmx, .yy, 2 .gml) 2 (GameAnalyticsExt.yy, GameAnalytics.gml) + libs from download.gameanalytics.com rebuilt on CI, collected by + ./fetch_desktop_binaries.py + JS/iOS from the private GA-SDK-BINARIES ./download_externals.py, from the + public repos in dependencies.json + 7z a gameanalytics.gmez (GMS1) a zip of the extension + scripts + changelog prepended to README.md prepended to CHANGELOG.md + commits into ../GA-SDK-GAMEMAKER commits and tags here + no release a GitHub release carrying the zip + +Downloading the old prebuilt libraries is deliberately *not* carried over: +those are the February 2022 builds, and they contain an out-of-bounds read in +the add*EventJson entry points. Taking them again would reintroduce a crash. +The libraries are rebuilt on CI instead. + +Usage: + + ./publish_release.py -v 4.2.0 -c "first line::second line" + ./publish_release.py -v 4.2.0 -c "..." --dry-run + ./publish_release.py -v 4.2.0 -c "..." --skip-ci # trust the committed libs + +The Marketplace upload stays manual: it is an IDE and web flow with no API. +The script prints the remaining steps when it finishes. + +Credentials +----------- +The GameAnalytics game key and secret are read from a file that is never +committed — internal/ is in .gitignore, and the script refuses to run if the +file has somehow become tracked: + + internal/release-credentials.env + + GA_GAME_KEY=... + GA_GAME_SECRET=... + +They are used for one thing: asking the GameAnalytics backend whether it +accepts the new `sdk_version` string before the release is tagged. That string +is what identifies this SDK in every event the game sends, and a version the +backend rejects is invisible until the data stops arriving. Run +`--init-credentials` to write a template. Values are never printed. +""" + +import argparse +import base64 +import hashlib +import hmac +import json +import os +import re +import stat +import subprocess +import sys +import time +import urllib.error +import urllib.request +import zipfile + +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) +EXTENSION_DIR = os.path.join(ROOT_DIR, "sample", "extensions", "GameAnalyticsExt") +SCRIPTS_DIR = os.path.join(ROOT_DIR, "sample", "scripts", "GameAnalytics") +OBJECT_DIR = os.path.join(ROOT_DIR, "sample", "objects", "obj_gameanalytics") + +YY_FILE = os.path.join(EXTENSION_DIR, "GameAnalyticsExt.yy") +GML_FILE = os.path.join(SCRIPTS_DIR, "GameAnalytics.gml") +CHANGELOG_FILE = os.path.join(ROOT_DIR, "CHANGELOG.md") +CREDENTIALS_FILE = os.path.join(ROOT_DIR, "internal", "release-credentials.env") + +CHANGELOG_TOP_TAG = "" +WORKFLOW = "desktop-binaries.yml" + +# The libraries CI produces, and the two dependency files +# ./download_externals.py maintains. A release missing any of them is broken in +# a way that only shows up when a game calls into the extension. +SHIPPED_BINARIES = [ + "libGameAnalytics.dylib", + "libGameAnalytics.so", + "GameAnalytics.dll", +] + +VERSION_RE = re.compile(r"^\d+\.\d+\.\d+$") + + +# Progress goes to stdout and failures to stderr, so leaving stdout +# block-buffered would reorder the two whenever the output is piped into a log +# — the error would surface above the step it came from. +sys.stdout.reconfigure(line_buffering=True) + + +def fail(message): + print(f"error: {message}", file=sys.stderr) + sys.exit(1) + + +def run(args, cwd=ROOT_DIR, capture=False, check=True): + """Runs a subprocess, echoing it so the transcript shows what was done.""" + print(" $ " + " ".join(args)) + result = subprocess.run( + args, cwd=cwd, check=False, + stdout=subprocess.PIPE if capture else None, + stderr=subprocess.PIPE if capture else None, + text=True, + ) + if check and result.returncode != 0: + if capture and result.stderr: + print(result.stderr.strip(), file=sys.stderr) + fail(f"command failed ({result.returncode}): {' '.join(args)}") + return result + + +def git(*args, capture=True, check=True): + return run(["git", *args], capture=capture, check=check) + + +# -------------------------------------------------------------------------- +# credentials +# -------------------------------------------------------------------------- + +def write_credentials_template(): + """Creates internal/release-credentials.env, owner-readable only.""" + if os.path.exists(CREDENTIALS_FILE): + fail(f"{rel(CREDENTIALS_FILE)} already exists — not overwriting it") + os.makedirs(os.path.dirname(CREDENTIALS_FILE), exist_ok=True) + # Created 0600 from the start: writing it first and chmod-ing after would + # leave the secret briefly readable by anyone on the machine. + fd = os.open(CREDENTIALS_FILE, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600) + with os.fdopen(fd, "w", encoding="utf-8") as f: + f.write( + "# GameAnalytics credentials for publish_release.py.\n" + "# internal/ is gitignored; never move this file out of it.\n" + "GA_GAME_KEY=\n" + "GA_GAME_SECRET=\n" + ) + print(f"wrote {rel(CREDENTIALS_FILE)} (mode 600) — fill in the two values") + + +def load_credentials(): + """ + Reads the key and secret, or returns None if the file is absent. + + Refuses to read a file git is tracking. internal/ is ignored, so that + should be impossible — but `git add -f` is one command away, and a secret + committed once is committed forever. + """ + if not os.path.exists(CREDENTIALS_FILE): + return None + + tracked = git("ls-files", "--error-unmatch", rel(CREDENTIALS_FILE), check=False) + if tracked.returncode == 0: + fail( + f"{rel(CREDENTIALS_FILE)} is tracked by git. Remove it from the index " + "(`git rm --cached`) and rotate the credentials before publishing." + ) + + mode = os.stat(CREDENTIALS_FILE).st_mode + if mode & (stat.S_IRGRP | stat.S_IROTH): + print(f" warning: {rel(CREDENTIALS_FILE)} is readable beyond its owner; chmod 600 it") + + values = {} + with open(CREDENTIALS_FILE, encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + name, _, value = line.partition("=") + values[name.strip()] = value.strip() + + key = values.get("GA_GAME_KEY", "") + secret = values.get("GA_GAME_SECRET", "") + if not key or not secret: + print(f" {rel(CREDENTIALS_FILE)} is missing GA_GAME_KEY or GA_GAME_SECRET") + return None + return key, secret + + +def rel(path): + return os.path.relpath(path, ROOT_DIR) + + +# -------------------------------------------------------------------------- +# steps +# -------------------------------------------------------------------------- + +def preflight(version, allow_dirty): + print("--- preflight ---") + if not VERSION_RE.match(version): + fail(f"version must be MAJOR.MINOR.PATCH, got {version!r}") + + if not allow_dirty: + dirty = git("status", "--porcelain").stdout.strip() + if dirty: + fail("working tree is not clean:\n" + dirty + "\n(or pass --allow-dirty)") + + existing = git("tag", "--list", version).stdout.strip() + if existing: + fail(f"tag {version} already exists") + + current = read_versions() + print(f" current: .yy {current['yy']}, GameAnalytics.gml {current['gml']}") + if current["yy"] != current["gml"]: + fail("the two version strings already disagree — fix that before releasing") + if current["yy"] == version: + print(f" note: already at {version}; the bump will be a no-op") + + +def read_versions(): + with open(YY_FILE, encoding="utf-8") as f: + yy_match = re.search(r'"extensionVersion"\s*:\s*"([^"]*)"', f.read()) + with open(GML_FILE, encoding="utf-8") as f: + gml_match = re.search(r'_sdkVersion\s*=\s*"gamemaker ([^"]*)"', f.read()) + if not yy_match: + fail("no extensionVersion in GameAnalyticsExt.yy") + if not gml_match: + fail("no _sdkVersion in GameAnalytics.gml") + return {"yy": yy_match.group(1), "gml": gml_match.group(1)} + + +def refresh_dependencies(dry_run): + """Brings the JS bundle (and the C++ source tree) to what dependencies.json pins.""" + print("--- refreshing upstream dependencies ---") + if dry_run: + print(" (dry run) would run ./download_externals.py") + return + run([sys.executable, os.path.join(ROOT_DIR, "download_externals.py")]) + + +def rebuild_desktop_binaries(dry_run, token, branch): + """ + Dispatches the desktop workflow, waits for it, and collects the libraries. + + The libraries are rebuilt rather than taken from whatever is committed, so a + release cannot quietly ship a stale one. The C++ SDK ref comes from + dependencies.json, which CI reads itself. + """ + print("--- rebuilding the desktop libraries on CI ---") + if dry_run: + print(f" (dry run) would dispatch {WORKFLOW} and run ./fetch_desktop_binaries.py") + return + + if not which("gh"): + fail("gh is required to dispatch the workflow (or pass --skip-ci)") + + before = latest_run_id(branch) + run(["gh", "workflow", "run", WORKFLOW, "--ref", branch]) + + print(" waiting for the run to appear...") + run_id = None + for _ in range(30): + time.sleep(4) + candidate = latest_run_id(branch) + if candidate and candidate != before: + run_id = candidate + break + if not run_id: + fail("the dispatched run did not appear; check `gh run list`") + + print(f" watching run {run_id}") + watched = run(["gh", "run", "watch", run_id, "--exit-status"], check=False) + if watched.returncode != 0: + fail(f"the desktop build failed; see `gh run view {run_id} --log-failed`") + + fetch = [sys.executable, os.path.join(ROOT_DIR, "fetch_desktop_binaries.py"), + "--run-id", run_id] + if token: + fetch += ["--token", token] + run(fetch) + + +def latest_run_id(branch): + result = run( + ["gh", "run", "list", "--workflow", WORKFLOW, "--branch", branch, + "--limit", "1", "--json", "databaseId"], + capture=True, check=False, + ) + if result.returncode != 0: + return None + try: + runs = json.loads(result.stdout) + except json.JSONDecodeError: + return None + return str(runs[0]["databaseId"]) if runs else None + + +def which(program): + from shutil import which as _which + return _which(program) + + +def verify_binaries(): + """Checks every shipped artifact is present before anything is tagged.""" + print("--- verifying shipped artifacts ---") + missing = [] + for name in SHIPPED_BINARIES + ["GameAnalytics.js"]: + path = os.path.join(EXTENSION_DIR, name) + if os.path.exists(path): + print(f" ok {name} ({os.path.getsize(path):,} bytes)") + else: + missing.append(name) + ios_lib = os.path.join(EXTENSION_DIR, "iOSSource", "GameAnalyticsSDK", "libGameAnalytics.a") + if os.path.exists(ios_lib): + print(f" ok iOSSource/.../libGameAnalytics.a ({os.path.getsize(ios_lib):,} bytes)") + else: + missing.append("iOSSource/GameAnalyticsSDK/libGameAnalytics.a") + + if missing: + fail("missing shipped artifacts: " + ", ".join(missing)) + + +def bump_versions(version, dry_run): + """ + Rewrites the two version strings. + + Both must change together: extensionVersion is what the IDE and the + Marketplace show, and _sdkVersion is what reaches the backend on every + event. They are the two halves of the same fact. + """ + print("--- updating version strings ---") + edits = [ + (YY_FILE, r'("extensionVersion"\s*:\s*")[^"]*(")', version), + (GML_FILE, r'(_sdkVersion\s*=\s*"gamemaker )[^"]*(")', version), + ] + for path, pattern, value in edits: + with open(path, encoding="utf-8") as f: + source = f.read() + updated, count = re.subn(pattern, lambda m: m.group(1) + value + m.group(2), source) + if count != 1: + fail(f"expected exactly one version string in {rel(path)}, found {count}") + if dry_run: + print(f" (dry run) would set {rel(path)} to {value}") + continue + with open(path, "w", encoding="utf-8") as f: + f.write(updated) + print(f" {rel(path)} -> {value}") + + +def smoke_test(version, credentials, required): + """ + Asks the backend whether it accepts the new sdk_version string. + + Mirrors what the SDK does on init: POST the init annotations with + `Authorization: base64(HMAC-SHA256(body, game_secret))`, which is + GAHTTPApi::createAuth in the C++ SDK. A 401 means the credentials are + wrong; a 400 means the payload — including the version string — was + rejected. Network trouble is not treated as a release blocker. + """ + print("--- backend check on the new sdk_version ---") + if credentials is None: + message = ( + f"no credentials at {rel(CREDENTIALS_FILE)} — skipping " + "(--init-credentials writes a template)" + ) + if required: + fail(message) + print(f" {message}") + return + + key, secret = credentials + sdk_version = f"gamemaker {version}" + body = json.dumps({ + "platform": "windows", + "os_version": "windows 10", + "sdk_version": sdk_version, + }).encode("utf-8") + auth = base64.b64encode( + hmac.new(secret.encode("utf-8"), body, hashlib.sha256).digest() + ).decode("ascii") + + url = ( + "https://api.gameanalytics.com/remote_configs/v1/init" + f"?game_key={key}&interval_seconds=0&configs_hash=&config_vsn_supported=3" + ) + request = urllib.request.Request( + url, data=body, method="POST", + headers={"Authorization": auth, "Content-Type": "application/json"}, + ) + + print(f" sending sdk_version={sdk_version!r} to api.gameanalytics.com") + try: + with urllib.request.urlopen(request, timeout=30) as response: + print(f" accepted (HTTP {response.status})") + return + except urllib.error.HTTPError as e: + detail = e.read()[:200].decode("utf-8", "replace").strip() + if e.code in (401, 403): + fail(f"the backend rejected the credentials (HTTP {e.code}: {detail})") + if e.code == 400: + fail(f"the backend rejected the payload (HTTP 400: {detail}) — " + f"check that {sdk_version!r} is a version it knows") + message = f"unexpected response (HTTP {e.code}: {detail})" + except urllib.error.URLError as e: + message = f"could not reach the backend ({e.reason})" + + if required: + fail(message) + print(f" warning: {message} — continuing") + + +def update_changelog(version, changelog_raw, dry_run): + """Inserts the entry directly below the CHANGELOG_TOP marker, newest first.""" + print("--- updating CHANGELOG.md ---") + lines = [line.strip() for line in changelog_raw.split("::") if line.strip()] + if not lines: + fail("--changelog produced no entries") + + with open(CHANGELOG_FILE, encoding="utf-8") as f: + source = f.read() + if CHANGELOG_TOP_TAG not in source: + fail(f"{CHANGELOG_TOP_TAG} not found in CHANGELOG.md") + if f"\n**{version}**\n" in source: + fail(f"CHANGELOG.md already has an entry for {version}") + + entry = f"**{version}**\n" + "".join(f"* {line}\n" for line in lines) + "\n" + updated = source.replace( + CHANGELOG_TOP_TAG + "\n", CHANGELOG_TOP_TAG + "\n" + entry, 1 + ) + if dry_run: + print(" (dry run) would insert:") + print("".join(" " + l + "\n" for l in entry.strip().splitlines())) + return entry + with open(CHANGELOG_FILE, "w", encoding="utf-8") as f: + f.write(updated) + print(f" added {len(lines)} line(s) under {version}") + return entry + + +def package(version, dry_run): + """ + Zips what a GameMaker developer needs: the extension and the GML wrapper. + + GA_Sample* and obj_controller are left out — they are the demo app, not + part of the SDK. The old + script produced a GMS1 `.gmez` with 7z; this is a plain zip, because the + Marketplace package is built by the IDE and this artifact exists for people + downloading from GitHub. + """ + print("--- packaging ---") + zip_path = os.path.join(ROOT_DIR, f"GameAnalytics-GameMaker-{version}.zip") + sources = [ + (EXTENSION_DIR, "extensions/GameAnalyticsExt"), + (SCRIPTS_DIR, "scripts/GameAnalytics"), + # ga_initialize() creates this; without it desktop uploads never go out. + (OBJECT_DIR, "objects/obj_gameanalytics"), + ] + + if dry_run: + total = sum(len(files) for base, _ in sources for _, _, files in os.walk(base)) + print(f" (dry run) would write {os.path.basename(zip_path)} with ~{total} files") + return zip_path + + with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as archive: + count = 0 + for base, prefix in sources: + for dirpath, _, filenames in os.walk(base): + for filename in sorted(filenames): + if filename == ".DS_Store": + continue + absolute = os.path.join(dirpath, filename) + arcname = os.path.join( + prefix, os.path.relpath(absolute, base) + ) + archive.write(absolute, arcname) + count += 1 + print(f" {os.path.basename(zip_path)} ({os.path.getsize(zip_path):,} bytes, {count} files)") + return zip_path + + +def commit_and_tag(version, dry_run, branch): + print("--- committing and tagging ---") + paths = [rel(YY_FILE), rel(GML_FILE), rel(CHANGELOG_FILE), + "sample/extensions/GameAnalyticsExt"] + if dry_run: + print(f" (dry run) would commit {', '.join(paths)}, tag {version}, push to {branch}") + return + git("add", "--", *paths, capture=False) + git("commit", "-m", f"Release {version}", capture=False) + git("tag", "-a", version, "-m", f"Release {version}", capture=False) + git("push", "origin", branch, capture=False) + git("push", "origin", version, capture=False) + + +def create_release(version, zip_path, entry, dry_run): + print("--- creating the GitHub release ---") + notes = entry.replace(f"**{version}**\n", "").strip() + if dry_run: + print(f" (dry run) would create release {version} with {os.path.basename(zip_path)}") + return + if not which("gh"): + print(" gh not found — create the release by hand and attach " + f"{os.path.basename(zip_path)}") + return + run(["gh", "release", "create", version, zip_path, + "--title", f"GameAnalytics GameMaker SDK {version}", + "--notes", notes]) + + +# -------------------------------------------------------------------------- + +def main(argv): + parser = argparse.ArgumentParser( + description="Publish a GameAnalytics GameMaker SDK release.") + parser.add_argument("-v", "--version", help="release version, e.g. 4.2.0") + parser.add_argument("-c", "--changelog", + help="changelog lines separated by '::'") + parser.add_argument("--branch", default="master", help="branch to push (default: master)") + parser.add_argument("--token", help="GitHub token, passed to fetch_desktop_binaries.py") + parser.add_argument("--dry-run", action="store_true", + help="report every step without writing, pushing or dispatching") + parser.add_argument("--skip-deps", action="store_true", + help="do not refresh dependencies") + parser.add_argument("--skip-ci", action="store_true", + help="do not rebuild on CI; use the committed libraries") + parser.add_argument("--skip-release", action="store_true", + help="commit and tag, but do not create a GitHub release") + parser.add_argument("--require-backend-check", action="store_true", + help="treat an unreachable backend as a failure") + parser.add_argument("--allow-dirty", action="store_true", + help="proceed with uncommitted changes") + parser.add_argument("--init-credentials", action="store_true", + help=f"write a {rel(CREDENTIALS_FILE)} template and exit") + args = parser.parse_args(argv) + + if args.init_credentials: + write_credentials_template() + return + + if not args.version or not args.changelog: + parser.error("-v/--version and -c/--changelog are both required") + + version = args.version.lstrip("v") + print(f"=== publishing {version}" + (" (dry run)" if args.dry_run else "") + " ===\n") + + preflight(version, args.allow_dirty) + credentials = load_credentials() + + if not args.skip_deps: + refresh_dependencies(args.dry_run) + if not args.skip_ci: + rebuild_desktop_binaries(args.dry_run, args.token, args.branch) + verify_binaries() + + bump_versions(version, args.dry_run) + smoke_test(version, credentials, args.require_backend_check) + entry = update_changelog(version, args.changelog, args.dry_run) + zip_path = package(version, args.dry_run) + commit_and_tag(version, args.dry_run, args.branch) + if not args.skip_release: + create_release(version, zip_path, entry, args.dry_run) + + print(f"\n=== {version} published ===") + print("Remaining steps, which have no API and stay manual:") + print(" 1. GameMaker IDE: Marketplace -> Update Existing Package") + print(" select Extensions/GameAnalyticsExt, scripts/GameAnalytics") + print(" and objects/obj_gameanalytics") + print(" 2. accounts.yoyogames.com: Publisher -> GameAnalytics -> Versions -> Publish") + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/sample/extensions/GameAnalyticsExt/DesktopSource/CMakeLists.txt b/sample/extensions/GameAnalyticsExt/DesktopSource/CMakeLists.txt index ef6dc21..255d869 100644 --- a/sample/extensions/GameAnalyticsExt/DesktopSource/CMakeLists.txt +++ b/sample/extensions/GameAnalyticsExt/DesktopSource/CMakeLists.txt @@ -16,7 +16,7 @@ # Output name matches what GameAnalyticsExt.yy expects per platform: # macOS libGameAnalytics.dylib (universal x86_64 + arm64) # Linux libGameAnalytics.so -# Windows GameAnalytics_x64.dll / GameAnalytics.dll (32-bit build) +# Windows GameAnalytics.dll (64-bit) cmake_minimum_required(VERSION 3.16) @@ -90,11 +90,21 @@ elseif(UNIX) set_target_properties(GameAnalyticsGM PROPERTIES OUTPUT_NAME "GameAnalytics" PREFIX "lib" SUFFIX ".so") elseif(WIN32) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set_target_properties(GameAnalyticsGM PROPERTIES OUTPUT_NAME "GameAnalytics_x64") - else() - set_target_properties(GameAnalyticsGM PROPERTIES OUTPUT_NAME "GameAnalytics") + # 64-bit only. 32-bit Windows was dropped: GameMaker's Windows target is + # x64, and the extension declares exactly one Windows library. + if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + message(FATAL_ERROR + "32-bit Windows is not supported — configure with -A x64") endif() + + # GameAnalyticsExt.yy declares this library as GameAnalytics.dll, and the + # C++ SDK's static library is GameAnalytics.lib. On MSVC the DLL's import + # library would claim that same name and path, and the linker refuses it + # (LNK1149), so the import library — a build artifact that is never + # shipped — is given a different name. + set_target_properties(GameAnalyticsGM PROPERTIES + RUNTIME_OUTPUT_NAME "GameAnalytics" + ARCHIVE_OUTPUT_NAME "GameAnalyticsGM") endif() # Drop the built library straight into the extension folder. diff --git a/sample/extensions/GameAnalyticsExt/GameAnalytics.dll b/sample/extensions/GameAnalyticsExt/GameAnalytics.dll index 98c97f1..1e72b04 100644 Binary files a/sample/extensions/GameAnalyticsExt/GameAnalytics.dll and b/sample/extensions/GameAnalyticsExt/GameAnalytics.dll differ diff --git a/sample/extensions/GameAnalyticsExt/GameAnalyticsExt.yy b/sample/extensions/GameAnalyticsExt/GameAnalyticsExt.yy index 3b2a4d7..c2daa71 100644 --- a/sample/extensions/GameAnalyticsExt/GameAnalyticsExt.yy +++ b/sample/extensions/GameAnalyticsExt/GameAnalyticsExt.yy @@ -17,7 +17,7 @@ "copyToTargets":35184372089070, "description":"", "exportToGame":true, - "extensionVersion":"4.1.0", + "extensionVersion":"5.0.0", "files":[ {"$GMExtensionFile":"v1","%Name":"","constants":[],"copyToTargets":32,"filename":"GameAnalytics.js","final":"","functions":[],"init":"","kind":5,"name":"","origname":"","ProxyFiles":[],"resourceType":"GMExtensionFile","resourceVersion":"2.0","uncompress":false,"usesRunnerInterface":false,}, {"$GMExtensionFile":"v1","%Name":"","constants":[],"copyToTargets":35184372089070,"filename":"GameAnalyticsExt.ext","final":"","functions":[],"init":"","kind":4,"name":"","origname":"","ProxyFiles":[],"resourceType":"GMExtensionFile","resourceVersion":"2.0","uncompress":false,"usesRunnerInterface":false,}, diff --git a/sample/extensions/GameAnalyticsExt/GameAnalytics_x64.dll b/sample/extensions/GameAnalyticsExt/GameAnalytics_x64.dll deleted file mode 100644 index 211dc75..0000000 Binary files a/sample/extensions/GameAnalyticsExt/GameAnalytics_x64.dll and /dev/null differ diff --git a/sample/extensions/GameAnalyticsExt/libGameAnalytics.dylib b/sample/extensions/GameAnalyticsExt/libGameAnalytics.dylib index 000e33e..4402c89 100755 Binary files a/sample/extensions/GameAnalyticsExt/libGameAnalytics.dylib and b/sample/extensions/GameAnalyticsExt/libGameAnalytics.dylib differ diff --git a/sample/extensions/GameAnalyticsExt/libGameAnalytics.so b/sample/extensions/GameAnalyticsExt/libGameAnalytics.so index 4d2fc56..10836ff 100755 Binary files a/sample/extensions/GameAnalyticsExt/libGameAnalytics.so and b/sample/extensions/GameAnalyticsExt/libGameAnalytics.so differ diff --git a/sample/objects/obj_controller/Other_3.gml b/sample/objects/obj_controller/Other_3.gml index a7ffa7d..562113c 100644 --- a/sample/objects/obj_controller/Other_3.gml +++ b/sample/objects/obj_controller/Other_3.gml @@ -1,4 +1,3 @@ /// @description Clean up on game exit -ga_http_abort(); ga_on_quit(); show_debug_message("[GA Sample] Game end — ga_on_quit() called."); diff --git a/sample/objects/obj_controller/Other_62.gml b/sample/objects/obj_controller/Other_62.gml deleted file mode 100644 index 8d2df45..0000000 --- a/sample/objects/obj_controller/Other_62.gml +++ /dev/null @@ -1,7 +0,0 @@ -/// @description Async HTTP - -// Hands GameAnalytics' own responses back to the SDK and returns false for -// everything else, so a game's http_request handling goes in the else branch. -if (!ga_http_handle_async()) { - // not a GameAnalytics request -} diff --git a/sample/objects/obj_controller/Step_0.gml b/sample/objects/obj_controller/Step_0.gml index 19e915c..e095829 100644 --- a/sample/objects/obj_controller/Step_0.gml +++ b/sample/objects/obj_controller/Step_0.gml @@ -39,10 +39,6 @@ if (!global.__ga_info.initialized) { } } -// Desktop routes the SDK's HTTP through GameMaker, so its queued requests are -// issued from here and answered in the Async HTTP event. -ga_http_pump(); - ga_sample_ui_fade_flashes(); refresh_countdown--; diff --git a/sample/objects/obj_controller/obj_controller.yy b/sample/objects/obj_controller/obj_controller.yy index 398268a..3b25788 100644 --- a/sample/objects/obj_controller/obj_controller.yy +++ b/sample/objects/obj_controller/obj_controller.yy @@ -13,7 +13,6 @@ {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":67,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":68,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":70,"eventType":9,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":62,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":3,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, ], "managed":true, diff --git a/sample/objects/obj_gameanalytics/Other_3.gml b/sample/objects/obj_gameanalytics/Other_3.gml new file mode 100644 index 0000000..364d111 --- /dev/null +++ b/sample/objects/obj_gameanalytics/Other_3.gml @@ -0,0 +1,4 @@ +/// @description Game End — stop waiting on any in-flight request + +// Without this, shutdown blocks until the pending request times out. +ga_http_abort(); diff --git a/sample/objects/obj_gameanalytics/Other_62.gml b/sample/objects/obj_gameanalytics/Other_62.gml new file mode 100644 index 0000000..f6a1459 --- /dev/null +++ b/sample/objects/obj_gameanalytics/Other_62.gml @@ -0,0 +1,6 @@ +/// @description Async HTTP — hand GameAnalytics' responses back to the SDK + +// async_load is delivered to every instance with this event, so a game's own +// http_request handling is unaffected: this returns false for anything that is +// not a GameAnalytics request and leaves it alone. +ga_http_handle_async(); diff --git a/sample/objects/obj_gameanalytics/Step_0.gml b/sample/objects/obj_gameanalytics/Step_0.gml new file mode 100644 index 0000000..3e78aa0 --- /dev/null +++ b/sample/objects/obj_gameanalytics/Step_0.gml @@ -0,0 +1,9 @@ +/// @description Issue whatever the SDK has queued + +// On desktop the native library hands its requests to GameMaker rather than +// linking cURL, so something has to issue them once per step. ga_initialize() +// creates this object so a game does not have to wire that up itself. +// +// Safe if the game also calls ga_http_pump() from its own object: the first +// caller in a step claims the queued request and the second finds nothing. +ga_http_pump(); diff --git a/sample/objects/obj_gameanalytics/obj_gameanalytics.yy b/sample/objects/obj_gameanalytics/obj_gameanalytics.yy new file mode 100644 index 0000000..3d914d4 --- /dev/null +++ b/sample/objects/obj_gameanalytics/obj_gameanalytics.yy @@ -0,0 +1,37 @@ +{ + "$GMObject":"", + "%Name":"obj_gameanalytics", + "eventList":[ + {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":3,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":62,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":3,"eventType":7,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, + ], + "managed":true, + "name":"obj_gameanalytics", + "overriddenProperties":[], + "parent":{ + "name":"sample", + "path":"sample.yyp", + }, + "parentObjectId":null, + "persistent":true, + "physicsAngularDamping":0.1, + "physicsDensity":0.5, + "physicsFriction":0.2, + "physicsGroup":0, + "physicsKinematic":false, + "physicsLinearDamping":0.1, + "physicsObject":false, + "physicsRestitution":0.1, + "physicsSensor":false, + "physicsShape":1, + "physicsShapePoints":[], + "physicsStartAwake":true, + "properties":[], + "resourceType":"GMObject", + "resourceVersion":"2.0", + "solid":false, + "spriteId":null, + "spriteMaskId":null, + "visible":false, +} diff --git a/sample/sample.yyp b/sample/sample.yyp index 04076c1..4034ed9 100644 --- a/sample/sample.yyp +++ b/sample/sample.yyp @@ -21,6 +21,7 @@ "resources":[ {"id":{"name":"GameAnalyticsExt","path":"extensions/GameAnalyticsExt/GameAnalyticsExt.yy",},}, {"id":{"name":"obj_controller","path":"objects/obj_controller/obj_controller.yy",},}, + {"id":{"name":"obj_gameanalytics","path":"objects/obj_gameanalytics/obj_gameanalytics.yy",},}, {"id":{"name":"rm_main","path":"rooms/rm_main/rm_main.yy",},}, {"id":{"name":"GA_SampleActions","path":"scripts/GA_SampleActions/GA_SampleActions.yy",},}, {"id":{"name":"GA_SampleInfo","path":"scripts/GA_SampleInfo/GA_SampleInfo.yy",},}, diff --git a/sample/scripts/GameAnalytics/GameAnalytics.gml b/sample/scripts/GameAnalytics/GameAnalytics.gml index b830e12..3d2be66 100644 --- a/sample/scripts/GameAnalytics/GameAnalytics.gml +++ b/sample/scripts/GameAnalytics/GameAnalytics.gml @@ -135,7 +135,8 @@ function ga_configure_external_user_id(extUserId) { case os_android: ga_configure_external_user_id_android(extUserId); break; case os_ios: ga_configure_external_user_id_ios(extUserId); break; case os_macosx: configureExternalUserId_mac(extUserId); break; - // windows/linux: available once their binaries are rebuilt + case os_windows: configureExternalUserId_windows(extUserId); break; + case os_linux: configureExternalUserId_linux(extUserId); break; default: __ga_unsupported("ga_configure_external_user_id"); break; } } @@ -232,8 +233,48 @@ function ga_configure_resource_item_types(types) { /// @func ga_initialize(gameKey, gameSecret) /// @param {String} gameKey /// @param {String} gameSecret +/// @func __ga_http_autowire() +/// @desc Creates the instance that drives the desktop HTTP bridge, so a game +/// does not have to wire ga_http_pump / ga_http_handle_async / +/// ga_http_abort into an object of its own. +/// +/// The Async HTTP event is the reason this needs an object at all: +/// GameMaker delivers async_load only to instances that define the +/// event, so a script or a time source cannot receive it. +/// +/// Looked up by name rather than referenced directly, so the SDK scripts +/// still compile if obj_gameanalytics was not imported alongside them. +function __ga_http_autowire() { + if (!__ga_http_uses_gm_stack()) return true; + + var _obj = asset_get_index("obj_gameanalytics"); + if (_obj == -1) { + show_debug_message( + "[GameAnalytics] obj_gameanalytics is missing, so nothing will be " + + "uploaded on desktop. Import it alongside the GameAnalytics " + + "scripts, or call ga_http_pump/ga_http_handle_async/ga_http_abort " + + "from an object of your own."); + return false; + } + + if (instance_exists(_obj)) return true; + + // instance_create_depth needs a room to be running, which means + // ga_initialize must be called from a Create or Room Start event. + if (!room_exists(room)) { + show_debug_message( + "[GameAnalytics] ga_initialize was called before a room was " + + "running, so the HTTP bridge could not start. Call it from a " + + "Create or Room Start event."); + return false; + } + + instance_create_depth(0, 0, 0, _obj); + return true; +} + function ga_initialize(gameKey, gameSecret) { - var _sdkVersion = "gamemaker 4.1.0"; + var _sdkVersion = "gamemaker 5.0.0"; if (os_browser != browser_not_a_browser) { ga_configure_sdk_version_html(_sdkVersion); ga_initialize_html(gameKey, gameSecret); @@ -260,6 +301,11 @@ function ga_initialize(gameKey, gameSecret) { native_ga_initialize_linux(gameKey, gameSecret); break; } + + // Desktop uploads go through GameMaker's HTTP, which needs an instance + // to receive the Async HTTP event. Started here so the game does not + // have to. + __ga_http_autowire(); } } @@ -670,25 +716,25 @@ function __ga_http_uses_gm_stack() { if (os_browser != browser_not_a_browser) return false; switch (os_type) { case os_macosx: + case os_windows: + case os_linux: return true; - - // case os_windows: - // case os_linux: - // Enable these once GameAnalytics.dll / GameAnalytics_x64.dll / - // libGameAnalytics.so have been rebuilt from DesktopSource. The - // binaries currently shipped for those targets predate this client - // and do their own HTTP, and they do not export the gaHttp* entry - // points, so calling them would fail at runtime. } return false; } /// @func ga_http_pump() /// @desc Issues whatever request the SDK has queued, using GameMaker's own HTTP -/// stack. Call once per step from an object that also implements the -/// Async HTTP event (see ga_http_handle_async) — without it, nothing the -/// SDK records is ever submitted. Harmless no-op on platforms whose -/// native SDK does its own networking. +/// stack. +/// +/// You do not need to call this: ga_initialize() starts +/// obj_gameanalytics, which does it once per step. It stays public so a +/// game can drive the bridge itself — calling it as well is harmless, +/// because whichever caller comes first in a step claims the queued +/// request and the other finds nothing. +/// +/// Harmless no-op on platforms whose native SDK does its own +/// networking. function ga_http_pump() { if (!__ga_http_uses_gm_stack()) return -1; @@ -733,6 +779,8 @@ function ga_http_pump() { } /// @func ga_http_handle_async() +/// @desc You do not need to call this: obj_gameanalytics handles it. Still +/// public so a game can host the Async HTTP event itself. /// @desc Call from the Async HTTP event. Passes the response for the SDK's /// in-flight request back to the SDK and leaves the game's own HTTP /// traffic alone. @@ -783,6 +831,8 @@ function __ga_http_deliver(status, body) { } /// @func ga_http_abort() +/// @desc You do not need to call this: obj_gameanalytics calls it at Game End. +/// Still public so a game can shut the bridge down itself. /// @desc Fails the in-flight request instead of letting the SDK's worker thread /// wait out its timeout. Call on game end, before ga_on_quit(). function ga_http_abort() { @@ -801,13 +851,14 @@ function ga_http_abort() { /// @func ga_get_user_id() /// @desc The id the SDK is actually sending events under - the one configured /// via ga_configure_user_id, or the device id it generated itself. -/// Only the rebuilt desktop binaries expose this; "" elsewhere. +/// Bound on Windows, macOS and Linux; "" elsewhere. /// @return {String} function ga_get_user_id() { if (os_browser != browser_not_a_browser) return ""; switch (os_type) { - case os_macosx: return getUserId_mac(); - // windows/linux: available once their binaries are rebuilt + case os_macosx: return getUserId_mac(); + case os_windows: return getUserId_windows(); + case os_linux: return getUserId_linux(); } return ""; } @@ -817,8 +868,9 @@ function ga_get_user_id() { function ga_get_external_user_id() { if (os_browser != browser_not_a_browser) return ""; switch (os_type) { - case os_macosx: return getExternalUserId_mac(); - // windows/linux: available once their binaries are rebuilt + case os_macosx: return getExternalUserId_mac(); + case os_windows: return getExternalUserId_windows(); + case os_linux: return getExternalUserId_linux(); } return ""; }