diff --git a/.github/scripts/check-team-membership.sh b/.github/scripts/check-team-membership.sh new file mode 100755 index 0000000000..6af1f50619 --- /dev/null +++ b/.github/scripts/check-team-membership.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -x + +USER=$1 + +response=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/immutable/teams/sdk/memberships/${USER}") + +echo "$response" + +if echo "$response" | grep -q '"state":"active"'; then + IS_MEMBER=true +else + IS_MEMBER=false +fi +echo "$IS_MEMBER" + +# Set the environment variable for the GitHub workflow +echo "IS_MEMBER=$IS_MEMBER" >> "$GITHUB_ENV" diff --git a/.github/workflows/build-game-bridge.yaml b/.github/workflows/build-game-bridge.yaml new file mode 100644 index 0000000000..499395a0e5 --- /dev/null +++ b/.github/workflows/build-game-bridge.yaml @@ -0,0 +1,184 @@ +# 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 }} + +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 + + # uncomment when the script it merged and tagged + # - name: Check SDK Team Membership + # id: check_team + # run: | + # ./.github/scripts/check-team-membership.sh "${{ github.actor }}" "${{ env.GH_TOKEN }}" + # source "$GITHUB_ENV" + # echo "${{ github.actor }} is a member of the SDK team: $IS_MEMBER" + # if [[ "$IS_MEMBER" != "true" ]]; then + # echo "Not a member of the SDK team, exiting workflow" + # exit 1 + # fi + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + registry-url: https://registry.npmjs.org/ + cache: "yarn" + + - name: Restore cached node_modules + id: restore-cache-node_modules + uses: actions/cache@v4 + with: + path: node_modules + key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }} + + - name: Install dependencies + if: steps.restore-cache-node_modules.outputs.cache-hit != 'true' + run: yarn install --immutable + + - name: Set TS SDK hash + run: echo "TS_SDK_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Build Game Bridge + run: cd packages/game-bridge && yarn build + + # make artifacs avilable for download + - name: Upload Build Artifacts + uses: actions/upload-artifact@v2 + with: + name: game-bridge-artifacts + path: ./packages/game-bridge/dist + + - name: Cache build artifacts + uses: actions/cache@v4 + with: + path: ./packages/game-bridge/dist + key: "${{ runner.os }}-game-bridge-build-${{ env.TS_SDK_TAG }}" + + 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 + # env: + # GH_TOKEN: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }} + # NODE_OPTIONS: --max-old-space-size=14366 + # steps: + # - name: Checkout SDK Repository + # uses: actions/checkout@v4 + # with: + # ref: "${{ github.event.inputs.ts_sdk_tag }}" diff --git a/packages/game-bridge/scripts/updateSdkVersion.sh b/packages/game-bridge/scripts/updateSdkVersion.sh index 284f1b026a..e47e79dcff 100755 --- a/packages/game-bridge/scripts/updateSdkVersion.sh +++ b/packages/game-bridge/scripts/updateSdkVersion.sh @@ -1,5 +1,10 @@ #!/bin/bash +# This script is used to update the SDK version in the output files +# It is run as part of the build process and expects the following environment variables to be set: +# - TS_SDK_TAG: The tag of the SDK +# - TS_SDK_HASH: The git hash of the tag + set -e set -x @@ -15,28 +20,35 @@ do fi done -# pull down latest tags -git fetch --tags - -# get latest git tag -LATEST_TAG=$(git tag -l --sort=-v:refname | grep -v '\-alpha' | head -n 1) +# check the TS_SDK_TAG environment variable is set +if [ -z "$TS_SDK_TAG" ]; then + echo "TS_SDK_TAG environment variable not found. Exiting..." + exit 1 +fi -if [ -z "$LATEST_TAG" ]; then - echo "No tags found. Exiting..." +# check the TS_SDK_HASH environment variable is set +if [ -z "$TS_SDK_HASH" ]; then + echo "TS_SDK_HASH environment variable not found. Exiting..." exit 1 fi -# get latest commit hash -LATEST_COMMIT=$(git rev-parse HEAD) +# use regex to check the current tag is a valid version +# example valid version: 1.2.3 +# or: 1.2.3-alpha +# or: 1.2.3-alpha.1 +if [[ ! $TS_SDK_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then + echo "Current tag is not a valid version. Exiting..." + exit 1 +fi # update variables in output files for FILE_PATH in "${FILE_PATHS[@]}" do if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "s/__SDK_VERSION__/${LATEST_TAG}/g" $FILE_PATH - sed -i '' "s/__SDK_VERSION_SHA__/${LATEST_COMMIT}/g" $FILE_PATH + sed -i '' "s/__SDK_VERSION__/${TS_SDK_TAG}/g" $FILE_PATH + sed -i '' "s/__SDK_VERSION_SHA__/${TS_SDK_HASH}/g" $FILE_PATH else - sed -i "s/__SDK_VERSION__/${LATEST_TAG}/g" $FILE_PATH - sed -i "s/__SDK_VERSION_SHA__/${LATEST_COMMIT}/g" $FILE_PATH + sed -i "s/__SDK_VERSION__/${TS_SDK_TAG}/g" $FILE_PATH + sed -i "s/__SDK_VERSION_SHA__/${TS_SDK_HASH}/g" $FILE_PATH fi done