Skip to content

Build Game Bridge

Build Game Bridge #59

# Workflow to manually trigger a build of the game bridge with the selected SDK tag
# and create a PR with the changes to the game SDK repository.
name: Build Game Bridge
on:
workflow_dispatch:
inputs:
ts_sdk_tag:
type: string
description: TS SDK version tag
required: true
game_engine:
type: choice
description: Game SDK to update
options:
- Unity
- Unreal
- Both
required: true
default: Unity
dry_run:
type: boolean
description: "(Optional) Dry run"
required: false
default: false
env:
TS_SDK_TAG: ${{ github.event.inputs.ts_sdk_tag }}
GAME_ENGINE: ${{ github.event.inputs.game_engine }}
DRY_RUN: ${{ github.event.inputs.dry_run }}
GH_TOKEN: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }}
SDK_TEAM_MEMBERS: ${{ secrets.SDK_TEAM_MEMBERS }}
CI: true
jobs:
build-game-bridge:
name: Build Game Bridge
runs-on: ubuntu-latest-4-cores
env:
NODE_OPTIONS: --max-old-space-size=14366
steps:
- name: Checkout SDK Repository
id: checkout-sdk
uses: actions/checkout@v4
with:
ref: "${{ env.TS_SDK_TAG }}"
fetch-depth: 0
- name: Check SDK Team Membership
id: allowed_actors_check
# only allow SDK team members to run this workflow
# ["ckailash", "CodeSchwert", "wdinau", "shineli1984", "nattb8", "YermekG", "zaidarain1"]
if: ${{ contains(fromJson(env.SDK_TEAM_MEMBERS), github.triggering_actor) }}
run: echo "ALLOWED_ACTOR=true" >> $GITHUB_OUTPUT
- name: Allowed Actors Filter
if: ${{ steps.allowed_actors_check.outputs.ALLOWED_ACTOR != 'true' }}
run: exit 1
- name: setup
uses: ./.github/actions/setup
- name: Set TS SDK hash
run: echo "TS_SDK_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Build Game Bridge
run: yarn nx run @imtbl/game-bridge:build --skip-nx-cache
- name: Update Version Strings
run: cd packages/game-bridge && ./scripts/updateSdkVersion.sh
- name: Check Unity Version String Updated
if: ${{ github.event.inputs.game_engine == 'Unity' || github.event.inputs.game_engine == 'Both' }}
run: |
UNITY_ARTIFACT_PATH="./packages/game-bridge/dist/unity/index.html"
if [ ! -f "$UNITY_ARTIFACT_PATH" ]; then
echo "Error: Unity artifact file not found at $UNITY_ARTIFACT_PATH"
exit 1
fi
UNITY_VERSION_STRING_COUNT=$(grep -c -o "ts-immutable-sdk-${{ env.TS_SDK_TAG }}" "$UNITY_ARTIFACT_PATH" || true)
if [ "$UNITY_VERSION_STRING_COUNT" -eq 0 ]; then
echo "Error: Updated version string not found in $UNITY_ARTIFACT_PATH"
exit 1
fi
echo "Unity version string updated successfully"
- name: Check Unreal Version String Updated
if: ${{ github.event.inputs.game_engine == 'Unreal' || github.event.inputs.game_engine == 'Both' }}
run: |
UNREAL_ARTIFACT_PATH="./packages/game-bridge/dist/unreal/index.js"
if [ ! -f "$UNREAL_ARTIFACT_PATH" ]; then
echo "Error: Unreal artifact file not found at $UNREAL_ARTIFACT_PATH"
exit 1
fi
UNREAL_VERSION_STRING_COUNT=$(grep -c -o "ts-immutable-sdk-${{ env.TS_SDK_TAG }}" "$UNREAL_ARTIFACT_PATH" || true)
if [ "$UNREAL_VERSION_STRING_COUNT" -eq 0 ]; then
echo "Error: Updated version string not found in $UNREAL_ARTIFACT_PATH"
exit 1
fi
echo "Unreal version string updated successfully"
- name: Cache build artifacts
uses: actions/cache@v4
with:
path: ./packages/game-bridge/dist
key: "${{ runner.os }}-game-bridge-build-${{ env.TS_SDK_TAG }}"
- name: Upload Game Bridge Build
uses: actions/upload-artifact@v4
with:
path: ./packages/game-bridge/dist
create-unity-pr:
name: Create Unity PR
needs: build-game-bridge
if: ${{ github.event.inputs.game_engine == 'Unity' || github.event.inputs.game_engine == 'Both' }}
runs-on: ubuntu-latest-4-cores
steps:
- name: Checkout SDK Repository
uses: actions/checkout@v4
with:
token: ${{ env.GH_TOKEN }}
ref: "${{ env.TS_SDK_TAG }}"
- name: Setup Github
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Restore Cached Build Artifacts
id: restore-cache-game-bridge-build
uses: actions/cache@v4
with:
path: ./packages/game-bridge/dist
key: ${{ runner.os }}-game-bridge-build-${{ env.TS_SDK_TAG }}
- name: Check Cache Restore
if: steps.restore-cache-game-bridge-build.outputs.cache-hit != 'true'
run: echo "Game Bridge build cache not restored, exiting" && exit 1
- name: Checkout Unity SDK Repo
uses: actions/checkout@v4
with:
repository: immutable/unity-immutable-sdk
token: ${{ env.GH_TOKEN }}
path: unity-immutable-sdk
ref: main
clean: true
fetch-depth: 0
- name: Change Unity Branch
run: |
cd unity-immutable-sdk
git checkout -b "chore/update-game-bridge-${{ env.TS_SDK_TAG }}"
cd ..
- name: Copy Game Bridge Build
run: cp -r ./packages/game-bridge/dist/unity/index.html ./unity-immutable-sdk/src/Packages/Passport/Runtime/Resources/index.html
- name: Commit Changes
run: |
cd unity-immutable-sdk
git add src/Packages/Passport/Runtime/Resources/index.html
git commit -m "chore: update game bridge to ${{ env.TS_SDK_TAG }}"
cd ..
- name: Push Changes
if: ${{ env.DRY_RUN == 'false' }}
run: |
cd unity-immutable-sdk
git push -u origin "chore/update-game-bridge-${{ env.TS_SDK_TAG }}"
cd ..
- name: Create PR (Dry Run)
if: ${{ env.DRY_RUN == 'true' }}
run: |
cd unity-immutable-sdk
echo "gh pr create --base main --head chore/update-game-bridge-${{ env.TS_SDK_TAG }} --title 'chore: update game bridge to ${{ env.TS_SDK_TAG }}' --body 'Update game bridge (build from ts-immutable-sdk version [${{ env.TS_SDK_TAG }}](https://github.com/immutable/ts-immutable-sdk/releases/tag/${{ env.TS_SDK_TAG }}))'"
cd ..
- name: Create PR
if: ${{ env.DRY_RUN == 'false' }}
run: |
cd unity-immutable-sdk
gh pr create --base main --head "chore/update-game-bridge-${{ env.TS_SDK_TAG }}" --title "chore: update game bridge to ${{ env.TS_SDK_TAG }}" --body "Update game bridge (build from ts-immutable-sdk version [${{ env.TS_SDK_TAG }}](https://github.com/immutable/ts-immutable-sdk/releases/tag/${{ env.TS_SDK_TAG }}))"
cd ..
create-unreal-pr:
name: Create Unreal PR
needs: build-game-bridge
if: ${{ github.event.inputs.game_engine == 'Unreal' || github.event.inputs.game_engine == 'Both' }}
runs-on: ubuntu-latest-4-cores
steps:
- name: Checkout SDK Repository
uses: actions/checkout@v4
with:
token: ${{ env.GH_TOKEN }}
ref: "${{ env.TS_SDK_TAG }}"
- name: Setup Github
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Restore Cached Build Artifacts
id: restore-cache-game-bridge-build
uses: actions/cache@v4
with:
path: ./packages/game-bridge/dist
key: ${{ runner.os }}-game-bridge-build-${{ env.TS_SDK_TAG }}
- name: Check Cache Restore
if: steps.restore-cache-game-bridge-build.outputs.cache-hit != 'true'
run: echo "Game Bridge build cache not restored, exiting" && exit 1
- name: Checkout Unreal SDK Repo
uses: actions/checkout@v4
with:
repository: immutable/unreal-immutable-sdk
token: ${{ env.GH_TOKEN }}
path: unreal-immutable-sdk
ref: main
clean: true
fetch-depth: 0
- name: Change Unreal Branch
run: |
cd unreal-immutable-sdk
git checkout -b "chore/update-game-bridge-${{ env.TS_SDK_TAG }}"
cd ..
- name: Copy Game Bridge Build
run: cp -r ./packages/game-bridge/dist/unreal/index.js ./unreal-immutable-sdk/Web/index.js
- name: Commit Changes
run: |
cd unreal-immutable-sdk
git add Web/index.js
git commit -m "chore: update game bridge to ${{ env.TS_SDK_TAG }}"
cd ..
- name: Push Changes
if: ${{ env.DRY_RUN == 'false' }}
run: |
cd unreal-immutable-sdk
git push -u origin "chore/update-game-bridge-${{ env.TS_SDK_TAG }}"
cd ..
- name: Create PR (Dry Run)
if: ${{ env.DRY_RUN == 'true' }}
run: |
cd unreal-immutable-sdk
echo "gh pr create --base main --head chore/update-game-bridge-${{ env.TS_SDK_TAG }} --title 'chore: update game bridge to ${{ env.TS_SDK_TAG }}' --body 'Update game bridge (build from ts-immutable-sdk version [${{ env.TS_SDK_TAG }}](https://github.com/immutable/ts-immutable-sdk/releases/tag/${{ env.TS_SDK_TAG }}))'"
cd ..
- name: Create PR
if: ${{ env.DRY_RUN == 'false' }}
run: |
cd unreal-immutable-sdk
gh pr create --base main --head "chore/update-game-bridge-${{ env.TS_SDK_TAG }}" --title "chore: update game bridge to ${{ env.TS_SDK_TAG }}" --body "Update game bridge (build from ts-immutable-sdk version [${{ env.TS_SDK_TAG }}](https://github.com/immutable/ts-immutable-sdk/releases/tag/${{ env.TS_SDK_TAG }}))"
cd ..